明天帮你看吧,没加注释,有点晕,^_^。
你的编译可以通过,但是放到我proteus仿真电路上不好使,显示不出来。
看了一下你的代码占用code小好多,明天来仔细研究下你的吧。
先贴我的吧。。。- #include <REGX51.H>
- #include <intrins.h>
- #define KEY_1 P3_2 //开始流动
- #define KEY_2 P3_3 //停止流动,并全熄灭
- #define KEY_3 P3_4 //从上往下流动
- #define KEY_4 P3_5 //从下往上流动
- #define crol _crol_
- #define cror _cror_
- static unsigned char status = 0;
- unsigned char index = 0;
- unsigned char lightRun[10] = {0xFE,0XFB,0X7F,0XC7,0X12,0X7F,0XFB,0X9D,0X5D,0X3F}; //开关1合上后按此表滚动
- void delay(void); //延时
- void directRun(void); //决定方向。
- void main(void)
- {
- unsigned char start;
- unsigned char i = 150;
- TCON = (TCON & 0X00) | 0X00; //开外部中断1
- IE = 0X84;
- PX1 = 1;
- start = 0xFE; //显示状态初始化
- while(KEY_1 != 0); //等待开关1合上
- while(1)
- {
- directRun();
- P1 = status;
- while(i--)
- delay();
- }
- }
- void delay(void) //延时50ms
- {
- TMOD = (TMOD & 0X0F) | 0X01;
- TL0 = (-50000)%256;
- TH0 = (-50000)/256;
- TR0 = 1;
- while(TF0 != 1);
- TR0 = 0;
- }
- void directRun(void)
- {
- if(KEY_1 == 0 && KEY_3 != 0 && KEY_4 != 0) //仅仅按下开关1,按表循环显示。
- {
- status = lightRun[index++];
- if(index >= 10)
- index = 0;
- }
- if(KEY_3 == 0 && KEY_4 != 0) //合上开关3,向下移动
- status = crol(status, 1);
- if(KEY_4 == 0 && KEY_3 != 0) //合上开关4,向下移动
- status = cror(status, 1);
- }
- void intx1intr(void) interrupt 2 //合上开关2,全部灯灭,等待按下开关1启动。
- {
- P1 = 0XFF;
- while(KEY_1 != 0);
- P1 = status;
- }
|