8051的P1口接有8只发光二极管,请用定时器中断控制连接在奇数位的LED和连接在偶数位LED一次亮灭

2024-12-12 01:55:30
推荐回答(1个)
回答1:

#include
#define uchar unsigned char
#define uint unsigned int
void timer_init()
{
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
IT0=1;
TR0=1;
}
void main()
{
timer_init();
P1=0Xaa;
while(1)
{
if(t==20)
{
t=0;
P1=~P1;
}
}
}

void exter0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}