51单片机简单的LED闪程序。想让P0^0口和P0^7口同时分别控制LED灯闪,怎么写

求大神
2024-11-09 09:31:20
推荐回答(1个)
回答1:

很简单呀,给你一个示范:
#include
#define uchar unsigned char
void delay(uchar a)
{
uchar i,j;
for(i=0;ifor(j=0;j<120;j++);
}
main()
{
uchar LED=0xfe;
while(1)
{
P0=LED;

delay(100);

P0=0xff;

delay(100);

LED=(LED<<1)|0x01;

if(LED==0xff)LED=0xfe;

}

}