单片机厨房定时器仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机厨房定时器源程序如下:
- #include<reg52.h>
- sbit fmq = P2^5; //凤鸣器
- sbit mo_shi= P3^2;
- sbit jia=P3^3;
- sbit jian=P3^4;
- sbit qi_dong=P3^5;
- unsigned char code xianshi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
- 0xf8,0x80,0x90};
- unsigned char code kongzhi[]={0x0e,0x0d,0x0b,0x07};
- char fen = 1, miao = 0, ting_zhi = 1,mo=0;
- void delay(unsigned int time)
- {
- unsigned int i;
- for(i = 0; i<time; i++);
- }
- void main()
- {
- TMOD=1;
- TH0=-5000/256;
- TL0=-5000%256;
- TR0=1;
- EA=1;
- ET0=1;
- P0 = 0;
- P2 = 0xff;
- while(1) //按键控制
- {
- if(jia==0)
- {
- fmq=1;
- ting_zhi = 1;
- if(mo==1)
- {
- fen += 10;
- if((fen/10)>5) fen = fen%10;
- }
- if(mo==2)
- {
- if((fen%10)==9) fen -= 9;
- else fen++;
- }
- if(mo==3)
- {
- miao += 10;
- if((miao/10)>5) miao=miao%10;
- }
- if(mo==4)
- {
- if((miao%10)==9)
- miao -= 9;
- else miao++ ;
- }
- delay(15000);
- }
-
- if(jian==0)
- {
- fmq=1;
- ting_zhi = 1;
- if(mo==1)
- {
- if((fen/10)==0) fen = fen + 50;
- else fen = fen - 10;
- }
-
- if(mo==2)
- {
- if((fen%10)!=0) fen--;
- else fen+=9;
-
- }
- if(mo==3)
- {
- if((miao/10)==0) miao = miao + 50;
- else miao = miao - 10;
- }
-
- if(mo==4)
- {
- if((miao%10)==0) miao+=9;
- else miao--;
- }
- delay(15000);
-
- }
- if(mo_shi==0)
- {
- ting_zhi = 1;
- mo++;
- if(mo>=5) mo=0;
- if(mo<5) ;
- delay(15000);
- }
- if(qi_dong==0)
- {
- mo=0;
- if(fen!=0||miao!=0)
- {
- ting_zhi = 0;
- }
- }
- }
- }
- void LU_int()interrupt 1
- {
- static unsigned char c=0,v=0; //初值
- TH0=-5000/256; //5ms
- TL0=-5000%256;
- P2 = P2|0x0f; //0xff; //xx(1)x 1111 fmq
-
- switch(v) //判断
- {
- case 0: if(mo!=1)P0=xianshi[fen/10];
- else{
- if(c<100) P0=xianshi[fen/10]; //前0.5s 模式闪烁
- else P0=0xff; //后0.5s
- }
- break;
- case 1: if(mo!=2)P0=xianshi[fen%10]&0x7f;
- else{
- if(c<100) P0=xianshi[fen%10]&0x7f;
- else P0=0xff&0x7f;
- };
- break;//0111 1111
- case 2: if(mo!=3)P0=xianshi[miao/10];
- else{
- if(c<100) P0=xianshi[miao/10];
- else P0=0xff;
- };
- break;
- case 3: if(mo!=4)P0=xianshi[miao%10];
- else{
- if(c<100) P0=xianshi[miao%10];
- else P0=0xff;
- };
- break;
- }
- P2 = (P2&0xf0)|kongzhi[v];
-
- if(fen==0&&miao==0&&mo==0&&ting_zhi==0) //定时到点
- {
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
厨房模式定时器.zip
(63.48 KB, 下载次数: 73)
|