#include #define uchar unsigned char #define uint unsigned int #define ulong unsigned long sbit DULA = P2^6; sbit WELA = P2^7; unsigned char code WETable[8] = { ~0x80,~0x40,~0x20,~0x10, ~0x08,~0x04,~0x02,~0x01 }; unsigned char code DUTable[16] = { 0x3F,0x06,0x5B,0x4F, 0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C, 0x39,0x5E,0x79,0x71 }; unsigned char LedBuff[8] = { 0x3F,0x3F,0x3F,0x3F, 0x3F,0x3F,0x3F,0x3F }; bit flag = 0; void Timer0Init(void); //1毫秒@11.0592MHz void main(void) { unsigned long sec = 0; Timer0Init(); while(1) { if(1==flag) { flag = 0; sec++; LedBuff[0] = DUTable[sec/1%10]; LedBuff[1] = DUTable[sec/10%10]; LedBuff[2] = DUTable[sec/100%10]; LedBuff[3] = DUTable[sec/1000%10]; LedBuff[4] = DUTable[sec/10000%10]; LedBuff[5] = DUTable[sec/100000%10]; LedBuff[6] = DUTable[sec/1000000%10]; LedBuff[7] = DUTable[sec/10000000%10]; } } } void Timer0Init(void) //1毫秒@11.0592MHz { EA = 1; ET0 = 1; //AUXR &= 0x7F; //定时器时钟12T模式 TMOD &= 0xF0; //设置定时器模式 TMOD |= 0x01; //设置定时器模式 TL0 = 0x66; //设置定时初值 TH0 = 0xFC; //设置定时初值 TF0 = 0; //清除TF0标志 TR0 = 1; //定时器0开始计时 } void LedScan(void) { static unsigned char i = 0; P0 = 0x00; DULA = 1; DULA = 0; P0 = WETable[i]; WELA = 1; WELA = 0; P0 = LedBuff[i]; DULA = 1; DULA = 0; if(i<7) { i++; } else { i = 0; } } void InterruptTimer0(void) interrupt 1 { static unsigned int cnt = 0; TL0 = 0x66; //设置定时初值 TH0 = 0xFC; //设置定时初值 LedScan(); cnt++; if(cnt>=1000) { cnt = 0; flag = 1; } }
上一篇:51单片机-点阵模块-横向移动-i love u
下一篇:51单片机-LED模块-来回流水灯
推荐阅读最新更新时间:2024-11-08 09:21
设计资源 培训 开发板 精华推荐
- 具有 400mA 突发模式操作、2.25MHz 同步降压稳压器的 LTC3621EDCB-5 5Vout 的典型应用
- 【物联网】鸿蒙智能开关+492390A
- LT3990EMSE-3.3 1.21V 降压转换器的典型应用
- 2相单极步进电机驱动IC —— TB67S149FG
- LTC2209UP 演示板,高 IF,LVDS 输出,160Msps,16 位 ADC,1MHz < Ain <80MHz
- RD33771CDSTEVB: MC33771C BCC评估板,具有隔离的菊花链通信
- 具有可编程调光控制的 RT8537 电流模式升压型 LED 驱动器的 6 颗高亮度 LED 的典型应用
- 时钟控制/2相双极型步进电机驱动IC —— TC78H670FTG
- NCV33074ADTBR2G快速建立逆变器的典型应用
- 具有 ON/OFF 拨动开关的 LF18ABPT-TR 1.8V 多路低压降稳压器电源的典型应用