求程序...用AT89C51单片机的定时/计数器T0产生一秒的定时时间,作为秒计
求程序...用AT89C51单片机的定时/计数器T0产生一秒的定时时间,作为秒计数时间,当一秒产生时,秒计数加1,秒计数到60时,分别用P1.5、P1.7输出1KHz的方...
求程序...用AT89C51单片机的定时/计数器T0产生一秒的定时时间,作为秒计数时间,当一秒产生时,秒计数加1,秒计数到60时,分别用P1.5、P1.7输出1KHz的方波信号驱动扬声器和指示灯,作报警信号。注:2位显示用静态显示或动态显示均可。
展开
展开全部
#include <reg51.H>
sbit P3_5 =P3^5;
void delay()
{
unsigned char i,j;
for(j=20;j>0;j--)
for( i= 250;i>0;i--);
}
unsigned char code dispcode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x00};
unsigned char second;
unsigned char keycnt;
unsigned int tcnt;
void main(void)
{
unsigned char i,j;
TMOD=0x02;
ET0=1;
EA=1;
second=0;
P0=dispcode[second/10];
P2=dispcode[second%10];
TR0=1;
while(1)
{
if( second ==60)
{
TR0=0;
P1=0x5F;
delay();
P1=0xFF;
delay();
}
}
}
void t0(void) interrupt 1 using 0
{
tcnt++;
if(tcnt==4000)
{
tcnt=0;
second++;
P0=dispcode[second/10];
P2=dispcode[second%10];
}
}
sbit P3_5 =P3^5;
void delay()
{
unsigned char i,j;
for(j=20;j>0;j--)
for( i= 250;i>0;i--);
}
unsigned char code dispcode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x00};
unsigned char second;
unsigned char keycnt;
unsigned int tcnt;
void main(void)
{
unsigned char i,j;
TMOD=0x02;
ET0=1;
EA=1;
second=0;
P0=dispcode[second/10];
P2=dispcode[second%10];
TR0=1;
while(1)
{
if( second ==60)
{
TR0=0;
P1=0x5F;
delay();
P1=0xFF;
delay();
}
}
}
void t0(void) interrupt 1 using 0
{
tcnt++;
if(tcnt==4000)
{
tcnt=0;
second++;
P0=dispcode[second/10];
P2=dispcode[second%10];
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询