完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
14个回答
|
|
这是是我自己整理后的工程,希望大神帮忙修改
|
|
|
|
注意:下载你的附件要扣1分.
|
|
|
|
|
|
|
|
我要做一个模拟电路控制系统的设计,用C语言,但是我自己不太会用C,还有电路仿真上有很多问题。 |
|
|
|
建议直接把程序贴出来
|
|
|
|
#include
#include "12864LCD.h" #include "DS1302.h" #define uchar unsigned char #define uint unsigned int ***it L1=P3^6; ***it L2=P3^7; ***it gz1=P0^2; ***it gz2=P0^3; ***it hw3=P0^3; ***it hw2=P0^4; ***it hw1=P0^5; ***it guangkong=P3^0; ***it beep=P1^6; ***it key1=P1^0; ***it key2=P1^1; ***it key3=P1^2; ***it key4=P1^3; ***it key5=P1^4; ***it key6=P1^5; char shil1=0,fenl1=0,shih1=0,fenh1=0,shil2,fenl2=0,shih2=0,fenh2=0,num=50,tt=0; uchar aaaa=0; bit flag0,flag1,flag2,flag3,aa=1,bb=1,cc=1,dd=1,d1,d2,cc1=1,cc2=1,cc3=1; uchar code table[]={"09全国大学生电子 I 题"}; uchar code table1[]={"设计竞赛 模拟路灯控制系统"}; uchar code table2[]={"L1:"}; uchar code table3[]={"L2:"}; uchar code table4[]={"时钟设定"}; uchar code table5[]={"开关设定"}; uchar code table6[]={" (光控模式) "}; uchar code table8[]={" (自动调节模式) "}; uchar code table9[]={"Time:"}; uchar code table10[]={"菜 单"}; uchar code table11[]={"调光设定 亮度:"}; //********************************************************** void init() { //液晶屏初始化 write_onecom(0x38); write_onecom(0x01); write_onecom(0x0e); write_onecom(0x06); write_onecom(0x0c); } //********************************************************** void kaijihuamian() { //开机画面 uchar i; write_onecom(0x80); for(i=0;i<26;i++)write_onedate(table[i]); write_onecom(0x92); for(i=0;i<28;i++)write_onedate(table1[i]); } //********************************************************** void display() { //时间显示 write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onedate(0x2d); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onedate(0x3a); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //******************************************************* void timechange() { //时间设置 uchar a,num=1,i; bit flag; write_onecom(0x01); write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 display(); while(flag1!=0) { if(a<13)flag=0; else flag=1; a++; if(a==26)a=0; //----------------------------------- if(key6==0) { delay(500); if(key6==0) //按K1键退出 { while(!key6); delay(500); flag1=0; } } //------------------------------------- if(key5==0) { delay(500); if(key5==0) { //按K2键右移 while(!key5); delay(500); num++; if(num==8)num=1; } } //------------------------------------- if(key2==0) { delay(500); if(key2==0) { //按K3键左移 while(!key2); delay(500); num--; if(num==0)num=7; } } //---------------------------------------- //----------------------------------------------------------------- if(num==1) { //设置年 if(flag==0) { write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onecom(0x91); write_onedate(0x20); write_onedate(0x20); write_onedate(0x20); write_onedate(0x20); } //年光标闪烁 else { write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); } //--------------------- if(key4==0) { delay(500); if(key4==0) //按K4键年加1 { while(!key4); nian++; if(nian==100)nian=0; } } //------------------------ if(key3==0) { delay(500); if(key3==0) { while(!key3); //按K5键年减1 nian--; if(nian==-1)nian=99; } } } //---------------------------------------------------------------- if(num==2) { //设置月 if(flag==0) { write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onecom(0x93); write_onedate(0x2d); write_onedate(0x20); //月光标闪烁 write_onedate(0x20); } else { write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); } //--------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); yue++; if(yue==13)yue=1; } } //----------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); yue--; if(yue==0)yue=12; } } } //------------------------------------------------------------------------- if(num==3) { if(flag==0) { write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x95); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); } //---------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); ri++; if(ri==32)ri=1; } } //------------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); ri--; if(ri==0)ri=31; } } } //----------------------------------------------------------------------------------- if(num==4) { if(flag==0) { write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onecom(0x96); write_onedate(0x2d); write_onedate(0x20); } else { write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); } //--------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); zhou++; if(zhou==8)zhou=1; } } //----------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); zhou--; if(zhou==0)zhou=7; } } } //-------------------------------------------------------------------- if(num==5) { if(flag==0) { write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); } //------------------------ if(key4==0) { delay(500); if(key4==0) { while(!key4); shi++; if(shi==24)shi=0; } } //-------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); shi--; if(shi==-1)shi=23; } } } //---------------------------------------------------------------------------------- if(num==6) { if(flag==0) { write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); } //----------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); fen++; if(fen==60)fen=0; } } //------------------------------ if(key3==0) { delay(500); if(key3==0) { while(!key3); fen--; if(fen==-1)fen=59; } } } //-------------------------------------------------------------------------- if(num==7) { if(flag==0) { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onecom(0x8d); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //-------------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); miao++; if(miao==60)miao=0; } } //-------------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); miao--; if(miao==-1)miao=59; } } } //----------------------------------- WDS1302(YEAR,nian/10*16+nian%10); WDS1302(MONTH,yue/10*16+yue%10); WDS1302(DAY,ri/10*16+ri%10); WDS1302(HOUR,shi/10*16+shi%10); WDS1302(MINUTE,fen/10*16+fen%10); //写入DS1302 WDS1302(SECOND,(miao/10*16+miao%10)&0x7f); WDS1302(WEEK,zhou); } } //***************************************************************************************************** void shikongshezi() { uchar a,i,num6=1; bit flag; write_onecom(0x01); write_onecom(0x82); //定时设置子程序 for(i=0;i<8;i++)write_onedate(table5[i]); write_onecom(0x90); //定时设置子程序 for(i=0;i<3;i++)write_onedate(table2[i]); write_onecom(0x88); for(i=0;i<3;i++)write_onedate(table3[i]); write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); //--------------------------------- while(flag2!=0) { if(a<13)flag=0; else flag=1; //sansuoshijian a++; if(a==26)a=0; //------------------------- if(key6==0) { delay(500); if(key6==0) { //tuichu while(!key6); flag2=0; } } //--------------------------- if(key5==0) { delay(500); if(key5==0) { //youyi while(!key5); delay(500); num6++; if(num6==9)num6=1; } } //-------------------- if(key2==0) { delay(500); if(key2==0) { while(!key2); //zuoyi delay(500); num6--; if(num6==0)num6=8; } } //-------------------- if(num6==1) { if(flag==0) { write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onecom(0x92); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shil1++; if(shil1==24)shil1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shil1--; if(shil1==-1)shil1=23; } } } if(num6==2) { if(flag==0) { write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onecom(0x93); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenl1++; if(fenl1==60)fenl1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenl1--; if(fenl1==-1)fenl1=59; } } } if(num6==3) { if(flag==0) { write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x95); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shih1++; if(shih1==24)shih1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shih1--; if(shih1==-1)shih1=23; } } } if(num6==4) { if(flag==0) { write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onecom(0x96); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenh1++; if(fenh1==60)fenh1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenh1--; if(fenh1==-1)fenh1=59; } } } if(num6==5) { if(flag==0) { write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shil2++; if(shil2==24)shil2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shil2--; if(shil2==-1)shil2=23; } } } if(num6==6) { if(flag==0) { write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenl2++; if(fenl2==60)fenl2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenl2--; if(fenl2==-1)fenl2=59; } } } if(num6==7) { if(flag==0) { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); write_onecom(0x8d); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shih2++; if(shih2==24)shih2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shih2--; if(shih2==-1)shih2=23; } } } if(num6==8) { if(flag==0) { write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenh2++; if(fenh2==60)fenh2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenh2--; if(fenh2==-1)fenh2=59; } } } } write_onecom(0x01); } //************************************************************************************************* void tiaoguang() { uchar i; write_onecom(0x01); while(flag3==1) { write_onecom(0x82); for(i=0;i<17;i++)write_onedate(table11[i]); //调光设置 write_onecom(0x8b); if(num/100)write_onedate(0x31); else write_onedate(0x20); write_onedate(0x30+num%100/10); write_onedate(0x30+num%10); write_onedate(0x25); if(key4==0) { delay(500); if(key4==0) { //按K2键右移 while(!key4); delay(500); num++; if(num>100)num=100; } } if(key3==0) { delay(500); if(key3==0) { //按K2键右移 while(!key3); delay(500); num--; if(num<20)num=20; } } if(key6==0) { delay(500); if(key6==0) { //tuichu while(!key6); flag3=0; } } } } //**************************************************************************************************** void shikong() { if(shi==shil1) { if(fen==fenl1) { if(miao==0)aa=0; //((((((((((((((((( ))))))))))))))))))))))) 灯1是否打开 } } if(shi==shih1) { if(fen==fenh1) { if(miao==0)aa=1; //((((((((((((((((( ))))))))))))))))))))))) 灯1是否关闭 } } if(shi==shil2) { if(fen==fenl2) { if(miao==0)bb=0; //((((((((((((((((( ))))))))))))))))))))))) 灯2是否打开 } } if(shi==shih2) { if(fen==fenh2) { if(miao==0)bb=1; //((((((((((((((((( ))))))))))))))))))))))) 灯2是否关闭 } } } //***************************************************************************** void display1(uchar num) { write_onecom(num); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onedate(0x3a); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //***************************************************************************** void caidanjiemian() { uchar i; write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table10[i]); //菜单 write_onecom(0x90); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 write_onecom(0x88); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 write_onecom(0x98); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 } void kongge(uchar aaa) { uchar i; write_onecom(aaa); for(i=0;i<8;i++)write_onedate(0x20); } //***************************************************************************** void caidan() { uchar a=0,num1=1,i; bit flag=0; write_onecom(0x01); caidanjiemian(); while(flag0!=0) { write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table10[i]); //菜单 if(a<3)flag=0; else flag=1; a++; if(a==6)a=0; if(key6==0) //---------------- { delay(500); if(key6==0) { while(!key6); flag0=0; } } if(key5==0) //---------------- { delay(500); if(key5==0) { while(!key5); num1++; if(num1==4)num1=1; } } //------------------- if(key2==0) { delay(500); if(key2==0) { while(!key2); num1--; if(num1==0)num1=3; } } if(num1==1) { if(key1==0) { delay(500); if(key1==0) { while(!key1); flag1=1; timechange(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 kongge(0x91); } else { write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 } } if(num1==2) { if(key1==0) { delay(500); if(key1==0) { while(!key1); flag2=1; shikongshezi(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 kongge(0x89); } else { write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 } } if(num1==3) { if(key1==0) { delay(500); if(key1==0) { while(!key1); write_onecom(0x01); flag3=1; tiaoguang(); // shezhi(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 kongge(0x99); } else { write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 } } } } //***************************************************************************** void xianshijiemian() { uchar i; write_onecom(0x01); write_onecom(0x90); //定时设置子程序 for(i=0;i<5;i++)write_onedate(table9[i]); //Time: write_onecom(0x88); //定时设置子程序 for(i=0;i<2;i++)write_onedate(table2[i]); //L1 write_onecom(0x98); for(i=0;i<2;i++)write_onedate(table3[i]); //L2 write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } //--------------------------------------------- void jiemian() { uchar i,a; bit beepd1,beepd2; xianshijiemian(); while(1) //(((((((((((((((((0000000000000000000000)))))))))) { GetTime(); display1(0x93); shikong(); if(d1==0) { write_onecom(0x89); write_onedate(0xa1); //L1灯灭显示 write_onedate(0xf0); if(beepd1==1) { write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } beepd1=0; } else { delay(65536); if(gz1==0) { write_onecom(0x89); write_onedate(0xa1); //L1灯坏显示 write_onedate(0xc1); if(beepd1==0) { write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); display1(0x8b); write_onedate(0x20); } beepd1=1; } else { if(beepd1==1) { write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } beepd1=0; write_onecom(0x89); write_onedate(0xa1); //L1灯亮显示 write_onedate(0xf1); } } //---------------------------- if(d2==0) { write_onecom(0x99); write_onedate(0xa1); //L2灯灭显示 write_onedate(0xf0); if(beepd2==1) { write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } beepd2=0; } else { delay(65536); if(gz2==0) { write_onecom(0x99); write_onedate(0xa1); //L2灯坏显示 write_onedate(0xc1); if(beepd2==0) { write_onecom(0x9a); write_onedate(0x20); write_onedate(0x20); display1(0x9b); write_onedate(0x20); } beepd2=1; } else { if(beepd2==1) { write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } beepd2=0; write_onecom(0x99); write_onedate(0xa1); //L2灯亮显示 write_onedate(0xf1); } } //------------------------------------------------------------------------------------------------- if(aa==0)d1=1; else { //--------------路灯控制检测程序 if(cc==0)d1=1; else d1=0; } //----------------------------- if(bb==0)d2=1; else { if(dd==0)d2=1; else d2=0; } //----------------------------------------------------------------------------------------------- if(beepd2||beepd1) { if(a<1)beep=1; else beep=0; //声光报警 a++; if(a>=2)a=0; } else beep=1; //----------------------------------------------------------------------------------------------- if(shi>5&&shi<18) { write_onecom(0x80); //模式控制子程序 for(i=0;i<16;i++)write_onedate(table6[i]); //guangkongmoshi if(guangkong==0) { cc=0; dd=0; //(((((((((((((((((00)))))))))))光控标志位 } else { cc=1; dd=1; } } else { write_onecom(0x80); for(i=0;i<16;i++)write_onedate(table8[i]); //zhidongmoshi /* if(hw1==1) { if(cc==0)cc=1; else cc=0; } if(hw2==1) { i=cc; cc=dd; //(((((((((((((((((00)))))))))))自控标志位 dd=i; } if(hw3==1) { if(dd==0)dd=1; else dd=0; } */ } //-------------------------------------------------------------------------------------- if(key1==0) { delay(500); if(key1==0) { while(!key1); //按键进入菜单 delay(500); beep=1; flag0=1; caidan(); write_onecom(0x01); xianshijiemian(); } } //---------------------------------- } } //***************************************************************************** void main() { uint a; init(); kaijihuamian(); //光控模式为反,要注意 for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); TMOD=0x11;//设置定时器0为工作方式1 TH0=(65536-10000)/256; TL0=(65536-10000)%256; EA=1;//开总中断 ET0=1;//开定时器0中断 TR0=1;//启动定时器0 write_onecom(0x01); SetTime(); jiemian(); } void denkong() { if(num&&d1==0)L1=1; else { if(tt<20)L1=0; if(tt>=20&&tt<(num+1))L1=0; else L1=1; } if(num&&d2==0)L2=1; else { if(tt<20)L2=0; if(tt>=20&&tt<(num+1))L2=0; else L2=1; } } void time0() interrupt 1 { uchar i; TH0=(65536-200)/256; TL0=(65536-200)%256; tt++; if(tt==101)tt=0; denkong(); aaaa++; if(aaaa==10) { aaaa=0; if(shi>5&&shi<18); else { if(hw1==1)cc1=1; if(hw1==0) { delay(100); if(hw1==0) { if(hw1!=cc1) { cc1=hw1; if(cc==0)cc=1; else cc=0; } } } if(hw2==1)cc2=1; if(hw2==0) { delay(100); if(hw2==0) { if(cc2!=hw2) { cc2=hw2; i=cc; cc=dd; dd=i; } } } if(hw3==1)cc3=1; if(hw3==0) { delay(100); if(hw3==0) { if(cc3!=hw3) { cc3=hw3; if(dd==0)dd=1; else dd=0; } } } } } } |
|
|
|
#include
#include "12864LCD.h" #include "DS1302.h" #define uchar unsigned char #define uint unsigned int ***it L1=P3^6; ***it L2=P3^7; ***it gz1=P0^2; ***it gz2=P0^3; ***it hw3=P0^3; ***it hw2=P0^4; ***it hw1=P0^5; ***it guangkong=P3^0; ***it beep=P1^6; ***it key1=P1^0; ***it key2=P1^1; ***it key3=P1^2; ***it key4=P1^3; ***it key5=P1^4; ***it key6=P1^5; char shil1=0,fenl1=0,shih1=0,fenh1=0,shil2,fenl2=0,shih2=0,fenh2=0,num=50,tt=0; uchar aaaa=0; bit flag0,flag1,flag2,flag3,aa=1,bb=1,cc=1,dd=1,d1,d2,cc1=1,cc2=1,cc3=1; uchar code table[]={"09全国大学生电子 I 题"}; uchar code table1[]={"设计竞赛 模拟路灯控制系统"}; uchar code table2[]={"L1:"}; uchar code table3[]={"L2:"}; uchar code table4[]={"时钟设定"}; uchar code table5[]={"开关设定"}; uchar code table6[]={" (光控模式) "}; uchar code table8[]={" (自动调节模式) "}; uchar code table9[]={"Time:"}; uchar code table10[]={"菜 单"}; uchar code table11[]={"调光设定 亮度:"}; //********************************************************** void init() { //液晶屏初始化 write_onecom(0x38); write_onecom(0x01); write_onecom(0x0e); write_onecom(0x06); write_onecom(0x0c); } //********************************************************** void kaijihuamian() { //开机画面 uchar i; write_onecom(0x80); for(i=0;i<26;i++)write_onedate(table[i]); write_onecom(0x92); for(i=0;i<28;i++)write_onedate(table1[i]); } //********************************************************** void display() { //时间显示 write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onedate(0x2d); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onedate(0x3a); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //******************************************************* void timechange() { //时间设置 uchar a,num=1,i; bit flag; write_onecom(0x01); write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 display(); while(flag1!=0) { if(a<13)flag=0; else flag=1; a++; if(a==26)a=0; //----------------------------------- if(key6==0) { delay(500); if(key6==0) //按K1键退出 { while(!key6); delay(500); flag1=0; } } //------------------------------------- if(key5==0) { delay(500); if(key5==0) { //按K2键右移 while(!key5); delay(500); num++; if(num==8)num=1; } } //------------------------------------- if(key2==0) { delay(500); if(key2==0) { //按K3键左移 while(!key2); delay(500); num--; if(num==0)num=7; } } //---------------------------------------- //----------------------------------------------------------------- if(num==1) { //设置年 if(flag==0) { write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onecom(0x91); write_onedate(0x20); write_onedate(0x20); write_onedate(0x20); write_onedate(0x20); } //年光标闪烁 else { write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); } //--------------------- if(key4==0) { delay(500); if(key4==0) //按K4键年加1 { while(!key4); nian++; if(nian==100)nian=0; } } //------------------------ if(key3==0) { delay(500); if(key3==0) { while(!key3); //按K5键年减1 nian--; if(nian==-1)nian=99; } } } //---------------------------------------------------------------- if(num==2) { //设置月 if(flag==0) { write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onecom(0x93); write_onedate(0x2d); write_onedate(0x20); //月光标闪烁 write_onedate(0x20); } else { write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); } //--------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); yue++; if(yue==13)yue=1; } } //----------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); yue--; if(yue==0)yue=12; } } } //------------------------------------------------------------------------- if(num==3) { if(flag==0) { write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x95); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); } //---------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); ri++; if(ri==32)ri=1; } } //------------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); ri--; if(ri==0)ri=31; } } } //----------------------------------------------------------------------------------- if(num==4) { if(flag==0) { write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onecom(0x96); write_onedate(0x2d); write_onedate(0x20); } else { write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); } //--------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); zhou++; if(zhou==8)zhou=1; } } //----------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); zhou--; if(zhou==0)zhou=7; } } } //-------------------------------------------------------------------- if(num==5) { if(flag==0) { write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); } //------------------------ if(key4==0) { delay(500); if(key4==0) { while(!key4); shi++; if(shi==24)shi=0; } } //-------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); shi--; if(shi==-1)shi=23; } } } //---------------------------------------------------------------------------------- if(num==6) { if(flag==0) { write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); } //----------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); fen++; if(fen==60)fen=0; } } //------------------------------ if(key3==0) { delay(500); if(key3==0) { while(!key3); fen--; if(fen==-1)fen=59; } } } //-------------------------------------------------------------------------- if(num==7) { if(flag==0) { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onecom(0x8d); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //-------------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); miao++; if(miao==60)miao=0; } } //-------------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); miao--; if(miao==-1)miao=59; } } } //----------------------------------- WDS1302(YEAR,nian/10*16+nian%10); WDS1302(MONTH,yue/10*16+yue%10); WDS1302(DAY,ri/10*16+ri%10); WDS1302(HOUR,shi/10*16+shi%10); WDS1302(MINUTE,fen/10*16+fen%10); //写入DS1302 WDS1302(SECOND,(miao/10*16+miao%10)&0x7f); WDS1302(WEEK,zhou); } } //***************************************************************************************************** void shikongshezi() { uchar a,i,num6=1; bit flag; write_onecom(0x01); write_onecom(0x82); //定时设置子程序 for(i=0;i<8;i++)write_onedate(table5[i]); write_onecom(0x90); //定时设置子程序 for(i=0;i<3;i++)write_onedate(table2[i]); write_onecom(0x88); for(i=0;i<3;i++)write_onedate(table3[i]); write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); //--------------------------------- while(flag2!=0) { if(a<13)flag=0; else flag=1; //sansuoshijian a++; if(a==26)a=0; //------------------------- if(key6==0) { delay(500); if(key6==0) { //tuichu while(!key6); flag2=0; } } //--------------------------- if(key5==0) { delay(500); if(key5==0) { //youyi while(!key5); delay(500); num6++; if(num6==9)num6=1; } } //-------------------- if(key2==0) { delay(500); if(key2==0) { while(!key2); //zuoyi delay(500); num6--; if(num6==0)num6=8; } } //-------------------- if(num6==1) { if(flag==0) { write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onecom(0x92); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shil1++; if(shil1==24)shil1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shil1--; if(shil1==-1)shil1=23; } } } if(num6==2) { if(flag==0) { write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onecom(0x93); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenl1++; if(fenl1==60)fenl1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenl1--; if(fenl1==-1)fenl1=59; } } } if(num6==3) { if(flag==0) { write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x95); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shih1++; if(shih1==24)shih1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shih1--; if(shih1==-1)shih1=23; } } } if(num6==4) { if(flag==0) { write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onecom(0x96); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenh1++; if(fenh1==60)fenh1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenh1--; if(fenh1==-1)fenh1=59; } } } if(num6==5) { if(flag==0) { write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shil2++; if(shil2==24)shil2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shil2--; if(shil2==-1)shil2=23; } } } if(num6==6) { if(flag==0) { write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenl2++; if(fenl2==60)fenl2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenl2--; if(fenl2==-1)fenl2=59; } } } if(num6==7) { if(flag==0) { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); write_onecom(0x8d); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shih2++; if(shih2==24)shih2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shih2--; if(shih2==-1)shih2=23; } } } if(num6==8) { if(flag==0) { write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenh2++; if(fenh2==60)fenh2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenh2--; if(fenh2==-1)fenh2=59; } } } } write_onecom(0x01); } //************************************************************************************************* void tiaoguang() { uchar i; write_onecom(0x01); while(flag3==1) { write_onecom(0x82); for(i=0;i<17;i++)write_onedate(table11[i]); //调光设置 write_onecom(0x8b); if(num/100)write_onedate(0x31); else write_onedate(0x20); write_onedate(0x30+num%100/10); write_onedate(0x30+num%10); write_onedate(0x25); if(key4==0) { delay(500); if(key4==0) { //按K2键右移 while(!key4); delay(500); num++; if(num>100)num=100; } } if(key3==0) { delay(500); if(key3==0) { //按K2键右移 while(!key3); delay(500); num--; if(num<20)num=20; } } if(key6==0) { delay(500); if(key6==0) { //tuichu while(!key6); flag3=0; } } } } //**************************************************************************************************** void shikong() { if(shi==shil1) { if(fen==fenl1) { if(miao==0)aa=0; //((((((((((((((((( ))))))))))))))))))))))) 灯1是否打开 } } if(shi==shih1) { if(fen==fenh1) { if(miao==0)aa=1; //((((((((((((((((( ))))))))))))))))))))))) 灯1是否关闭 } } if(shi==shil2) { if(fen==fenl2) { if(miao==0)bb=0; //((((((((((((((((( ))))))))))))))))))))))) 灯2是否打开 } } if(shi==shih2) { if(fen==fenh2) { if(miao==0)bb=1; //((((((((((((((((( ))))))))))))))))))))))) 灯2是否关闭 } } } //***************************************************************************** void display1(uchar num) { write_onecom(num); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onedate(0x3a); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //***************************************************************************** void caidanjiemian() { uchar i; write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table10[i]); //菜单 write_onecom(0x90); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 write_onecom(0x88); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 write_onecom(0x98); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 } void kongge(uchar aaa) { uchar i; write_onecom(aaa); for(i=0;i<8;i++)write_onedate(0x20); } //***************************************************************************** void caidan() { uchar a=0,num1=1,i; bit flag=0; write_onecom(0x01); caidanjiemian(); while(flag0!=0) { write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table10[i]); //菜单 if(a<3)flag=0; else flag=1; a++; if(a==6)a=0; if(key6==0) //---------------- { delay(500); if(key6==0) { while(!key6); flag0=0; } } if(key5==0) //---------------- { delay(500); if(key5==0) { while(!key5); num1++; if(num1==4)num1=1; } } //------------------- if(key2==0) { delay(500); if(key2==0) { while(!key2); num1--; if(num1==0)num1=3; } } if(num1==1) { if(key1==0) { delay(500); if(key1==0) { while(!key1); flag1=1; timechange(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 kongge(0x91); } else { write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 } } if(num1==2) { if(key1==0) { delay(500); if(key1==0) { while(!key1); flag2=1; shikongshezi(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 kongge(0x89); } else { write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 } } if(num1==3) { if(key1==0) { delay(500); if(key1==0) { while(!key1); write_onecom(0x01); flag3=1; tiaoguang(); // shezhi(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 kongge(0x99); } else { write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 } } } } //***************************************************************************** void xianshijiemian() { uchar i; write_onecom(0x01); write_onecom(0x90); //定时设置子程序 for(i=0;i<5;i++)write_onedate(table9[i]); //Time: write_onecom(0x88); //定时设置子程序 for(i=0;i<2;i++)write_onedate(table2[i]); //L1 write_onecom(0x98); for(i=0;i<2;i++)write_onedate(table3[i]); //L2 write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } //--------------------------------------------- void jiemian() { uchar i,a; bit beepd1,beepd2; xianshijiemian(); while(1) //(((((((((((((((((0000000000000000000000)))))))))) { GetTime(); display1(0x93); shikong(); if(d1==0) { write_onecom(0x89); write_onedate(0xa1); //L1灯灭显示 write_onedate(0xf0); if(beepd1==1) { write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } beepd1=0; } else { delay(65536); if(gz1==0) { write_onecom(0x89); write_onedate(0xa1); //L1灯坏显示 write_onedate(0xc1); if(beepd1==0) { write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); display1(0x8b); write_onedate(0x20); } beepd1=1; } else { if(beepd1==1) { write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } beepd1=0; write_onecom(0x89); write_onedate(0xa1); //L1灯亮显示 write_onedate(0xf1); } } //---------------------------- if(d2==0) { write_onecom(0x99); write_onedate(0xa1); //L2灯灭显示 write_onedate(0xf0); if(beepd2==1) { write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } beepd2=0; } else { delay(65536); if(gz2==0) { write_onecom(0x99); write_onedate(0xa1); //L2灯坏显示 write_onedate(0xc1); if(beepd2==0) { write_onecom(0x9a); write_onedate(0x20); write_onedate(0x20); display1(0x9b); write_onedate(0x20); } beepd2=1; } else { if(beepd2==1) { write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } beepd2=0; write_onecom(0x99); write_onedate(0xa1); //L2灯亮显示 write_onedate(0xf1); } } //------------------------------------------------------------------------------------------------- if(aa==0)d1=1; else { //--------------路灯控制检测程序 if(cc==0)d1=1; else d1=0; } //----------------------------- if(bb==0)d2=1; else { if(dd==0)d2=1; else d2=0; } //----------------------------------------------------------------------------------------------- if(beepd2||beepd1) { if(a<1)beep=1; else beep=0; //声光报警 a++; if(a>=2)a=0; } else beep=1; //----------------------------------------------------------------------------------------------- if(shi>5&&shi<18) { write_onecom(0x80); //模式控制子程序 for(i=0;i<16;i++)write_onedate(table6[i]); //guangkongmoshi if(guangkong==0) { cc=0; dd=0; //(((((((((((((((((00)))))))))))光控标志位 } else { cc=1; dd=1; } } else { write_onecom(0x80); for(i=0;i<16;i++)write_onedate(table8[i]); //zhidongmoshi /* if(hw1==1) { if(cc==0)cc=1; else cc=0; } if(hw2==1) { i=cc; cc=dd; //(((((((((((((((((00)))))))))))自控标志位 dd=i; } if(hw3==1) { if(dd==0)dd=1; else dd=0; } */ } //-------------------------------------------------------------------------------------- if(key1==0) { delay(500); if(key1==0) { while(!key1); //按键进入菜单 delay(500); beep=1; flag0=1; caidan(); write_onecom(0x01); xianshijiemian(); } } //---------------------------------- } } //***************************************************************************** void main() { uint a; init(); kaijihuamian(); //光控模式为反,要注意 for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); TMOD=0x11;//设置定时器0为工作方式1 TH0=(65536-10000)/256; TL0=(65536-10000)%256; EA=1;//开总中断 ET0=1;//开定时器0中断 TR0=1;//启动定时器0 write_onecom(0x01); SetTime(); jiemian(); } void denkong() { if(num&&d1==0)L1=1; else { if(tt<20)L1=0; if(tt>=20&&tt<(num+1))L1=0; else L1=1; } if(num&&d2==0)L2=1; else { if(tt<20)L2=0; if(tt>=20&&tt<(num+1))L2=0; else L2=1; } } void time0() interrupt 1 { uchar i; TH0=(65536-200)/256; TL0=(65536-200)%256; tt++; if(tt==101)tt=0; denkong(); aaaa++; if(aaaa==10) { aaaa=0; if(shi>5&&shi<18); else { if(hw1==1)cc1=1; if(hw1==0) { delay(100); if(hw1==0) { if(hw1!=cc1) { cc1=hw1; if(cc==0)cc=1; else cc=0; } } } if(hw2==1)cc2=1; if(hw2==0) { delay(100); if(hw2==0) { if(cc2!=hw2) { cc2=hw2; i=cc; cc=dd; dd=i; } } } if(hw3==1)cc3=1; if(hw3==0) { delay(100); if(hw3==0) { if(cc3!=hw3) { cc3=hw3; if(dd==0)dd=1; else dd=0; } } } } } } |
|
|
|
#include
#include "12864LCD.h" #include "DS1302.h" #define uchar unsigned char #define uint unsigned int ***it L1=P3^6; ***it L2=P3^7; ***it gz1=P0^2; ***it gz2=P0^3; ***it hw3=P0^3; ***it hw2=P0^4; ***it hw1=P0^5; ***it guangkong=P3^0; ***it beep=P1^6; ***it key1=P1^0; ***it key2=P1^1; ***it key3=P1^2; ***it key4=P1^3; ***it key5=P1^4; ***it key6=P1^5; char shil1=0,fenl1=0,shih1=0,fenh1=0,shil2,fenl2=0,shih2=0,fenh2=0,num=50,tt=0; uchar aaaa=0; bit flag0,flag1,flag2,flag3,aa=1,bb=1,cc=1,dd=1,d1,d2,cc1=1,cc2=1,cc3=1; uchar code table[]={"09全国大学生电子 I 题"}; uchar code table1[]={"设计竞赛 模拟路灯控制系统"}; uchar code table2[]={"L1:"}; uchar code table3[]={"L2:"}; uchar code table4[]={"时钟设定"}; uchar code table5[]={"开关设定"}; uchar code table6[]={" (光控模式) "}; uchar code table8[]={" (自动调节模式) "}; uchar code table9[]={"Time:"}; uchar code table10[]={"菜 单"}; uchar code table11[]={"调光设定 亮度:"}; //********************************************************** void init() { //液晶屏初始化 write_onecom(0x38); write_onecom(0x01); write_onecom(0x0e); write_onecom(0x06); write_onecom(0x0c); } //********************************************************** void kaijihuamian() { //开机画面 uchar i; write_onecom(0x80); for(i=0;i<26;i++)write_onedate(table[i]); write_onecom(0x92); for(i=0;i<28;i++)write_onedate(table1[i]); } //********************************************************** void display() { //时间显示 write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onedate(0x2d); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onedate(0x3a); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //******************************************************* void timechange() { //时间设置 uchar a,num=1,i; bit flag; write_onecom(0x01); write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 display(); while(flag1!=0) { if(a<13)flag=0; else flag=1; a++; if(a==26)a=0; //----------------------------------- if(key6==0) { delay(500); if(key6==0) //按K1键退出 { while(!key6); delay(500); flag1=0; } } //------------------------------------- if(key5==0) { delay(500); if(key5==0) { //按K2键右移 while(!key5); delay(500); num++; if(num==8)num=1; } } //------------------------------------- if(key2==0) { delay(500); if(key2==0) { //按K3键左移 while(!key2); delay(500); num--; if(num==0)num=7; } } //---------------------------------------- //----------------------------------------------------------------- if(num==1) { //设置年 if(flag==0) { write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onecom(0x91); write_onedate(0x20); write_onedate(0x20); write_onedate(0x20); write_onedate(0x20); } //年光标闪烁 else { write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); } //--------------------- if(key4==0) { delay(500); if(key4==0) //按K4键年加1 { while(!key4); nian++; if(nian==100)nian=0; } } //------------------------ if(key3==0) { delay(500); if(key3==0) { while(!key3); //按K5键年减1 nian--; if(nian==-1)nian=99; } } } //---------------------------------------------------------------- if(num==2) { //设置月 if(flag==0) { write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onecom(0x93); write_onedate(0x2d); write_onedate(0x20); //月光标闪烁 write_onedate(0x20); } else { write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); } //--------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); yue++; if(yue==13)yue=1; } } //----------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); yue--; if(yue==0)yue=12; } } } //------------------------------------------------------------------------- if(num==3) { if(flag==0) { write_onecom(0x93); write_onedate(0x2d); write_onedate(0x30+yue/10); write_onedate(0x30+yue%10); write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x95); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); } //---------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); ri++; if(ri==32)ri=1; } } //------------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); ri--; if(ri==0)ri=31; } } } //----------------------------------------------------------------------------------- if(num==4) { if(flag==0) { write_onecom(0x95); write_onedate(0x30+ri/10); write_onedate(0x30+ri%10); write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onecom(0x96); write_onedate(0x2d); write_onedate(0x20); } else { write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); } //--------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); zhou++; if(zhou==8)zhou=1; } } //----------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); zhou--; if(zhou==0)zhou=7; } } } //-------------------------------------------------------------------- if(num==5) { if(flag==0) { write_onecom(0x96); write_onedate(0x2d); write_onedate(0x30+zhou%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); } //------------------------ if(key4==0) { delay(500); if(key4==0) { while(!key4); shi++; if(shi==24)shi=0; } } //-------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); shi--; if(shi==-1)shi=23; } } } //---------------------------------------------------------------------------------- if(num==6) { if(flag==0) { write_onecom(0x8a); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); } //----------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); fen++; if(fen==60)fen=0; } } //------------------------------ if(key3==0) { delay(500); if(key3==0) { while(!key3); fen--; if(fen==-1)fen=59; } } } //-------------------------------------------------------------------------- if(num==7) { if(flag==0) { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onecom(0x91); write_onedate(0x32); write_onedate(0x30); write_onedate(0x30+nian/10); write_onedate(0x30+nian%10); write_onecom(0x8d); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8d); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //-------------------------------- if(key4==0) { delay(500); if(key4==0) { while(!key4); miao++; if(miao==60)miao=0; } } //-------------------------------- if(key3==0) { delay(500); if(key3==0) { while(!key3); miao--; if(miao==-1)miao=59; } } } //----------------------------------- WDS1302(YEAR,nian/10*16+nian%10); WDS1302(MONTH,yue/10*16+yue%10); WDS1302(DAY,ri/10*16+ri%10); WDS1302(HOUR,shi/10*16+shi%10); WDS1302(MINUTE,fen/10*16+fen%10); //写入DS1302 WDS1302(SECOND,(miao/10*16+miao%10)&0x7f); WDS1302(WEEK,zhou); } } //***************************************************************************************************** void shikongshezi() { uchar a,i,num6=1; bit flag; write_onecom(0x01); write_onecom(0x82); //定时设置子程序 for(i=0;i<8;i++)write_onedate(table5[i]); write_onecom(0x90); //定时设置子程序 for(i=0;i<3;i++)write_onedate(table2[i]); write_onecom(0x88); for(i=0;i<3;i++)write_onedate(table3[i]); write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); //--------------------------------- while(flag2!=0) { if(a<13)flag=0; else flag=1; //sansuoshijian a++; if(a==26)a=0; //------------------------- if(key6==0) { delay(500); if(key6==0) { //tuichu while(!key6); flag2=0; } } //--------------------------- if(key5==0) { delay(500); if(key5==0) { //youyi while(!key5); delay(500); num6++; if(num6==9)num6=1; } } //-------------------- if(key2==0) { delay(500); if(key2==0) { while(!key2); //zuoyi delay(500); num6--; if(num6==0)num6=8; } } //-------------------- if(num6==1) { if(flag==0) { write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onecom(0x92); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shil1++; if(shil1==24)shil1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shil1--; if(shil1==-1)shil1=23; } } } if(num6==2) { if(flag==0) { write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onecom(0x93); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenl1++; if(fenl1==60)fenl1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenl1--; if(fenl1==-1)fenl1=59; } } } if(num6==3) { if(flag==0) { write_onecom(0x93); write_onedate(0x3a); write_onedate(0x30+fenl1/10); write_onedate(0x30+fenl1%10); write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x95); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shih1++; if(shih1==24)shih1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shih1--; if(shih1==-1)shih1=23; } } } if(num6==4) { if(flag==0) { write_onecom(0x95); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onecom(0x96); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenh1++; if(fenh1==60)fenh1=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenh1--; if(fenh1==-1)fenh1=59; } } } if(num6==5) { if(flag==0) { write_onecom(0x96); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shil2++; if(shil2==24)shil2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shil2--; if(shil2==-1)shil2=23; } } } if(num6==6) { if(flag==0) { write_onecom(0x8a); write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenl2++; if(fenl2==60)fenl2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenl2--; if(fenl2==-1)fenl2=59; } } } if(num6==7) { if(flag==0) { write_onecom(0x8b); write_onedate(0x3a); write_onedate(0x30+fenl2/10); write_onedate(0x30+fenl2%10); write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); write_onecom(0x8d); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); shih2++; if(shih2==24)shih2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); shih2--; if(shih2==-1)shih2=23; } } } if(num6==8) { if(flag==0) { write_onecom(0x8d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onecom(0x92); write_onedate(0x30+shil1/10); write_onedate(0x30+shil1%10); write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x20); write_onedate(0x20); } else { write_onecom(0x8e); write_onedate(0x3a); write_onedate(0x30+fenh2/10); write_onedate(0x30+fenh2%10); } if(key4==0) { delay(500); if(key4==0) { while(!key4); fenh2++; if(fenh2==60)fenh2=0; } } if(key3==0) { delay(500); if(key3==0) { while(!key3); fenh2--; if(fenh2==-1)fenh2=59; } } } } write_onecom(0x01); } //************************************************************************************************* void tiaoguang() { uchar i; write_onecom(0x01); while(flag3==1) { write_onecom(0x82); for(i=0;i<17;i++)write_onedate(table11[i]); //调光设置 write_onecom(0x8b); if(num/100)write_onedate(0x31); else write_onedate(0x20); write_onedate(0x30+num%100/10); write_onedate(0x30+num%10); write_onedate(0x25); if(key4==0) { delay(500); if(key4==0) { //按K2键右移 while(!key4); delay(500); num++; if(num>100)num=100; } } if(key3==0) { delay(500); if(key3==0) { //按K2键右移 while(!key3); delay(500); num--; if(num<20)num=20; } } if(key6==0) { delay(500); if(key6==0) { //tuichu while(!key6); flag3=0; } } } } //**************************************************************************************************** void shikong() { if(shi==shil1) { if(fen==fenl1) { if(miao==0)aa=0; //((((((((((((((((( ))))))))))))))))))))))) 灯1是否打开 } } if(shi==shih1) { if(fen==fenh1) { if(miao==0)aa=1; //((((((((((((((((( ))))))))))))))))))))))) 灯1是否关闭 } } if(shi==shil2) { if(fen==fenl2) { if(miao==0)bb=0; //((((((((((((((((( ))))))))))))))))))))))) 灯2是否打开 } } if(shi==shih2) { if(fen==fenh2) { if(miao==0)bb=1; //((((((((((((((((( ))))))))))))))))))))))) 灯2是否关闭 } } } //***************************************************************************** void display1(uchar num) { write_onecom(num); write_onedate(0x30+shi/10); write_onedate(0x30+shi%10); write_onedate(0x3a); write_onedate(0x30+fen/10); write_onedate(0x30+fen%10); write_onedate(0x3a); write_onedate(0x30+miao/10); write_onedate(0x30+miao%10); } //***************************************************************************** void caidanjiemian() { uchar i; write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table10[i]); //菜单 write_onecom(0x90); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 write_onecom(0x88); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 write_onecom(0x98); write_onedate(0x04); write_onedate(0x20); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 } void kongge(uchar aaa) { uchar i; write_onecom(aaa); for(i=0;i<8;i++)write_onedate(0x20); } //***************************************************************************** void caidan() { uchar a=0,num1=1,i; bit flag=0; write_onecom(0x01); caidanjiemian(); while(flag0!=0) { write_onecom(0x82); for(i=0;i<8;i++)write_onedate(table10[i]); //菜单 if(a<3)flag=0; else flag=1; a++; if(a==6)a=0; if(key6==0) //---------------- { delay(500); if(key6==0) { while(!key6); flag0=0; } } if(key5==0) //---------------- { delay(500); if(key5==0) { while(!key5); num1++; if(num1==4)num1=1; } } //------------------- if(key2==0) { delay(500); if(key2==0) { while(!key2); num1--; if(num1==0)num1=3; } } if(num1==1) { if(key1==0) { delay(500); if(key1==0) { while(!key1); flag1=1; timechange(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 kongge(0x91); } else { write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 } } if(num1==2) { if(key1==0) { delay(500); if(key1==0) { while(!key1); flag2=1; shikongshezi(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 kongge(0x89); } else { write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 } } if(num1==3) { if(key1==0) { delay(500); if(key1==0) { while(!key1); write_onecom(0x01); flag3=1; tiaoguang(); // shezhi(); write_onecom(0x01); caidanjiemian(); } } if(flag==0) { write_onecom(0x91); for(i=0;i<8;i++)write_onedate(table4[i]); //时间设置 write_onecom(0x89); for(i=0;i<8;i++)write_onedate(table5[i]); //定时设置 kongge(0x99); } else { write_onecom(0x99); for(i=0;i<8;i++)write_onedate(table11[i]); //调光设置 } } } } //***************************************************************************** void xianshijiemian() { uchar i; write_onecom(0x01); write_onecom(0x90); //定时设置子程序 for(i=0;i<5;i++)write_onedate(table9[i]); //Time: write_onecom(0x88); //定时设置子程序 for(i=0;i<2;i++)write_onedate(table2[i]); //L1 write_onecom(0x98); for(i=0;i<2;i++)write_onedate(table3[i]); //L2 write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } //--------------------------------------------- void jiemian() { uchar i,a; bit beepd1,beepd2; xianshijiemian(); while(1) //(((((((((((((((((0000000000000000000000)))))))))) { GetTime(); display1(0x93); shikong(); if(d1==0) { write_onecom(0x89); write_onedate(0xa1); //L1灯灭显示 write_onedate(0xf0); if(beepd1==1) { write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } beepd1=0; } else { delay(65536); if(gz1==0) { write_onecom(0x89); write_onedate(0xa1); //L1灯坏显示 write_onedate(0xc1); if(beepd1==0) { write_onecom(0x8a); write_onedate(0x20); write_onedate(0x20); display1(0x8b); write_onedate(0x20); } beepd1=1; } else { if(beepd1==1) { write_onecom(0x8a); write_onedate(0x30+shil1/10); //-------------- write_onedate(0x30+shil1%10); write_onedate(0x3a); write_onedate(0x30+fenl1/10); //L1定时时间 write_onedate(0x30+fenl1%10); write_onedate(0x2d); write_onedate(0x30+shih1/10); write_onedate(0x30+shih1%10); write_onedate(0x3a); write_onedate(0x30+fenh1/10); write_onedate(0x30+fenh1%10); } beepd1=0; write_onecom(0x89); write_onedate(0xa1); //L1灯亮显示 write_onedate(0xf1); } } //---------------------------- if(d2==0) { write_onecom(0x99); write_onedate(0xa1); //L2灯灭显示 write_onedate(0xf0); if(beepd2==1) { write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } beepd2=0; } else { delay(65536); if(gz2==0) { write_onecom(0x99); write_onedate(0xa1); //L2灯坏显示 write_onedate(0xc1); if(beepd2==0) { write_onecom(0x9a); write_onedate(0x20); write_onedate(0x20); display1(0x9b); write_onedate(0x20); } beepd2=1; } else { if(beepd2==1) { write_onecom(0x9a); //---------------------- write_onedate(0x30+shil2/10); write_onedate(0x30+shil2%10); write_onedate(0x3a); write_onedate(0x30+fenl2/10); //L2定时时间 write_onedate(0x30+fenl2%10); write_onedate(0x2d); write_onedate(0x30+shih2/10); write_onedate(0x30+shih2%10); write_onedate(0x23a); write_onedate(0x30+fenh2/10); //---------------------- write_onedate(0x30+fenh2%10); } beepd2=0; write_onecom(0x99); write_onedate(0xa1); //L2灯亮显示 write_onedate(0xf1); } } //------------------------------------------------------------------------------------------------- if(aa==0)d1=1; else { //--------------路灯控制检测程序 if(cc==0)d1=1; else d1=0; } //----------------------------- if(bb==0)d2=1; else { if(dd==0)d2=1; else d2=0; } //----------------------------------------------------------------------------------------------- if(beepd2||beepd1) { if(a<1)beep=1; else beep=0; //声光报警 a++; if(a>=2)a=0; } else beep=1; //----------------------------------------------------------------------------------------------- if(shi>5&&shi<18) { write_onecom(0x80); //模式控制子程序 for(i=0;i<16;i++)write_onedate(table6[i]); //guangkongmoshi if(guangkong==0) { cc=0; dd=0; //(((((((((((((((((00)))))))))))光控标志位 } else { cc=1; dd=1; } } else { write_onecom(0x80); for(i=0;i<16;i++)write_onedate(table8[i]); //zhidongmoshi /* if(hw1==1) { if(cc==0)cc=1; else cc=0; } if(hw2==1) { i=cc; cc=dd; //(((((((((((((((((00)))))))))))自控标志位 dd=i; } if(hw3==1) { if(dd==0)dd=1; else dd=0; } */ } //-------------------------------------------------------------------------------------- if(key1==0) { delay(500); if(key1==0) { while(!key1); //按键进入菜单 delay(500); beep=1; flag0=1; caidan(); write_onecom(0x01); xianshijiemian(); } } //---------------------------------- } } //***************************************************************************** void main() { uint a; init(); kaijihuamian(); //光控模式为反,要注意 for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); for(a=0;a<50000;a++)delay(65536); TMOD=0x11;//设置定时器0为工作方式1 TH0=(65536-10000)/256; TL0=(65536-10000)%256; EA=1;//开总中断 ET0=1;//开定时器0中断 TR0=1;//启动定时器0 write_onecom(0x01); SetTime(); jiemian(); } void denkong() { if(num&&d1==0)L1=1; else { if(tt<20)L1=0; if(tt>=20&&tt<(num+1))L1=0; else L1=1; } if(num&&d2==0)L2=1; else { if(tt<20)L2=0; if(tt>=20&&tt<(num+1))L2=0; else L2=1; } } void time0() interrupt 1 { uchar i; TH0=(65536-200)/256; TL0=(65536-200)%256; tt++; if(tt==101)tt=0; denkong(); aaaa++; if(aaaa==10) { aaaa=0; if(shi>5&&shi<18); else { if(hw1==1)cc1=1; if(hw1==0) { delay(100); if(hw1==0) { if(hw1!=cc1) { cc1=hw1; if(cc==0)cc=1; else cc=0; } } } if(hw2==1)cc2=1; if(hw2==0) { delay(100); if(hw2==0) { if(cc2!=hw2) { cc2=hw2; i=cc; cc=dd; dd=i; } } } if(hw3==1)cc3=1; if(hw3==0) { delay(100); if(hw3==0) { if(cc3!=hw3) { cc3=hw3; if(dd==0)dd=1; else dd=0; } } } } } } |
|
|
|
#define SECOND 0x80 //秒 #define MINUTE 0x82 //分鍾 #define HOUR 0x84 //小時 #define DAY 0x86 //天 #define MONTH 0x88 //月 #define WEEK 0x8a //星期 #define YEAR 0x8c //年 ***it DS1302_RST=P2^5; ***it DS1302_SCLK=P2^6; ***it DS1302_IO=P2^7; char shi=12,fen=0,miao=0,nian=9,yue=1,ri=1,zhou=4; void DS1302_Write(unsigned char D) { unsigned char i; for(i=0;i<8;i++) { DS1302_IO=D&0x01; DS1302_SCLK=1; DS1302_SCLK=0; D=D>>1; } } unsigned char DS1302_Read() { unsigned char TempDat=0,i; for(i=0;i<8;i++) { TempDat>>=1; if(DS1302_IO) TempDat=TempDat|0x80; DS1302_SCLK=1; DS1302_SCLK=0; } return TempDat; } void WDS1302(unsigned char ucAddr,unsigned char ucDat) { DS1302_RST = 0; DS1302_SCLK = 0; DS1302_RST = 1; DS1302_Write(ucAddr); // 地址,命令 DS1302_Write(ucDat); // 写1Byte数据 DS1302_SCLK = 1; DS1302_RST = 0; } unsigned char RDS1302(unsigned char ucAddr) { unsigned char ucDat; DS1302_RST = 0; DS1302_SCLK = 0; DS1302_RST = 1; DS1302_Write(ucAddr); // 地址,命令 ucDat=DS1302_Read(); DS1302_SCLK = 1; DS1302_RST = 0; return ucDat; } void SetTime() { WDS1302(YEAR,nian/10*16+nian%10); WDS1302(MONTH,yue/10*16+yue%10); WDS1302(DAY,ri/10*16+ri%10); WDS1302(HOUR,shi/10*16+shi%10); WDS1302(MINUTE,fen/10*16+fen%10); WDS1302(SECOND,(miao/10*16+miao%10)&0x7f); WDS1302(WEEK,zhou); } void GetTime() { unsigned char Temp; Temp=RDS1302(YEAR|0x01); nian=(Temp>>4)*10+(Temp&0x0f); Temp=RDS1302(0x88|0x01); yue=((Temp&0x1f)>>4)*10+(Temp&0x0f); Temp=RDS1302(DAY|0x01); ri=((Temp&0x3f)>>4)*10+(Temp&0x0f); Temp=RDS1302(HOUR|0x01); shi=((Temp&0x3f)>>4)*10+(Temp&0x0f); Temp=RDS1302(MINUTE|0x01); fen=((Temp&0x7f)>>4)*10+(Temp&0x0f); Temp=RDS1302(SECOND|0x01); miao=((Temp&0x7f)>>4)*10+(Temp&0x0f); Temp=RDS1302(WEEK|0x01); zhou=Temp&0x07; } |
|
|
|
#define lcd_date P2
***it lcde=P2^2; ***it lcdrs=P2^0; ***it lcdrw=P2^1; void delay(unsigned int time) { unsigned int n; n=0; while(n {n++;} } //读状态 void ReadSta() { do { lcd_date=0xff; lcdrs=0; lcdrw= 1; lcde= 1; } while(lcd_date&0x80==0); //检测忙信号 lcde=0; } //写数据 void write_onedate(unsigned char date) { ReadSta(); lcdrs=1; lcdrw=0; lcd_date=date; lcde=1; delay(500); lcde=0; } //写指令 void write_onecom(unsigned char com) { ReadSta(); lcdrw=0; lcdrs=0; lcd_date=com; lcde=1; delay(500); lcde=0; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
模拟路灯控制系统,我有一份单片机的代码,但是代码的电路图我始终在proteus中连接错误,实现不了;但是我还有份电路图是很详细的,但是我不知道怎么改代码。最主要的是我下载的KEIL中始终生成不了HEX文件 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
【敏矽微ME32G070开发板免费体验】使用coremark测试敏矽微ME32G070 跑分
148 浏览 0 评论
【敏矽微ME32G070开发板免费体验】开箱+点灯+点亮OLED
348 浏览 2 评论
558 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-内核编译之初次编译
252 浏览 0 评论
388 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11973 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 23:02 , Processed in 0.921438 second(s), Total 105, Slave 84 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号