【发布时间】:2017-08-16 23:04:40
【问题描述】:
我在 Atmel Studio 上编写 AVR 代码时,我忘记在 main 中写入 IO 端口设置(DDRx、PORTx、...等),而是将其放在 main 之外,如下所示:
#include <avr/io.h>
#define F_CPU 1000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
void delay_250ms();
uint8_t t_hr = 0 , t_min = 0 , t_sec = 0 , i = 0 , tempp;
uint8_t start_stopwatch = 0;
DDRA |= 0xFF;
PORTA = 0x00;
DDRD = 0x00;
PORTD |= 0xFF;
然后我得到了那个错误:
- 预计
)在(令牌之前- 预期标识符或
(在volatile之前- 在
(令牌之前应为)- 预期标识符或
(在volatile之前- 预计
)在(令牌之前 …
当我将它们添加回主函数时,没有错误
问题是为什么我不能将它们添加到 main 之外? 我错过了什么吗?
【问题讨论】:
-
将相关代码放入您的问题中(复制粘贴,然后选择它并单击
{}图标,使其格式正确)。
标签: c compiler-errors microcontroller avr atmelstudio