Header file有說明了,為什麼說我沒有定義呢?真的鬱悶!在GCC下compile可以,為何出現identifier is undefined error?
void USART_Init(void)
{
UCSR 0C =(1<<< span>; //非同步操作,8位元資料,無奇偶校驗位,一個停止位
UBRR 0L = (F_CPU / BAUDRATE / 16 - 1) % 256;//設置串列傳輸速率
UBRR0H = (F_CPU / BAUDRATE / 16 - 1) / 256;
UCSR0B = (1<<<< span); //使能接收中斷,使能接收,使能發送
}
Error[Pe020]: identifier "UCSZ01" is undefined F:\AVR\main.c 32
Error[Pe020]: identifier "UCSZ00" is undefined F:\AVR\main.c 32
Error[Pe020]: identifier "RXCIE0" is undefined F:\AVR\main.c 36
Error[Pe020]: identifier "RXEN0" is undefined F:\AVR\main.c 36
Error[Pe020]: identifier "TXEN0" is undefined F:\AVR\main.c 36
Error[Pe020]: identifier "UDRE0" is undefined F:\AVR\main.c 44
Error[Pe020]: identifier "RXC0" is undefined F:\AVR\main.c 52
原因:
右擊project,,打開options-->General Options-->System,
在Enable bit definitions in I/O-Include files 前打上個勾
【圖片】
問題2:porting procedure(從GCC到IAR快速移植)
- 增加檔
- header file處理
- //#include<avr/io.h>
#include <iom16.h>
//#include<avr/eeprom.h>
//#include<avr/interrupt.h>
//#include<avr/wdt.h> - 中斷方式的變化GCC中 ISR()
- IAR中:#pragma vector=TIMER2_OVF_vect
- __interrupt void timer0isr(void)
- {
- ......
- }
- 啟用一些編譯開關 : #define ENABLE_BIT_DEFINITIONS
- 庫函數快速適應,在GCC中存在相應庫函數
- void eeprom_read_block(uchar *data,uint addr,unsigned char length)
- void eeprom_write_block(unsigned char *data,uint addr,unsigned char length)到了IAR可以自己編寫一個,還用這樣的名稱:
- void eeWriteByte(unsigned int uiAddress, char ucData)
- {
- while(EECR & (1<< font)) // 等待上一次寫操作結束
- EEAR = uiAddress; // 設置位址和資料寄存器
- EEDR = ucData; //置位EEMWE
- EECR |= (1<< font) // 置位EEWE 以啟動寫操作
- EECR |= (1<< font)
- }
- unsigned char eeReadByte(unsigned int uiAddress)
- {
- while(EECR & (1<< font)) //等待上一次寫操作結束
- EEAR = uiAddress; //設置位址寄存器
- EECR |= (1<< font>) // 設置EERE 以啟動讀操作
- return EEDR; //自資料寄存器返回資料
- }
- void eeprom_write_block(unsigned char *data,uint addr,unsigned char length)
- {
- for(;length>0;length–)
- {
- eeWriteByte(addr,*data);
- addr++;data++;
- }
- }
- void eeprom_read_block(uchar *data,uint addr,unsigned char length)
- {
- for(;length>0;length–)
- {
- *data=eeReadByte(addr);
- addr++;data++;
- }
- }
- 一些語法的適應
- IAR中 volitale還和一般的不相容
- 不支援二進位0B…形式,可換成0x…形式
- 還不能之間從常數表格中寫,還得讀到RAM中
- 更換memory type,比如由tiny換成small模式 Error[Pe095]: array is too large E….h 78 等等
問題3:
__asm__ __volatile__ (" nop\n nop\n nop\n nop\n" ::);
-----> Error[Pe020]: identifier "__asm__" is undefined
原因: 改成 asm(" nop\n nop\n nop\n nop\n");
問題4:
sei( )-->Warning[Pe223]: function "sei" declared implicitly
原因:
#include
__asm__ __volatile__ (" nop\n nop\n nop\n nop\n" ::);
-----> Error[Pe020]: identifier "__asm__" is undefined
原因: 改成 asm(" nop\n nop\n nop\n nop\n");
問題4:
sei( )-->Warning[Pe223]: function "sei" declared implicitly
原因:
#include
#include
#define sei() _SEI() // enable interrupy
#define sei() _SEI() // enable interrupy
#define cli() _CLI() // disable interrupy
#define SEI() _SEI() // enable interrupy
#define CLI() _CLI() // disable interrupy
This file gives an overview of the C library functions implemented in the avr-libc standard library for the Atmel AVR microcontroller family.
As of the writing of this reference, the current version of avr-libc was 20010821.
avr-libc is maintained by Marek Michalkiewicz <marekm@linux.org.pl>.
This document is written by Enno Luebbers <luebbers@users.sourceforge.net>. I do not take any responsibility about what happens if you use the information in this reference. You are on your own. :) Formally that means:
This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Documentation for most of the functions that are not hardware specific to the AVR architecture (like I/O ports or interrupt handlers) can be found in the Linux manpages.
Thanks go to Jörg Wunsch for pointing me to several errors in previous versions of this reference and for including it in the FreeBSD Port of the avr-libc. Also thanks to Jochen Pernsteiner for his explanation of strlwr() and to Peter N Lewis for his help about SIGNAL() and INTERRUPT().
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
Be careful with the -mint8 option, though.
M_PI = 3.141592653589793238462643
Pi.
M_SQRT2 = 1.4142135623730950488016887
The square root of two.
Since it's a compatibility header file, I chose not to document it. Yet.
In a handler defined with SIGNAL(), additional interrupts are implicitly forbidden, whereas in an INTERRUPT() handler, the first (implicit) instruction is "sei", so that additional interrupts can occur.
Thanks to Jörg Wunsch for correcting me there.
typedef struct {
int quot;
int rem;
} div_t;
typedef struct {
long quot;
long rem;
} ldiv_t;
typedef int (*__compar_fn_t)(const void *, const void *);
Used for comparison functions, eg. qsort().
Additionally, the following functions/macros are declared:
The following functions are not yet implemented:
atexit(), atof(), calloc(), rand(), realloc(), srand();
enum {
STOP = 0,
CK = 1,
CK8 = 2,
CK64 = 3,
CK256 = 4,
CK1024 = 5,
T0_FALLING_EDGE = 6,
T0_RISING_EDGE = 7
};
And there are the following functions:
WinAVR libc function reference
As of the writing of this reference, the current version of avr-libc was 20010821.
avr-libc is maintained by Marek Michalkiewicz <marekm@linux.org.pl>.
This document is written by Enno Luebbers <luebbers@users.sourceforge.net>. I do not take any responsibility about what happens if you use the information in this reference. You are on your own. :) Formally that means:
This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Documentation for most of the functions that are not hardware specific to the AVR architecture (like I/O ports or interrupt handlers) can be found in the Linux manpages.
Thanks go to Jörg Wunsch for pointing me to several errors in previous versions of this reference and for including it in the FreeBSD Port of the avr-libc. Also thanks to Jochen Pernsteiner for his explanation of strlwr() and to Peter N Lewis for his help about SIGNAL() and INTERRUPT().
Function list by Header files
ctype.h | Character type test functions |
eeprom.h | EEPROM access functions |
errno.h | Error handling |
ina90.h | Compatibility header for IAR C |
interrupt.h | Interrupt handling routines |
inttypes.h | Defines for different int data types |
io-avr.h | Includes the correct ioXXX.h header |
io.h | Includes other I/O-Headers |
ioXXX.h | I/O-Defines for various AVR microcontrollers |
iomacros.h | Several macros for I/O access |
math.h | Various mathematical functions |
pgmspace.h | Compatibility header for IAR C |
progmem.h | Alias for pgmspace.h |
setjmp.h | Provides functions for long jumps |
sig-avr.h | AVR interrupt and signal handling |
signal.h | Alias for sig-avr.h. Should no longer be used. |
stdlib.h | Miscellaneous routines |
string-avr.h | String manipulation functions |
string.h | More string manipulation routines |
timer.h | Timer control functions |
twi.h | ATmega163 specific defines |
wdt.h | Watchdog Timer control functions |
Alphabetical function list
CTYPE.H
EEPROM.H
ERRNO.H
int errno; | Holds the system-wide error code. |
INA90.H
This header file contains some compatibility functions and macros to make porting applications from the IAR C compiler to avr-gcc easier. Since you wouldn't use it for writing new applications, there's no need for documentation here (lazy me).INTERRUPT.H
INTTYPES.H
Defines the following types:typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef int int16_t;
typedef unsigned int uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
Be careful with the -mint8 option, though.
IO-AVR.H
Automagically includes the ioXXX.h header file for the target AVR microcontroller.IO.H
Just includes both io-avr.h and iomacros.h.IOXXX.H
I/O-register definitions for the XXX MCU. Refer to the specific datasheet for a description of the registers and their functions.IOMACROS.H
MATH.H
Constants:M_PI = 3.141592653589793238462643
Pi.
M_SQRT2 = 1.4142135623730950488016887
The square root of two.
PGMSPACE.H
Another compatibility header file for the IAR C compiler. Contains (or is suposed to contain) things like memcpy_P, strcat_P, printf_P etc.Since it's a compatibility header file, I chose not to document it. Yet.
PROGMEM.H
Includes pgmspace.h.SETJMP.H
SIG-AVR.H
Defines symbols for the interrupt vectors that are stored at the begining of the flash memory. Defined are:SIGNAL( signame ); | Used for defining an Signal handler for the signal 'signame'. |
INTERRUPT( signame ); | Used for defining an Interrupt handler for the signal 'signame'. |
Thanks to Jörg Wunsch for correcting me there.
SIGNAL.H
Includes sig-avr.h. You should use sig-avr.h directly, because signal.h might disappear shortly because it conflicts with the "real" ANSI C signal.h.STDLIB.H
Defines the following types:typedef struct {
int quot;
int rem;
} div_t;
typedef struct {
long quot;
long rem;
} ldiv_t;
typedef int (*__compar_fn_t)(const void *, const void *);
Used for comparison functions, eg. qsort().
Additionally, the following functions/macros are declared:
void abort(); | Effectively aborts the execution by putting the MCU into an endless loop. |
long labs( long x ); | Returns the absolute value of x. |
void *bsearch(const void *key, const void *base, size_t nmemb, > size_t size, int (*compar)(const void *, const void *)); | Performs a binary search on a sorted array. |
div_t div( int x, int y ); | Divides x by y and returns the result (quotient and remainder) in a div_t struct (see above). |
ldiv_t ldiv( lomg x, long y ); | Divides x by y and returns the result (quotient and remainder) in a ldiv_t struct (see above). |
void qsort(void *base, size_t nmemb, size_t size, __compar_fn_t compar); | Sorts an array at 'base' with 'nmemb' elements of size 'size', using the comparison function 'compar'. |
long strtol(const char *nptr, char **endptr, int base); | Converts the string at 'nptr' to a long integer according to the base 'base'. |
unsigned long strtoul(const char *nptr, char **endptr, int base); | Converts the string at 'nptr' to an unsigned long integer according to the base 'base'. |
long atol( char *p ); | Converts the string 'p' to a long integer. |
long atoi( char *p ); | Converts the string 'p' to an integer. |
void *malloc( size_t size ); | Allocates 'size' bytes of memory and returns a pointer to it. Implemented, but not tested. |
void free( void *ptr ); | Releases the memory at 'ptr', which was previously allocated with malloc(). Implemented, but not tested. |
double strtod( char *, char ** ); | See math.h. |
char *itoa( int value, char *string, int radix ); | Converts an integer into a string. This is not ANSI C, but nonetheless (or maybe just because of this) very useful. |
atexit(), atof(), calloc(), rand(), realloc(), srand();
STRING-AVR.H
STRING.H
extern void *memccpy(void *dest, const void *src, int c, size_t n); | Copy at most 'n bytes from 'src' to 'dest' until character 'c' is found. |
extern void *memchr(const void *, int, size_t); | See string-avr.h. |
extern int memcmp(const void *, const void *, size_t); | See string-avr.h. |
extern void *memcpy(void *, const void *, size_t); | See string-avr.h. |
extern void *memmove(void *dest, const void *src, size_t n); | See string-avr.h. |
extern void *memset(void *, int, size_t); | See string-avr.h. |
extern char *strcat(char *, const char *); | See string-avr.h. |
extern char *strchr(const char *, int); | See string-avr.h. |
extern int strcmp(const char *, const char *); | See string-avr.h. |
extern char *strcpy(char *, const char *); | See string-avr.h. |
extern int strcasecmp(const char *s1, const char *s2); | Compare 's1' and 's2', ignoring case. |
extern size_t strlen(const char *); | See string-avr.h. |
extern char *strlwr(char *s); | Converts all upper case characters in 's' to lower case. |
extern char *strncat(char *, const char *, size_t); | See string-avr.h. |
extern int strncmp(const char *, const char *, size_t); | See string-avr.h. |
extern char *strncpy(char *, const char *, size_t); | See string-avr.h. |
extern int strncasecmp(const char *, const char *, size_t); | Compare 'n' bytes of 's1' and 's2', ignoring case. |
extern size_t strnlen(const char *, size_t); | See string-avr.h. |
extern char *strrchr(const char *, int); | See string-avr.h. |
extern char *strrev(char *s1); | Probably reverses 's1'. |
extern char *strstr(const char *haystack, const char *needle); | Locate 'needle' in 'haystack', and return a pointer to it. |
extern char *strupr(char *s); | Converts all lower case characters in 's' to upper case. |
TIMER.H
Defines an enumeration for the Timer Control Register:enum {
STOP = 0,
CK = 1,
CK8 = 2,
CK64 = 3,
CK256 = 4,
CK1024 = 5,
T0_FALLING_EDGE = 6,
T0_RISING_EDGE = 7
};
And there are the following functions:
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。