用89S52编了一个交通灯的程序,但是在运行一段时间后出现死机现象,怀疑是程序跑飞了,不知道是什么原因,哪位大侠帮我看一下啊,怎么改?? #include "reg52.h"
#define unchar unsigned char #define uint unsigned int
sbit bule0 =P1^7 ; sbit yellow0 =P1^6; sbit red0 =P1^5; sbit bule1 =P1^4; sbit yellow1 =P1^3; sbit red1 =P1^2;
//******************************* // 延时 //*******************************
void delay_50ms(uint t) { uint j; for(;t>0;t--) { for(j=6245;j>0;j--) ; } }
void state1() { bule0 =0; yellow0 =1; red0 =1; bule1 =1; yellow1 =1; red1 =0; } void state2() { bule0 =1; yellow0 =0; red0 =1; bule1 =1; yellow1 =1; red1 =0; } void state3() { bule0 =1; yellow0 =1; red0 =0; bule1 =0; yellow1 =1; red1 =1; } void state4() { bule0 =1; yellow0 =1; red0 =0; bule1 =1; yellow1 =0; red1 =1; }
void main () { P1 = 0XFF; //delay_50ms(100); while(1) { state1(); delay_50ms(400); // 延时 20S state2(); delay_50ms(100); // 延时 5S state3(); delay_50ms(400); state4(); delay_50ms(100); } }
怀疑是延时哪里的问题 |