各位老师好,我的这段程序想在设定的时间到达时,P1^7对应的LED 灯亮,但实际测试时灯不亮,能请各位老师帮忙看一下吗,谢谢
单片机源程序如下:
- #include<reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar hour_now,hour_set,min_now,min_set,sec_now,sec_set;
- uint time_t;
- sbit led7=P1^7;
- sbit beep=P2^3;
- sbit led0=P1^0;
- void delay1ms(uint x)
- {
- TMOD=0X20;
- TR1=1;
- while(x--)
- {
- TH1=0Xfc;
- TL1=0X18;
- while(!TF1);
- TF1=0;
- time_t++;
- }
- TR1=0;
- }
- void dingshi()
- {
- while(1)
- {
- if((hour_now=hour_set)&&(min_now=min_set)&&(sec_now=sec_set))
-
- led7=0;
- while(1)
- delay1ms(20);
- sec_now++;
- if(sec_now>=60)
- {
- sec_now=0;
- min_now++;
- if(min_now>=60)
- {
- min_now=0;
- hour_now++;
- if(hour_now>=24)
- {
- hour_now=0;
- }
- }
- }
- }
- }
- void main()
- {
- hour_now=23;
- min_now=59;
- sec_now=50;
- hour_set=0;
- min_set=0;
- sec_set=0;
- while(1)
- {
- dingshi();
- }
- }
复制代码
|