⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1-8-1.c

📁 单片机中用c语言编写的实现不同点亮方式的流水灯程序
💻 C
字号:
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
void delay_10us(uint n)
{
	do{
	_nop_(); 
	_nop_();

	_nop_();

	_nop_();

	_nop_();

	} while(--n);

}

  void delay_ms(uint m)
  {
   do                                      
     delay_10us(131);
	 while(--m);

   }
main()
{
    uint LEDIndex = 0;
	bit LEDDirection = 1;

	while(1)
	{
		if(LEDDirection)
			P2 = ~(0x01<<LEDIndex);
		else
			P2 = ~(0x80>>LEDIndex);	
		if(LEDIndex==7)
			LEDDirection = !LEDDirection;
		LEDIndex = (LEDIndex+1)%8;				
		delay_ms(100);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -