天天看點

基于proteus軟體仿真AT89C52的流水燈

proteus軟體仿真設定界面如下:

基于proteus軟體仿真AT89C52的流水燈

代碼如下:

#include <reg51.h>

void Delay1ms(unsigned int count)
{
	unsigned int i,j;
	for(i=0;i<count;i++)
	for(j=0;j<0;j++);
}

main()
{
	unsigned char LEDIndex = 0;
	bit LEDDirection = 1;

	while(1)
	{
		if(LEDDirection)
			P1 = ~(0x01<<LEDIndex);
		else
			P0 = ~(0x80>>LEDIndex);	
		if(LEDIndex==7)
			LEDDirection = !LEDDirection;
		LEDIndex = (LEDIndex+1)%8;
		Delay1ms(1000);
	}
}

           

用keil生成并導入即可;

效果圖:

基于proteus軟體仿真AT89C52的流水燈

繼續閱讀