main.c

来自「一个关于AVR单片机的例程」· C语言 代码 · 共 46 行

C
46
字号
//ICC-AVR application builder : 2006-1-31 下午 01:03:41
// Target : M16
// Crystal: 7.3728Mhz

#include <iom16v.h>
#include <macros.h>
#include "delay.h" //调用头文件
void port_init(void)
{
PORTA = 0x03;
DDRA = 0x03;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}

void main(void)
{

init_devices();       //初始化

while(1)
{
PORTB = 0x02;     //1脚为高,0脚为低,0脚灯亮
delay_1s();     //延时1S
PORTB = 0x01;       //0脚为高,1脚为低,1脚灯亮
delay_1s();     //延时1S
}
}

⌨️ 快捷键说明

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