复制
收藏
提问
简洁
//ICC-AVR application builder : 2012/2/13 20:52:33 /******************************************************************************* * 版权: 木仔科技 * * 单片机: ATMAGE128A-AU * 晶振: 外部8MHz * 编译器: ICC 7.22 * * 文件名: main.c * 作者: 木仔科技 * 版本: 1.0 * 完成日期: * 功能描述: 在8M晶振下,实现6路LED流水灯操作 *******************************************************************************/ #include <iom128v.h> #include <macros.h> #define LED PORTF #define BEEL_ON PORTB |= BIT(0); #define BEEL_OFF PORTB &= ~BIT(0); unsigned char i = 0; unsigned char tab[16] = {0XFB,0XF3,0XE3,0XC3,0X83,0X03,0X03,0X83,0XC3,0XE3,0XF3,0XFB,0X55,0XAA,0X55,0XAA}; /******************************************************************************* * 函数名称: delay_us() * 入口参数: microsecond : 输入延时微秒的时间 * 出口参数: * 功能描述: 微秒的延时 *******************************************************************************/ void delay_us(unsigned int microsecond) { do { microsecond--; } while (microsecond>1); } /******************************************************************************* * 函数名称: delay_ms() * 入口参数: millisecond : 输入延时毫秒的时间 * 出口参数: * 功能描述: 毫秒的延时 *******************************************************************************/ void delay_ms(unsigned int millisecond) { while (millisecond--) { delay_us(999); } } void port_init(void) { PORTA = 0x00; DDRA = 0x00; PORTB = 0x01; DDRB = 0x01; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0x00; DDRD = 0x00; PORTE = 0x00; DDRE = 0x00; PORTF = 0xFC; DDRF = 0xFC;//LED口 PF2~PF7 PORTG = 0x00; DDRG = 0x00; } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts XDIV = 0x00; //xtal divider XMCRA = 0x00; //external memory port_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EICRB = 0x00; //extended ext ints EIMSK = 0x00; TIMSK = 0x00; //timer interrupt sources ETIMSK = 0x00; //extended timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized } void main(void) { init_devices(); BEEL_ON; delay_ms(100); BEEL_OFF; while(1) { LED = 0X00; delay_ms(1000); LED = 0XFC; delay_ms(1000); for(i = 0; i < 16; i ++) { LED = tab[i]; delay_ms(200); } i = 0; } }
0秒前
全网
文档
学术
百科
知识库
回答简洁模式
深入研究一些
- 该代码是用于ATMEGA128A-AU单片机的ICCAVR编译器编写的流水灯程序。
程序概述
- 版权声明:木仔科技版权所有。
- 单片机型号:ATMAGE128A-AU。
- 晶振频率:外部8MHz。
- 编译器版本:ICC 7.22。
- 文件功能:实现6路LED流水灯操作。
程序详解
- 头文件包含:iom128v.h和macros.h,用于访问单片机的I/O寄存器和宏定义。
- 宏定义:LED定义为PORTF,BEEL_ON和BEEL_OFF分别用于控制蜂鸣器的开和关。
- 全局变量:i用于循环计数,tab数组存储流水灯的模式。
- 延时函数:delay_us和delay_ms分别实现微秒和毫秒级的延时。
- 端口初始化:port_init函数设置各端口的输入输出模式。
- 设备初始化:init_devices函数配置中断、时钟等设备。
- 主函数:main中初始化设备后,通过循环控制LED流水灯的显示效果。
代码实现
你觉得结果怎么样?