专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

AVR单片机从左到右LED流水灯C语言程序

作者:佚名   来源:本站原创   点击数:  更新时间:2013年04月14日   【字体:

AVR单片机第一个实验,从左到右的LED流水灯C语言程序,编程环境是WinAVR,8MHZ晶振。

 

#include <avr/io.h>//相关库

#include <util/delay.h>

typedef unsigned int uint;

typedef unsigned char uchar;

uchar const tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

void main(void)//主函数

{

   PORTB=0xff;//PB口输出为高电平

   DDRB=0xff;//高PB口为输出

   uchar a;//定义变量

   while(1)//无限循环

   {

       for(a=0;a<8;a++)

       {

           PORTB=tab[a];//流水灯十六进制数组

           _delay_ms(500);//调用库中的延时函数

       }

   }

}

关闭窗口

相关文章