想了半天,终于实现了定时器+左右流水灯
下面贴代码
- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define LED P1
- uchar code water_led1[] = {0XFE,0XFD,0XFB,0XF7,
- 0XEF,0XDF,0XBF,0X7F};//正向流动
- uchar code water_led2[] = {0X7F,0XBF,0XDF,0XEF,
- 0XF7,0XFB,0XFD,0XFE};//反向流动
- void main ()
- {
- uint count = 0;
- uint i = 0;
- TMOD = 0X01;//定时器设置为工作模式1
- TH0 = 0XB8;
- TL0 = 0X00;
- TR0 = 1;//启动T0
- while (1)
- {
- if (TF0 == 1)//判断TF0是否溢出
- {
- TF0 = 0;//T0溢出后,清零
- TH0 = 0XB8;
- TL0 = 0X00;
- count ++;
- if (count == 10)//计数满200ms
- {
- count = 0;
- if ( i < 8 )
- LED = water_led1[i];
- if ( i >= 8 )
- LED = water_led2[i - 8 ];
- i ++;
- if ( i == 16 )
- i = 0;
- }
- }
- }
- }
复制代码
老司机勿笑,毕竟新手上路!
|