基於proteus軟件仿真AT89C52的流水燈

proteus軟件仿真設置界面如下:
在這裏插入圖片描述
代碼如下:

#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生成並導入即可;
效果圖:

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章