该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
void port_init(void)
{
PORTA = 0x03; // 设置PA0和PA1为高
DDRA = 0x03; //设置PA0和PA1为输出
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 Delay(void)
{
unsigned char i,j;
for(i=200;i>0;i--)
{
for(j=200;j>0;j--)
;
}
}
void main(void)
{
init_devices(); //初始化
while(1)
{
PORTA = 0x02; //1脚为高,0脚为低,0脚灯亮
Delay(); //延时
PORTA = 0x01; //0脚为高,1脚为低,1脚灯亮
Delay(); //延时
}
}