刚开始学51
单片机,买了个
开发板,做LED实验,开发板的8个LED接的STC89C52RC的P2口@P2^0-P2^7分别对应1-8个LED)
想实现的效果是1-4个LED和5-8个LED两两交替闪烁,但是下载到单片机后的结果却是5-8四个LED可以实现LED4,LED6和LED5,LED7交替闪烁,但是LED0,LED2常亮,LED1和LED3一起快速闪一下后灭,然后又快速闪一下灭如此闪烁,删除下列程序中的if(b ==2)和if(b ==4)中的对应的任意一个函数,都能实现两两交替闪烁,求解!函数如下:
#include<reg52.h>
typedef unsigned char uint8;
uint8 a,b;
sbit LED0 = P2^0;
sbit LED1 = P2^1;
sbit LED2 = P2^2;
sbit LED3 = P2^3;
sbit LED4 = P2^4;
sbit LED5 = P2^5;
sbit LED6 = P2^6;
sbit LED7 = P2^7;
main()
{
TMOD = 0x01;
TF0 = 0;
TH0 = 0xb8;
TL0 = 0x00;
TR0 = 1;
P2 = 0xaa;
a = 0; b = 0;
while(1)
{
if(TF0 == 1)
{
TF0 = 0;
TH0 = 0xb8;
TL0 = 0x00;
a++;
}
if(a == 10)
{
a = 0;
b++;
}
if(b == 2)
{
LED4 = ~LED4;
LED5 = ~LED5;
LED6 = ~LED6;
LED7 = ~LED7;
}
if(b == 4)
{
b = 0;
LED0 = ~LED0;
LED1 = ~LED1;
LED2 = ~LED2;
LED3 = ~LED3;
}
}
}
请明示!!!
一周热门 更多>