|
发表于 2013-2-2 13:48:13
|
显示全部楼层
10L:
The #pragma directive will prevent the compiler from generating a warning that the function was declared, but not used in the program.
加入 #pragma used+目的是防止编译器出现一个警告提示,说已经申明/定义了一个函数,但没有在本程序中使用。警告信息如下:unreferenced funcetin 'function_name'。其实你可以写个函数,但不要使用它,编译是就会出现上述警告信息。
13L:
CVAVR本身提供了一些函数,如putchar().该函数是采用轮询方式,从USART发送一个字符.
如果你想编写自己的,例如,采用中断方式从USART发送一个字符,但函数名仍然为putchar(),顶掉原系统的putchar()函数是,使用#pragma used+ .使用CVAVR自动生成USART函数时,就会出现这样的使用:
#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
{
tx_buffer[tx_wr_index]=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
++tx_counter;
}
else
UDR=c;
#asm("sei")
}
#pragma used-
#endif
此处的#pragma used+表示,使用#pragma used+/#pragma used-之间的代码,生成putchar()函数,代替原系统的putchar()函数.
如果你仍旧希望使用原系统的putchar()函数(调试阶段),那么就在最前面加上一句:
#defien _DEBUG_TERMINAL_IO_
学到了,谢谢~~~ |
|