本帖最后由 zhihuizhou 于 2012-2-27 09:52 编辑
/* 名称:8X8LED点阵显示数字
说明:8X8LED 点阵屏循环显
示数字 0~9,刷新过程由定时器中
断完成。
*/
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code Table_of_Digits[]=
{
0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //0
0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //1
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //2
0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //3
0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //4
0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //5
0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //6
0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //7
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8
0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00 //9
};
uchar i=0,t=0,Num_Index;
//主程序
void main()
{
P3=0x80;
Num_Index=0; //从0 开始显示
TMOD=0x00; //T0 方式 0
TH0=(8192-2000)/32; //2ms 定时
TL0=(8192-2000)%32;
IE=0x82;
TR0=1; //启动 T0
while(1);
}
//T0 中断函数
void LED_Screen_Display() interrupt 1
{
TH0=(8192-2000)/32; //恢复初值
TL0=(8192-2000)%32;
P0=0xff; //输出位码和段码
P0=~Table_of_Digits[Num_Index*8+i];
P3=_crol_(P3,1);
if(++i==8) i=0; //每屏一个数字由 8 个字节构成
if(++t==250) //每个数字刷新显示一段时间
{
t=0;
if(++Num_Index==10) Num_Index=0; //显示下一个数字
}
proteus仿真图:
|