/****************************************/
/* Copyright (c) 2004, 通信工程学院戴佳 */
/* All rights reserved. */
/* 作 者:戴佳 */
/****************************************/
/* 4位8段数码管分别动态显示“1234”, */
#include "7LEDShow.h"
void main()
{
DIGPORT = 0; // 关闭显示
TMOD = 0x01; // T0工作方式1
/* 2ms 定时设置 */
time0_tmp = 65536-time0*fosc/12;
TH0 = (time0_tmp/256);
TL0 = (time0_tmp%256);
TR0 = 1;
ET0 = 1;
EA = 1;
digbit = 0x01; // 从第一位数码管开始
wordbuf[3] = 4;
wordbuf[2] = 3;
wordbuf[1] = 2;
wordbuf[0] = 1;
while(1);
}
/* 定时器0中断服务子程序,定时动态扫描显示 */
void time0_int(void) interrupt 1
{
TH0 = (time0_tmp/256);
TL0 = (time0_tmp%256);
display();
}
/* 根据共阴极字型编码表获取0~9,A~B字型代码 */
uchar getcode(uchar i)
{
uchar p;
switch (i)
{
case 0: p=0x3f; break; /* 0 */
case 1: p=0x06; break; /* 1 */
case 2: p=0x5B; break; /* 2 */
case 3: p=0x4F; break; /* 3 */
case 4: p=0x66; break; /* 4 */
case 5: p=0x6D; break; /* 5 */
case 6: p=0x7D; break; /* 6 */
case 7: p=0x07; break; /* 7 */
case 8: p=0x7F; break; /* 8 */
case 9: p=0x67; break; /* 9 */
case 10: p=0x77; break; /* A */
case 11: p=0x7C; break; /* B */
case 12: p=0x39; break; /* C */
case 13: p=0x5E; break; /* D */
case 14: p=0x79; break; /* E */
case 15: p=0x71; break; /* F */
default: break;
}
return(p);
}
/* 显示函数 */
void display(void)
{
uchar i;
switch (digbit)
{
case 1: i=0;break;
case 2: i=1;break;
case 4: i=2;break;
case 8: i=3;break;
default: break;
}
DIGPORT = 0; // 关闭显示
WORDPORT = getcode(wordbuf[i]); // 送字型码
DIGPORT = digbit; // 送字位码
if (digbit<0x08)
digbit = digbit*2;
else
digbit = 0x01;
}