爆闪灯C51程序知识讲解Word文档格式.docx

上传人:b****6 文档编号:21197861 上传时间:2023-01-28 格式:DOCX 页数:19 大小:18.54KB
下载 相关 举报
爆闪灯C51程序知识讲解Word文档格式.docx_第1页
第1页 / 共19页
爆闪灯C51程序知识讲解Word文档格式.docx_第2页
第2页 / 共19页
爆闪灯C51程序知识讲解Word文档格式.docx_第3页
第3页 / 共19页
爆闪灯C51程序知识讲解Word文档格式.docx_第4页
第4页 / 共19页
爆闪灯C51程序知识讲解Word文档格式.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

爆闪灯C51程序知识讲解Word文档格式.docx

《爆闪灯C51程序知识讲解Word文档格式.docx》由会员分享,可在线阅读,更多相关《爆闪灯C51程序知识讲解Word文档格式.docx(19页珍藏版)》请在冰豆网上搜索。

爆闪灯C51程序知识讲解Word文档格式.docx

sfrP2M0=0X96;

sfrP2M仁0X95;

sfrP1M0=0X92;

sfrP1M1=0X91;

sfrIAP_DATA=0XC2;

sfrIAP_ADDRH=0XC3;

sfrIAP_ADDRL=0XC4;

sfrIAP_CMD=0xc5;

sfrIAP_TRIG=0XC6;

sfrIAP_CONTR=0XC7;

unsignedcharliang_temp=1;

unsignedcharan_temp=1;

unsignedcharR_to_B_temp=1;

unsignedcharstop_temp=1;

unsignedcharmode=1;

unsignedchartime_key=0;

unsignedchartime_temp=0;

unsignedcharmode1_temp=0;

ucharajs,ljs;

ucharrtobjs,stopjs,js3c=1;

ucharrba=0;

bitla=1;

ksj=0;

unsignedcharcodezhifu0[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};

unsignedcharcodezhifu2[16]={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0XFe,0Xf6,0Xee,0X3e,0X9c,0X7a,0X9e,0X8e};

〃*********************************************************

voiddelay20(void)//

误差-0.000000000002us

{

unsignedchara,b,c;

for(c=2;

c>

0;

c--)for(b=95;

b>

b--)for(a=209;

a>

a--);

}

voiddelay500(void)//误差0us500ms

for(c=23;

c--)

for(b=152;

b--)

for(a=70;

voideeprom_erase(unsignedchara)

{_

unsignedintadd=512;

unsignedintadd1=0;

add1=add*a;

IAP_ADDRH=add1/255;

IAP_ADDRL=add1%255;

IAP_CONTR=0X8C;

IAP_CMD=0X03;

IAP_TRIG=0X5A;

IAP_TRIG=0XA5;

_nop_();

voideeprom_writer(unsignedintadd,unsignedchardate){_

IAP_DATA=date;

IAP_ADDRH=add/255;

IAP_ADDRL=add%255;

IAP_CONTR=OX8C;

IAP_CMD=2;

//***********************************************************

unsignedchareeprom_read(unsignedintadd)

unsignedchardate=0;

//

IAP_CMD=0X01;

date=IAP_DATA;

return(date);

//*********************************************************

voidshow(unsignedchara)

unsignedcharshi;

unsignedcharge;

unsignedchar*p;

unsignedchar*p1;

p=zhifu0;

p仁zhifu2;

shi=a/10;

shi=*(p+shi);

//得到编码值

ge=a%10;

ge=*(p1+ge);

P0=shi;

P2=ge;

〃**********************************************************

voidliang_key()

if(!

P1_0)

delay20();

liang_temp++;

if(liang_temp>

99)

{liang_temp=1;

}show(liang_temp);

while(!

while(ksj){liang_temp++;

99)liang_temp=1;

show(

liang_temp);

_}

〃***********************************************************

voidan_key()

if(P1_0==0)

an_temp++;

if(an_temp>

{an_temp=1;

show(an_temp);

while(!

while(ksj){an_temp++;

if(an_temp>

99)an_temp=1;

voidR_to_B_key()

if(P1_O==O)

R_to_B_temp++;

if(R_to_B_temp>

R_to_B_temp=1;

show(R_to_B_temp);

while(ksj){R_to_B_temp++;

99)R_to_B_temp=1;

show(R_to_B_temp);

voidstop_key()

stop_temp++;

if(stop_temp>

{stop_temp=1;

}show(stop_temp);

while(ksj){stop_temp++;

99)stop_temp=1;

show(sto

P_temp);

〃************************************************************

voidshow_mode(unsignedchara)

unsignedcharge=0;

ge=*(p1+a);

//P0=0x00;

voidset_mode()

TR1=1;

〃开定时器

show_mode(mode);

}_

while(time_key==0)

mode++;

if(mode>

5)

mode=1;

time_temp=0;

delay20();

TR1=0;

〃关定时器

time_key=0;

TH1=0x3C;

TL1=0xB0;

eeprom_erase

(1);

eeprom_writer(0,mode);

P0=0;

P2=0;

rtobjs=R_to_B_temp;

stopjs=stop_temp;

ajs=an_temp;

ljs=liang_temp;

rba=0;

4个步骤第

voidset_fun()〃设置时间的顺序是从亮,暗,红到蓝,停,

个模式

unsignedcharpanduan=0;

P1_1)

P0=zhifu0[15];

P2=zhifu2[1];

delay500();

panduan=1;

while(panduan)

liang_key();

show(liang_temp);

panduan=0;

P2=zhifu2[2];

an_key();

ajs=an_temp;

P2=zhifu2[3];

delay500();

{R_to_B_key();

rtobjs=R_to_B_temp;

P2=zhifu2[4];

stop_key();

show(stop_temp);

if(!

{delay20();

stopjs=stop_temp;

}eeprom_erase(0);

eeprom_writer(0,liang_temp);

eeprom_writer(1,an_temp);

eeprom_writer(2,R_to_B_temp);

eeprom_writer(3,stop_temp);

P0=0X0;

P2=0X0;

//red=1;

//blue=0;

//yq=yq2=0;

rtobjs=R_to_B_temp;

stopjs=stop_temp;

ajs=an_temp;

ljs=liang_temp;

voidmode_out(bita1,bita2,bita3,bita4)//a为停留时间,各位为输出

P1_4=a1;

P1_5=a2;

P1_6=a3;

P1_7=a4;

voidredfun(void)

if(js3c<

4)

if(la)mode_out(1,0,1,0);

elsemode_out(0,0,0,0);

else

mode_out(0,0,0,0);

voidbluefun(void)

if(la)mode_out(0,1,0,1);

voidallfun(void)

if(la)mode_out(1,1,1,1);

voidmode1()〃模式1

〃unsignedchara=0;

switch(rba)

case0:

redfun();

break;

case1:

bluefun();

case2:

allfun();

default:

voidmode_work(unsignedchara)//参数为模式

{switch(a)

mode1();

break;

//第一种模式

case2:

case3:

case4:

case5:

}

/*

voiddecipherment_dog()〃解密完后才能使用本控制器

if((P1_O==O)&

(P1_1==0))

}*/

voidInitTimerl(void)

TMOD=0x11;

TL1=OxBO;

EA=1;

ET1=1;

voidInitTimerO(void)

THO=Oxf2;

TLO=Oxfb;

ET0=1;

TRO=1;

main()

InitTimer1();

InitTimerO();

P0M0=0XFF;

〃配成强上拉

POM仁0X00;

P2M0=0XFF;

P2M仁0X00;

P1M仁0X00;

P1M0=0XF0;

P1_4=0;

P1_5=0;

P1_6=0;

P1_7=0;

liang_temp=eeprom_read(0);

an_temp=eeprom_read

(1);

R_to_B_temp=eeprom_read

(2);

stop_temp=eeprom_read(3);

rtobjs=R_to_B_temp;

ljs=liang_temp;

while

(1)

set_fun();

set_mode();

mode_work(mode);

voidTimer1Interrupt(void)interrupt3{

TH1=0x7d;

TL1=Oxcb;

time_temp++;

if(time_temp>

30)

time_key=1;

voidTimerOInterrupt(void)interrupt1

//TR0=0;

staticuchari=0;

staticucharkj=0;

TH0=0xf2;

TL0=0xfb;

if(la)//

Ijs--;

if(ljs==0)

la=0;

ajs--;

if(ajs==0)

la=1;

js3c++;

〃10ms

如果在亮计时

//亮计数自减

//亮的时间到

//置0亮暗计数

//还原暗计数值

//如果在暗计时

//晚计数自减

//保持暗的时间到

//点亮

//还原亮计数初值

 

//elseP1&

=OxOf;

if(rba==O&

&

js3c>

=3)

i++;

if(i>

i=0;

rtobjs--;

//红到蓝时间自减

if(rtobjs==0)//时间到进入到蓝亮

js3c=1;

rba=1;

rtobjs=R_to_B_temp;

if(rba==1&

=3){

i++;

}//

if(rtobjs==0)

rba=2;

//红到蓝时间自减

红到蓝时间自减

//时间到进入到蓝亮

if(rba==2&

=3){i++;

stopjs--;

if(stopjs==0)

{js3c=1;

P1_0)〃ksj为长按标记。

如果长按,ksj置

1,否则置0

kj++;

if(kj>

70){kj=0;

ksj=1;

kj=0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1