以下是程序,下载到板子上不能实现一秒变化一次,大概8秒才一次
#include<reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
code uint8 number[] = {0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xa7,0xa1,0x86,0x8e}; //【16进制数组】
uint8 i = 0;
uint16 counter = 0;
//sbit ENLED = P1^4;
sbit SMG1 = P3^4;
sbit SMG2 = P3^5;
sbit SMG3 = P3^6;
sbit SMG4 = P3^7;
void timer1_init() //定时器初始化
{
TMOD |= 0x01;
TH1 = 0xfc;
TL1 = 0x67; //1ms
TR1 = 1;
}
void int_init() //中断初始化
{
ET1 = 1;
EA = 1;
}
main()
{
P0 = 0xff;P3 = 0xff;
timer1_init();
int_init();
while(1);
}
void refresh() //数码管动态扫描显示
{
static uint8 j = 0;
switch(j)
{
case 0: SMG1 = 0;P0 = number[i];break;
case 1: SMG2 = 0;P0 = number[i];break;
case 2: SMG3 = 0;P0 = number[i];break;
case 3: SMG4 = 0;P0 = number[i];break;
default: break;
}
if(3 == j++)
j = 0;
}
void interrupt_timer1() interrupt 3
{
TH1 = 0xfc;
TL1 = 0x67;
counter++;
if(1000 == counter)
{
i++;
if(15 == i)
{
i = 0;
}
}
refresh();
}
附上原理图
在线等 谢谢各位了~~
此帖出自
小平头技术问答
void timer1_init() //定时器初始化
{
//初始化
}
void display(void)
{
//显示函数
}
main()
{
P0 = 0xff;P3 = 0xff;
timer1_init();
while(1)
{
if(timer>=1)
{
dispaly_time++;
check_time++;
timer=0;
}
if(display_time>=Display_Timer)
{
dispaly_time=0;
display();
}
if(check_time>=Check_Timer)
{
check_time=0;
//定时加1
}
}
}
void interrupt_timer1() interrupt 3
{
TH1 = 0xfc;
TL1 = 0x67;
timer++;
}
一周热门 更多>