- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit dengguan=P1^0;
- sbit zhujiti=P1^1;
- sbit jidianqi=P1^2;
- uchar count=0,miao=0;
- ///////////////////////////////////////////////////////////
- void time0()
- {
- TMOD=0x01; //设置定时器0和1工作方式为1(0001 0001)
- TH0=(65536-50000)/256; //装定时器初值
- TL0=(65536-50000)%256;
- EA=1; //开总中断
- ET0=1; //开定时器0中断
- TR0=0; //关闭时器0
- }
- void main(void)
- {
- time0();
- while(1)
- {
-
- if(dengguan==1&&zhujiti==0)
- {
- jidianqi=0;TR0=1;
-
- }
-
-
- }
- }
- void timer0(void) interrupt1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- count++;
- if (count == 20)
- {
- count = 0;
- miao++;
- if(miao>=10)
- {
- miao=0;TR0=0;
- jidianqi=1;
-
- }
-
- }
- }
复制代码
|