P0端需接上拉电阻
上电复位之后P0--P3默认高电平
发光二级管需串联470欧电阻
延迟计算11.0592MHZ一机器周期为0.75纳秒,12MHZ为1纳秒
/*流水灯实验程序*/
#include <REGX52.H>
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
main()
{
unsigned char LEDIndex = 0;
bit LEDDirection = 0;
while(1)
{
if(LEDDirection)
P1 = ~(0x01<<LEDIndex);
else
P1 = ~(0x80>>LEDIndex);
if(LEDIndex==7)
LEDDirection = !LEDDirection;
LEDIndex = (LEDIndex+1)%8;
Delay1ms(500);
}
}