iccavr编译putchar未定义时解决方案.docVIP

  • 90
  • 0
  • 约4.36千字
  • 约 7页
  • 2016-06-11 发布于重庆
  • 举报
iccavr编译putchar未定义时解决方案

我在用iccavr编译程序“hello.c的时候,出现!ERROR file hello.o: undefined symbol _putchar E:\INSTAL~1\ICCAVR~1\bin\imakew.exe: Error code 1 Done: there are error(s). Exit code: 1. Mon Nov 11 23:07:35 2013。 附上源程序如下: #include iom128v.h #include macros.h unsigned char const SEGtable[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80}; unsigned char rxtemp=0x00; void port_init(void) //端口初始化 { PORTA = 0xFF; DDRA = 0xFF; PORTB = 0x00; DDRB = 0x00; PORTC = 0xFF; DDRC = 0xFF; PORTD = 0xFF; DDRD = 0x00; PORTE = 0x00; DDRE = 0x00; PORTF = 0xFF; DDRF = 0x00; PORTG = 0x00; DDRG = 0x00; } void uart0_init(void) //UART0初始化,8数据位,1位起始位,1位停止位,比特率为9600bps { UCSR0B = 0x00; UCSR0A = 0x00; UCSR0C = 0x06; UBRR0L = 0x33; UBRR0H = 0x00; UCSR0B = 0xD8; } #pragma interrupt_handler uart0_rx_isr:19 //UART0接收数据中断服务子程序 void uart0_rx_isr(void) { rxtemp = UDR0; putchar(rxtemp); } #pragma interrupt_handler uart0_tx_isr:21 //UART0发送数据中断服务子程序 void uart0_tx_isr(void) { } void init_devices(void)//系统初始化函数 { CLI(); XDIV = 0x00; XMCRA = 0x00; port_init(); uart0_init(); MCUCR = 0x00; EICRA = 0x00; EICRB = 0x00; EIMSK = 0x00; TIMSK = 0x00; ETIMSK = 0x00; SEI(); } unsigned char Fun(unsigned char X) { unsigned Y,Sum; static unsigned Z = 1; Y = 0; Y = Y + 1; Z = Z + 1; Sum = Y + Z + X; return(Sum); } void main(void) { unsigned char temp,i; init_devices(); for(i=0;i=5;i++) { temp = Fun(2); putchar(temp); } } 在网上找教程,说是在程序前面加上#include”stdio.h”,但是还是错误。后面通过一天都研究,发现了一个解决办法。 打开icc avr 安装目录,找到“example.avr”文件,打开其中”putchar_m16.c”文件,文件如下: /* This putchar works with the M16 UART0. It will work with other devices * if their UART registers use the same names. If the UART IO locations * are different from the M16, then you will also have to change the * #include header file statement. * * For device with multiple UARTs and i

文档评论(0)

1亿VIP精品文档

相关文档