本程序所用的原理图下载:点这里,单片机芯片运用的stc89c52;找到相应部分即可.这是一整个单片机开发板的电路图其他的疏忽.
hex文件及其工程文件下载:http://www.51hei.com/f/youhuajs.rar以下是经过测验的源代码:
/**
*功用:完成一秒优化计时(只显现有用位),0~59;
*作者:徐冉
*日期:2013-05-02
**/
/************AT89C52-RC 单片机-51hei-5试验板***********/
/*******************51hei-开发板**********************/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
sbit wela = P2^7;
sbit dula = P2^6;
uchar counter,shi,ge;
uint num;
void init();
void display(uint num1);
void delay(uint xms);
//数码管编码
uchar code table[] = {
0x3F, //”0″
0x06, //”1″
0x5B, //”2″
0x4F, //”3″
0x66, //”4″
0x6D, //”5″
0x7D, //”6″
0x07, //”7″
0x7F, //”8″
0x6F //”9″
};
//主程序
void main()
{
init();
while(1)
{
display(num);
}
}
//守时器初始化程序
void init()
{
TMOD = 0x01;
TH0 = 0xB8;//准确守时20毫秒
TL0 = 0x00;
TR0 = 1;
EA = 1;
ET0 = 1;
}
//显现子程序
void display(uint num1)
{
shi = num1 / 10 % 10;
ge = num1 % 10;
if(num1 < 10)
{
dula = 1;
P0 = table[ge];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xdf;
wela = 0;
delay(1);
}
else
{
dula = 1;
P0 = table[shi];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xef;
wela = 0;
delay(1);
dula = 1;
P0 = table[ge];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xdf;
wela = 0;
delay(1);
}
}
//延时程序
void delay(uint xms)
{
uint i,j;
for(i = xms; i > 0; i–)
for(j = 110; j > 0; j–);
}
//守时器0中止服务子程序
void int_time0() interrupt 1
{
TH0 = 0xB8;
TL0 = 0x00;
counter++;
if(counter == 50)
{
counter = 0;
num++;
if(num == 60)
num = 0;
}
}