爆闪灯C51程序知识讲解.docx
- 文档编号:8061602
- 上传时间:2023-01-28
- 格式:DOCX
- 页数:19
- 大小:18.54KB
爆闪灯C51程序知识讲解.docx
《爆闪灯C51程序知识讲解.docx》由会员分享,可在线阅读,更多相关《爆闪灯C51程序知识讲解.docx(19页珍藏版)》请在冰豆网上搜索。
爆闪灯C51程序知识讲解
爆闪灯C51程序
爆闪灯
一,电子
1,灯闪模式,灯闪模式可调,4个输出端口
蓝—红一蓝一红
1234
a,四路轮流闪烁,频率可调,每路间隔可调,可一路闪,两路闪,三路
闪,四路闪可调
节例如(12—34—1234)
b,四路变换工作,每路间隔可调,例如(1—2—3—4黄闪灯模式)
c,四路组合变换闪烁,每路间隔可调,例如(1—2—3—4—12—34—
1234)
2,输出,电池板,蓄电池,开关的端口采用接线槽(路灯控制器那种接线
端子)
3,LED—种颜色的数量在45—60PCS之间,电流控制在150mA-600mA
4,电池板在15W10W6W
5,电池在20Ah,14Ah,8Ah
二,结构
1,开一套LED反光杯,以提高亮度,
2,电池板的方向可灵活调动
3,电池需固定好,不能左右,上下晃动
4,灯板和透明罩可采用插槽式的,以便好组装
5,控制器可以固定在灯壳里面,不能有漏水到上面
6,外壳设计成插槽拼接的,减少螺丝的使用率
#inelude
#includevintrins.h>
typedefunsignedcharuchar;
typedefunsignedintuint;
sbitP1_0=P1A0;
sbitP1_仁P1A1;
sbitP1_4=P1A4;
sbitP1_5=P1A5;
sbitP1_6=P1A6;
sbitP1_7=PM7;
sfrP0M0=0X94;
sfrP0M仁0X93;
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>0;b--)for(a=209;a>0;a--);
}
〃*********************************************************
voiddelay500(void)//误差0us500ms
{
unsignedchara,b,c;
for(c=23;c>0;c--)
for(b=152;b>0;b--)
for(a=70;a>0;a--);
}
〃*********************************************************
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;
IAP_TRIG=0X5A;
IAP_TRIG=0XA5;
_nop_();
_nop_();
_nop_();
}
//***********************************************************
unsignedchareeprom_read(unsignedintadd)
{
unsignedchardate=0;
IAP_ADDRH=add/255;
IAP_ADDRL=add%255;
IAP_CONTR=0X8C;//
IAP_CMD=0X01;
IAP_TRIG=0X5A;
IAP_TRIG=0XA5;
_nop_();
_nop_();
_nop_();
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();
if(!
P1_0)
{
liang_temp++;
if(liang_temp>99)
{liang_temp=1;}show(liang_temp);while(!
P1_0)
{
while(ksj){liang_temp++;delay20();if(liang_temp>99)liang_temp=1;show(
liang_temp);}
_}
}
delay20();
}
}
〃***********************************************************
voidan_key()
{_
if(P1_0==0)
{
delay20();
if(P1_0==0)
{
an_temp++;
if(an_temp>99)
{an_temp=1;}
show(an_temp);
while(!
P1_0)
{
while(ksj){an_temp++;delay20();if(an_temp>99)an_temp=1;show(an_temp);}
}
}
delay20();
}
}
〃***********************************************************
voidR_to_B_key()
{
if(P1_0==0)
{
delay20();
if(P1_O==O)
{
R_to_B_temp++;
if(R_to_B_temp>99)
{
R_to_B_temp=1;
}
show(R_to_B_temp);
while(!
P1_0)
{
while(ksj){R_to_B_temp++;delay20();if(R_to_B_temp>99)R_to_B_temp=1;show(R_to_B_temp);}
}
}
delay20();
}
}
〃***********************************************************
voidstop_key()
{_
if(P1_0==0)
{
delay20();
if(P1_0==0)
{
stop_temp++;
if(stop_temp>99)
{stop_temp=1;}show(stop_temp);
while(!
P1_0)
{
while(ksj){stop_temp++;delay20();if(stop_temp>99)stop_temp=1;show(sto
P_temp);}
}
}
delay20();
}
}
〃************************************************************
voidshow_mode(unsignedchara)
{_
unsignedcharge=0;
unsignedchar*p1;
p仁zhifu2;
ge=*(p1+a);
//P0=0x00;
P2=ge;
}
〃************************************************************
voidset_mode()
{_
if(!
P1_0)
{
delay20();
TR1=1;〃开定时器
if(!
P1_0)
{
show_mode(mode);
}_
while(time_key==0)
{_
if(!
P1_0)
{
delay20();
if(!
P1_0)
{
mode++;
if(mode>5)
{
mode=1;
time_temp=0;
}_
show_mode(mode);delay20();
}
}
TR1=0;〃关定时器
time_key=0;
time_temp=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;
if(!
P1_1)
{
delay20();
if(!
P1_1)
{
P0=zhifu0[15];
P2=zhifu2[1];
delay500();
delay500();
panduan=1;
while(panduan)
{
liang_key();
show(liang_temp);
if(!
P1_1)
{
delay20();
panduan=0;
ljs=liang_temp;delay20();
}
}
panduan=1;
P0=zhifu0[15];
P2=zhifu2[2];
delay500();
delay500();
while(panduan)
{
an_key();
show(an_temp);
if(!
P1_1)
{
delay20();
panduan=0;ajs=an_temp;
delay20();
}
}
panduan=1;
P0=zhifu0[15];
P2=zhifu2[3];delay500();delay500();
while(panduan)
{R_to_B_key();
show(R_to_B_temp);
if(!
P1_1)
{
delay20();
panduan=0;rtobjs=R_to_B_temp;delay20();
}
panduan=1;
P0=zhifu0[15];
P2=zhifu2[4];delay500();delay500();
while(panduan)
{
stop_key();show(stop_temp);if(!
P1_1)
{delay20();
panduan=0;stopjs=stop_temp;delay20();
}
}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;
rba=0;
}
}
}
〃***********************************************************
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(js3c<4)
{
if(la)mode_out(0,1,0,1);
elsemode_out(0,0,0,0);
}_
elsemode_out(0,0,0,0);
}_
voidallfun(void)
{
if(js3c<4)
{
if(la)mode_out(1,1,1,1);
elsemode_out(0,0,0,0);
}
elsemode_out(0,0,0,0);
}_
〃***********************************************************
voidmode1()〃模式1
{
〃unsignedchara=0;
switch(rba)
{
case0:
redfun();break;
case1:
bluefun();break;case2:
allfun();break;default:
break;
}
}
voidmode_work(unsignedchara)//参数为模式
{switch(a)
{
case1:
mode1();break;//第一种模式
case2:
mode1();break;case3:
mode1();break;case4:
mode1();break;case5:
mode1();break;}
}
/*
voiddecipherment_dog()〃解密完后才能使用本控制器
{
if((P1_O==O)&(P1_1==0))
{
}
}*/
〃***********************************************************
voidInitTimerl(void)
{
TMOD=0x11;
TH1=0x3C;
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;
P0=0;
P2=0;
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;stopjs=stop_temp;
ajs=an_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(js3c<4)
{
if(la)//
{
Ijs--;
if(ljs==0)
{
la=0;
ajs=an_temp;
}
}
else
{
ajs--;
if(ajs==0)
{
la=1;
ljs=liang_temp;
js3c++;
}
〃10ms
如果在亮计时
//亮计数自减
//亮的时间到
//置0亮暗计数
//还原暗计数值
//如果在暗计时
//晚计数自减
//保持暗的时间到
//点亮
//还原亮计数初值
//elseP1&=OxOf;
if(rba==O&&js3c>=3)
{
i++;
if(i>5)
{
i=0;rtobjs--;//红到蓝时间自减
}
if(rtobjs==0)//时间到进入到蓝亮
{
js3c=1;rba=1;rtobjs=R_to_B_temp;
}
}
if(rba==1&&js3c>=3){
i++;
if(i>5)
{
i=0;rtobjs--;
}//
if(rtobjs==0)
{
js3c=1;rba=2;stopjs=stop_temp;
}_
}
//红到蓝时间自减
红到蓝时间自减
//时间到进入到蓝亮
if(rba==2&&js3c>=3){i++;
if(i>5)
{
i=0;
stopjs--;
//
红到蓝时间自减
//时间到进入到蓝亮
}
if(stopjs==0)
{js3c=1;rba=0;rtobjs=R_to_B_temp;
}
}
if(!
P1_0)〃ksj为长按标记。
如果长按,ksj置
1,否则置0
{
kj++;if(kj>70){kj=0;ksj=1;}
}
else
{
kj=0;
ksj=0;
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 爆闪灯 C51 程序 知识 讲解