#include <REGX52.H>
#define LED_PORT P1
unsigned int g_u8LedDisplayBuffer[8]={0}; //显示缓冲区
code unsigned int g_u8LedDisplayCode[]=
{
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x40
};
sbit io_led_seg_cs=P2^0;
sbit io_led_bit_cs=P2^1;
bit g_bSystemTime2Ms=0; // 2msLED 动态扫描时标消息
static void SendLedSegData(unsigned int dat)
{
LED_PORT=dat;
io_led_seg_cs=1; //开段码锁存,送段码数据
io_led_seg_cs=0 ;
}
static void SendLedBitData(unsigned int dat)
{
unsigned int temp;
temp=(0xfe<<dat); //根据要选通的位计算出位码
LED_PORT=temp;
io_led_bit_cs=1; //开位码锁存,送位码数据
io_led_bit_cs=0;
}
void LedDisplay(unsigned int *pBuffer)
{
static unsigned int s_LedDisPos=0;
if(g_bSystemTime2Ms)
{
g_bSystemTime2Ms=0;
SendLedBitData(8); //消隐,只需要设置位选不为0~7 即可
if(pBuffer[s_LedDisPos]== '-') //显示'-'号
{
SendLedSegData(g_u8LedDisplayCode[16]) ;
}
else
{
SendLedSegData(g_u8LedDisplayCode[pBuffer[s_LedDisPos]]) ;
}
SendLedBitData(s_LedDisPos);
if(++s_LedDisPos >7)
{
s_LedDisPos=0;
}
}
}
void Timer0Init( )
{
TMOD=0xf0;
TMOD=0x01; //定时器0 工作方式1
TH0=0xf8; //定时器初始值
TL0=0xcc;
TR0=1;
ET0=1;
}
void Time0Isr( ) interrupt 1
{
TH0=0xf8; //定时器重新赋初值
TL0=0xcc;
g_bSystemTime2Ms=1; //2MS 时标标志位置位
}
压缩包里包含了仿真文件,请高手帮看下
状态机动态显示.rar
(58.87 KB, 下载次数: 10)
2013-11-21 22:03 上传
点击文件名下载附件
一周热门 更多>