C51单片机编程 求按下按键 8盏LED灯闪烁3次后 灯灭 闪烁频率为1HZ
2个回答
展开全部
#include<reg51.h>
#define uchar unsigned char
uchar times=6,dcnt=0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
dcnt++;
if(dcnt>=10)
{
dcnt=0;
P0=~P0;
times--;
if(times==0){TR0=0;P0=0xff);}
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
P0=0x00;
while(1);
}
#define uchar unsigned char
uchar times=6,dcnt=0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
dcnt++;
if(dcnt>=10)
{
dcnt=0;
P0=~P0;
times--;
if(times==0){TR0=0;P0=0xff);}
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
P0=0x00;
while(1);
}
追问
请问按键在哪里?刚学不怎么会请见谅
追答
#include
#define uchar unsigned char
uchar times=6,dcnt=0;
sbit key=P1^0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
dcnt++;
if(dcnt>=10)
{
dcnt=0;
P0=~P0;
times--;
if(times==0){TR0=0;P0=0xff);}
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
P0=0x00;
while(1)
{
if(key==0){while(key==0);TR0=1;}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询