code unsigned char tab[] = {
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
//共阳极断码值0~9,10为全灭
uchar dspbuf[8] = {
10, 10, 10, 10, 10, 10, 10, 10 };
void main()
{
cls_buzz(); //关闭buzz
AUXR = 0x80; //将定时器0设置为12分频,定时器时钟1T模式
TMOD = 0x30; //屏蔽定时器1,设置定时器0为定时模式
TL0 = 0xcd; //填入初始值,设置时间为1ms
TH0 = 0xd4;
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //允许定时器0中断
EA = 1; //开启CPU总中断允许
while(1){
}; //死循环
}
void time0(void) interrupt 1
{
display();
}
//显示函数
void display()
{
static unsigned char dspcom = 0;
P2 = (P2 & 0x1f) | 0xe0; //消影
P0 = 0xff;
P2 = 0x1f;
P2 = (P2 & 0x1f) | 0xc0; //位选
P0 = 1 << dspcom;
P2 = 0x1f;
P2 = (P2 & 0x1f) | 0xe0; //显示
P0 = tab[dspbuf[dspcom]];
P2 = 0x1f;
if (++dspcom == 8) dspcom = 0;
}
测试的时候,可以将dspbuf[]中的值,全部置为1; 以下是测试结果
#include <stc15f2k60s2.h>
#define uchar unsigned char
#define uint unsigned int
code unsigned char tab[] = {
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
//共阳极断码值0~9,10为全灭
uchar dspbuf[8] = {
10, 10, 10, 10, 10, 10, 10, 10 };
void main()
{
cls_buzz(); //关闭buzz
AUXR = 0x80; //将定时器0设置为12分频,定时器时钟1T模式
TMOD = 0x30; //屏蔽定时器1,设置定时器0为定时模式
TL0 = 0xcd; //填入初始值,设置时间为1ms
TH0 = 0xd4;
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //允许定时器0中断
EA = 1; //开启CPU总中断允许
while(1){
}; //死循环
}
void time0(void) interrupt 1
{
display();
}
void display()
{
static unsigned char dspcom = 0;
P2 = (P2 & 0x1f) | 0xe0; //消影
P0 = 0xff;
P2 = 0x1f;
P2 = (P2 & 0x1f) | 0xc0; //位选
P0 = 1 << dspcom;
P2 = 0x1f;
P2 = (P2 & 0x1f) | 0xe0; //显示
P0 = tab[dspbuf[dspcom]];
P2 = 0x1f;
if (++dspcom == 8) dspcom = 0;
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100132.html原文链接: