设计一个秒脉冲发生器
任务描述:应用单片机定时/计数器设计一个秒脉冲发生器,并用2位数码管显示脉冲数
文章目录
要求
1.在Keil IDE(u Vision2)中完成应用程序设计,并编译
2.在ISIS 7 Professional 中完成电路设计、调试与仿真
/**
I use a timer in my code to control the time
**/
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar second=0,counter=0,second_1=0,second_0=0,time=0;
/******************************Timer******************************/
void init_timer()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
counter++;
time++;
}
/******************************Display_Tube******************************/
void display_Tube()
{
if(counter==20)
{
counter=0;
second++;
if((second>60)||(second==60))
{
second=0;
}
second_1=second/10;
second_0=second%10;
}
}
void display()
{
if(time==5)
{
time=0;
P2=tab[second_1];
P3=0x01;
}
P3=0x00;
if(time==5)
{
time=0;
P2=tab[second_0];
P3=0x02;
}
P3=0x00;
}
/******************************Main******************************/
void main()
{
init_timer();
while(1)
{
display_Tube();
display();
}
}
/**
Writer: Terence
Email: 3117807944@qq
Date: 2020-10-24
etc: If there is a problem with the code, you can call me.
I will solve the problem in the first time
**/