单片机P1口接8盏LED小灯,试写一个低4盏灯和高4盏灯分别亮灭1s、循环不止的程序。要求采用定时器中断的方

2024-11-25 19:20:36
推荐回答(1个)
回答1:

#include
#define uchar unsigned char
uchar num=0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num>=20)
{
num=0;
P1=~P1;
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
P0=0xf0;
while(1);
}