代码拉取完成,页面将自动刷新
#include <intrins.h>
#include <STC8.H>
#include <TM1637.h>
#include <EEPROM.h>
sbit SEV_PWM = P1^2;
sbit FA_PAI_0 = P1^0;
sbit FA_PAI_1 = P1^1;
sbit TUI_PAI_0 = P1^2;
sbit TUI_PAI_1 = P1^3;
sbit AJ_0 = P1^5;
sbit AJ_1 = P3^6;
sbit AJ_2 = P3^5;
sbit FENG_M = P3^7;
sbit LED_ACC1 = P3^6;
sbit LED_ACC2 = P3^7;
#define ADDR_PAIS 0x0400
#define ADDR_WS 0x0800
unsigned char _pais,_weishu;
void Delay20ms() //@11.0592MHz
{
unsigned char i, j, k;
i = 2;
j = 32;
k = 60;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
i = 29;
j = 14;
k = 54;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay10ms(unsigned char m) //@11.0592MHz
{
unsigned char i, j;
do
{
_nop_();
_nop_();
i = 144;
j = 157;
do
{
while (--j);
} while (--i);
} while (--m);
}
void Delay100ms(unsigned char m) //@11.0592MHz
{
unsigned char i, j, k;
do
{
_nop_();
i = 6;
j = 157;
k = 59;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
} while (--m);
}
void fapai()
{
FA_PAI_1 = 1;
Delay10ms(9);
FA_PAI_1 = 0;
Delay10ms(5);
FA_PAI_0 = 1;
Delay10ms(5);
FA_PAI_0 = 0;
Delay10ms(5);
}
void Delay100us() //@11.0592MHz
{
unsigned char i, j;
i = 2;
j = 109;
do
{
while (--j);
} while (--i);
}
void ChangeOne(unsigned char x)
{
unsigned char i;
i = 200;
while(i--)
{
if(i <= x)
{
SEV_PWM = 1; //高电平
}
else
{
SEV_PWM = 0; //低电平
}
Delay100us();
}
}
void Change(unsigned char x) // 0-20
{
unsigned char i,t;
i = 10;
t = 3 + x;
while(i--)
{
ChangeOne(t);
}
}
void ChangeReset()
{
unsigned char i;
i = 20;
while(i--)
{
ChangeOne(3);
}
}
void init()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0xFF;
P1M1 = 0x00;
P3M0 = 0xFF;
P3M1 = 0x00;
P1 = 0x00;
P3 = 0x00;
_pais = 0;
_weishu = 0;
AJ_1 = 0;
AJ_2 = 0;
FENG_M = 0;
/*
P_SW2 = 0x80;
XOSCCR = 0xc0; //启动外部晶振
while (!(XOSCCR & 1)); //等待时钟稳定
CLKDIV = 0x00; //时钟不分频
CKSEL = 0x01; //选择外部晶振
P_SW2 = 0x00;
*/
}
void showNum(unsigned char a,unsigned char b)
{
unsigned char b0,b1;
b0 = b % 10;
b1 = b / 10;
TM1637_display(a,21,b1,b0,0x00);//演示怎样按顺序显示
}
void fengming()
{
FENG_M = 1;
Delay100ms(1);
FENG_M = 0;
}
void paisAdd()
{
_pais++;
if (_pais > 17) {
_pais = 1;
}
}
void weishuAdd()
{
_weishu++;
if (_weishu > 6) {
_weishu = 2;
}
}
unsigned char isStar()
{
while(AJ_0 == 0) {
_nop_();
if (AJ_1 == 1) {
paisAdd();
showNum(_weishu, _pais);
fengming();
Delay100ms(2);
while(AJ_1 == 1) {
paisAdd();
showNum(_weishu, _pais);
Delay100ms(1);
}
}
if (AJ_2 == 1) {
weishuAdd();
showNum(_weishu, _pais);
fengming();
Delay100ms(2);
while(AJ_2 == 1) {
weishuAdd();
showNum(_weishu, _pais);
Delay100ms(1);
}
}
}
fengming();
Delay100ms(2);
return 1;
}
void fapai2()
{
TUI_PAI_0 = 1;
FA_PAI_1 = 1;
Delay10ms(12);
FA_PAI_1 = 0;
Delay10ms(5);
FA_PAI_0 = 1;
Delay10ms(7);
FA_PAI_0 = 0;
Delay10ms(5);
TUI_PAI_0 = 0;
}
void main()
{
unsigned char max,t,jd,t1, pais, weishu;
init();
fengming();
ChangeReset();
Delay500ms();
max = 20;
pais = IapRead(ADDR_PAIS); //读取
weishu = IapRead(ADDR_WS); //读取
if (weishu == 0) {
weishu = 4;
pais = 3;
}
_pais = pais;
_weishu = weishu;
//showNum(count, 15);
//IapErase(0x0400); // 擦除
//IapProgram(0x0400, pais); // 写入
//pais = IapRead(0x0400); //读取
showNum(weishu, pais);
LED_ACC1 = 0;
while(1) {
fapai2();
Delay100ms(8);
}
while(1) {
isStar();
if (pais != _pais) {
IapErase(ADDR_PAIS); // 擦除
IapProgram(ADDR_PAIS, _pais); // 写入
}
if (weishu != _weishu) {
IapErase(ADDR_WS); // 擦除
IapProgram(ADDR_WS, _weishu); // 写入
}
pais = _pais;
weishu = _weishu;
jd = max / weishu;
while(pais>0)
{
P2 = 0;
pais--;
t = 0;
t1 = 0;
ChangeReset();
fapai();
while(t < max)
{
t++;
t1++;
if ( t1 > jd) {
Change(t);
t1 = 0;
//P2 = 0;
fapai();
}
}
}
ChangeReset();
}
while(2>1) ;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。