爆闪灯C51程序知识讲解.docx

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

爆闪灯C51程序知识讲解.docx

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

爆闪灯C51程序知识讲解.docx

爆闪灯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,电池板在15W,10W,6W

5,电池在20Ah,14Ah,8Ah

二,结构

1,开一套LED反光杯,以提高亮度,

2,电池板的方向可灵活调动

3,电池需固定好,不能左右,上下晃动

4,灯板和透明罩可采用插槽式的,以便好组装

5,控制器可以固定在灯壳里面,不能有漏水到上面

6,外壳设计成插槽拼接的,减少螺丝的使用率

#include

#include

typedefunsignedcharuchar;

typedefunsignedintuint;

sbitP1_0=P1^0;

sbitP1_1=P1^1;

sbitP1_4=P1^4;

sbitP1_5=P1^5;

sbitP1_6=P1^6;

sbitP1_7=P1^7;

sfrP0M0=0X94;

sfrP0M1=0X93;

sfrP2M0=0X96;

sfrP2M1=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=0X8C;

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;

p1=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_0==0)

{

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(stop_temp);}

}

}

delay20();

}

}

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

voidshow_mode(unsignedchara)

{

unsignedcharge=0;

unsignedchar*p1;

p1=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;

}

}

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

voidset_fun()//设置时间的顺序是从亮,暗,红到蓝,停,4个步骤第一个模式

{

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_0==0)&(P1_1==0))

{

}

}*/

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

voidInitTimer1(void)

{

TMOD=0x11;

TH1=0x3C;

TL1=0xB0;

EA=1;

ET1=1;

}

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

voidInitTimer0(void)

{

TH0=0xf2;

TL0=0xfb;

ET0=1;

TR0=1;

}

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

main()

{

InitTimer1();

InitTimer0();

P0M0=0XFF;//配成强上拉

P0M1=0X00;

P2M0=0XFF;

P2M1=0X00;

P1M1=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=0xcb;

time_temp++;

if(time_temp>30)

{

time_key=1;

}

}

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

voidTimer0Interrupt(void)interrupt1

{

//TR0=0;

staticuchari=0;

staticucharkj=0;

TH0=0xf2;//10ms

TL0=0xfb;

if(js3c<4)

{

if(la)//如果在亮计时

{

ljs--;//亮计数自减

if(ljs==0)//亮的时间到

{

la=0;//置0亮暗计数

ajs=an_temp;//还原暗计数值

}

}

else//如果在暗计时

{

ajs--;//晚计数自减

if(ajs==0)//保持暗的时间到

{

la=1;//点亮

ljs=liang_temp;//还原亮计数初值

js3c++;

}

}

}

//elseP1&=0x0f;

if(rba==0&&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;}

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

当前位置:首页 > 初中教育 > 数学

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

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