1、sfr IAP_ADDRH=0XC3;sfr IAP_ADDRL=0XC4;sfr IAP_CMD=0xc5;sfr IAP_TRIG=0XC6;sfr IAP_CONTR=0XC7;unsigned char liang_temp=1;unsigned char an_temp=1;unsigned char R_to_B_temp=1;unsigned char stop_temp=1;unsigned char mode=1;unsigned char time_key=0;unsigned char time_temp=0;unsigned char mode1_temp=0;ucha
2、r ajs,ljs;uchar rtobjs,stopjs,js3c=1;uchar rba=0;bit la=1;ksj=0;unsigned char code zhifu016=0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71;unsigned char code zhifu216=0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0XFe,0Xf6,0Xee,0X3e,0X9c,0X7a,0X9e,0X8e;/*void delay20(void)
3、 /误差 -0.000000000002us unsigned char a,b,c; for(c=2;c0;c-) for(b=95;bb-) for(a=209;aa-);void delay500(void) /误差 0us 500ms for(c=23; for(b=152; for(a=70;void eeprom_erase(unsigned char a) unsigned int add=512; unsigned int add1=0; add1=add*a; IAP_ADDRH=add1/255; IAP_ADDRL=add1%255; IAP_CONTR=0X8C; IA
4、P_CMD=0X03; IAP_TRIG=0X5A; IAP_TRIG=0XA5; _nop_();void eeprom_writer(unsigned int add,unsigned char date) IAP_DATA=date; IAP_ADDRH=add/255; IAP_ADDRL=add%255; IAP_CMD=2;/*unsigned char eeprom_read(unsigned int add) unsigned char date=0;/ IAP_CMD=0X01; date=IAP_DATA; return(date);void show(unsigned c
5、har a) unsigned char shi; unsigned char ge; unsigned char *p; unsigned char *p1; p=zhifu0; p1=zhifu2; shi=a/10; shi=*(p+shi);/得到编码值 ge=a%10; ge=*(p1+ge); P0=shi; P2=ge;/*void liang_key() if(!P1_0) delay20(); liang_temp+; if(liang_temp99) liang_temp=1; show(liang_temp); while(! while(ksj)liang_temp+;
6、delay20();if(liang_temp99)liang_temp=1;show(liang_temp); void an_key() if(P1_0=0) if(P1_0=0) an_temp+; if(an_temp an_temp=1; show(an_temp); while(ksj)an_temp+;if(an_temp99)an_temp=1;show(an_temp); /*void R_to_B_key() R_to_B_temp+; if(R_to_B_temp R_to_B_temp=1; show(R_to_B_temp); while(ksj)R_to_B_tem
7、p+;if(R_to_B_temp99)R_to_B_temp=1;show(R_to_B_temp); void stop_key() stop_temp+; if(stop_temp stop_temp=1; show(stop_temp); while(! while(ksj)stop_temp+;if(stop_temp99)stop_temp=1;show(stop_temp); /*void show_mode(unsigned char a) unsigned char ge=0; ge=*(p1+a);/ P0=0x00; P2=ge;void set_mode() TR1=1
8、;/开定时器 show_mode(mode); while(time_key=0) if(! delay20(); mode+; if(mode5) mode=1; time_temp=0; show_mode(mode); 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;
9、void set_fun()/设置时间的顺序是从亮,暗,红到蓝,停,4个步骤 第一个模式 unsigned char panduan=0;P1_1) P0=zhifu015; P2=zhifu21; delay500(); panduan=1; while(panduan) liang_key(); show(liang_temp); delay20(); panduan=0; ljs=liang_temp; delay20(); P0=zhifu015; P2=zhifu22; while(panduan) an_key(); show(an_temp); if(! panduan=0; a
10、js=an_temp; P2=zhifu23; R_to_B_key(); rtobjs=R_to_B_temp; panduan=1; P2=zhifu24; while(panduan) stop_key(); show(stop_temp); if(! panduan=0; 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=
11、0X0;/ red=1;/ blue=0;/ yq=yq2=0; rtobjs = R_to_B_temp; stopjs = stop_temp; ajs = an_temp; ljs = liang_temp; void mode_out(bit a1,bit a2,bit a3,bit a4)/a为停留时间,各位为输出值 P1_4=a1; P1_5=a2; P1_6=a3; P1_7=a4;void redfun(void) if(js3c4) if(la) mode_out(1,0,1,0); else mode_out(0,0,0,0); else mode_out(0,0,0,0)
12、;void bluefun(void) if(la) mode_out(0,1,0,1); else mode_out(0,0,0,0);void allfun(void) if(js3c30) time_key=1;void Timer0Interrupt(void) interrupt 1/ TR0=0; static uchar i=0; static uchar kj=0; /10 ms if(la) /如果在亮计时 ljs-; /亮计数自减 if(ljs=0) /亮的时间到 la=0; /置0亮暗计数 /还原暗计数值 else /如果在暗计时 ajs-; /晚计数自减 if(ajs=
13、0) /保持暗的时间到 la=1; /点亮 /还原亮计数初值 js3c+; /else P1&=0x0f; if(rba=0 & js3c=3) i+; if(i i=0;rtobjs-; /红到蓝时间自减 if(rtobjs=0) /时间到进入到蓝亮 js3c=1;rba=1;rtobjs=R_to_B_temp; if(rba=1 & /红到蓝时间自减rba=2; if(rba=2 & i+; stopjs-; if(stopjs=0) /时间到进入到蓝亮rba=0; rtobjs=R_to_B_temp; P1_0) /ksj为长按标记。如果长按,ksj置1,否则置0 kj+;if(kj70)kj=0;ksj=1; else kj=0; ks
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2