基于C语言在8×8点阵实现9到0倒计时牌显示。
每个数之间为1秒间隔,采用定时器实现。
#include sbit ADDR0 = P1^0; sbit ADDR1 = P1^1; sbit ADDR2 = P1^2; sbit ADDR3 = P1^3; sbit ENLED = P1^4; code unsigned char image[10][8]={ {0xFF,0xC3,0xDB,0xDB,0xC3,0xDF,0xDF,0xC3}, //要显示数字9时,对于的P0值 {0xFF,0xC3,0xDB,0xDB,0xC3,0xDB,0xDB,0xC3}, {0xFF,0xC3,0xDF,0xDF,0xDF,0xDF,0xDF,0xDF}, //要显示数字7时,对于的P0值 {0xFF,0xFB,0xFB,0xFB,0xC3,0xDB,0xDB,0xC3}, {0xFF,0xC3,0xFB,0xFB,0xC3,0xDF,0xDF,0xC3}, {0xFF,0xDB,0xDB,0xDB,0xC3,0xDF,0xDF,0xDF}, {0xFF,0xC3,0xDF,0xDF,0xC3,0xDF,0xDF,0xC3}, {0xFF,0xC3,0xDF,0xDF,0xC3,0xFB,0xFB,0xC3}, {0xEF,0xE7,0xE3,0xE7,0xE7,0xE7,0xE7,0x81}, {0xFF,0xC3,0xDB,0xDB,0xDB,0xDB,0xC3,0xFF} }; void main() { ENLED = 0; //使能点阵 ADDR3 = 0; EA = 1; //打开中断 ET0 = 1; TMOD = 0x01; //定时器初始化 TH0 = 0xFC; TL0 = 0x67; TR0 = 1; while(1); } void InterrupTimer0() interrupt 1 { static unsigned long cnt = 0; //ms计数 static unsigned char sec = 0; //s计数 static unsigned char i = 0; //点阵行号 TH0 = 0xFC; //定时器重新赋值,保证每次为1ms TL0 = 0x67; cnt++; if(cnt>=1000) { cnt = 0; sec++; if(sec>9) { sec = 0; } } P0 = 0xFF; //消隐 switch(i) { case 0 : ADDR2 = 0;ADDR1 = 0;ADDR0 = 0;i++;P0 = image[sec][0];break; case 1 : ADDR2 = 0;ADDR1 = 0;ADDR0 = 1;i++;P0 = image[sec][1];break; case 2 : ADDR2 = 0;ADDR1 = 1;ADDR0 = 0;i++;P0 = image[sec][2];break; case 3 : ADDR2 = 0;ADDR1 = 1;ADDR0 = 1;i++;P0 = image[sec][3];break; case 4 : ADDR2 = 1;ADDR1 = 0;ADDR0 = 0;i++;P0 = image[sec][4];break; case 5 : ADDR2 = 1;ADDR1 = 0;ADDR0 = 1;i++;P0 = image[sec][5];break; case 6 : ADDR2 = 1;ADDR1 = 1;ADDR0 = 0;i++;P0 = image[sec][6];break; case 7 : ADDR2 = 1;ADDR1 = 1;ADDR0 = 1;i=0;P0 = image[sec][7];break; default : break; } }
上一篇:51单片机课程设计——led点阵广告牌程序设计
下一篇:单片机实例---定时器控制点阵显示0~9
推荐阅读最新更新时间:2024-11-17 06:08
设计资源 培训 开发板 精华推荐
- LT6108-2 演示板、具有基准和比较器的高侧电流检测放大器
- STC8A8K64D4 LCM_DMA开发板
- DER-613 - 27 W USB PD 3.0,采用 3.3 V-11 V PPS 电源,使用 InnoSwitch3-Pro 和 Weltrend WT6635P 控制器(单板设计)
- 使用 Analog Devices 的 AD5611AKS 的参考设计
- 用于白光 LED 驱动器的 TB62737FPG 升压型 DC-DC 转换器的典型应用
- LT3083 演示板、可调 3A 单电阻器低压差稳压器
- CN3722太阳能充电器
- 具有浪涌保护和反向保护功能的 LTC3897EFE 24V/10A 2 相同步升压转换器的典型应用电路
- 具有 400mA 突发钳位、fSW = 1MHz 同步降压型稳压器的 LTC3621EMS8E-2 2.5V Vout 的典型应用
- BD49xxx系列BD49K50电压检测IC的典型应用