新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > AVR单片机从左到右LED流水灯C语言程序

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

作者: 时间:2016-11-30 来源:网络 收藏
AVR单片机第一个实验,从左到右的LED流水灯C语言程序,编程环境是WinAVR,8MHZ晶振。

本文引用地址:https://www.eepw.com.cn/article/201611/323645.htm

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

#include

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);//调用库中的延时函数

}

}

}



关键词: AVR单片机LED流水

评论


技术专区

关闭