|
我之前编写的范例: (教程2).LGT编程、编译、烧录、仿真的第一个范例:流水灯,
熟悉AVR的人应该会狂喜: 下面的代码除了 #include <iolgt8f0xa.h> 这句头文件指向LGT外, 其它的所有语句,100%是与AVR相同的。
也就是说,AVR的代码,只需要修改一句头文件,就能立即应用于LGT上。
本文描述LGT的头文件及其使用方法。
LGT芯片LGT8F08A 的头文件 iolgt8f0xa.h, 只有88行。 有兴趣的网友可以细读。它的寄存器位置等与 ATmega164P 是完全一致。- #ifndef __iolgt8f0xa_h
- #define __iolgt8f0xa_h
- /* GUID */
- #define GUID3 (*(volatile unsigned char *)0xF6)
- #define GUID2 (*(volatile unsigned char *)0xF5)
- #define GUID1 (*(volatile unsigned char *)0xF4)
- #define GUID0 (*(volatile unsigned char *)0xF3)
- /* Power Management */
- #define PMCR (*(volatile unsigned char *)0xF2)
- #define RC16MEN 0
- #define RC1KEN 1
- #define OSCMEN 2
- #define CFDS 4
- #define EXTMSEL 5
- #define LFEN 6
- /* RTC */
- #define RTCNTH (*(volatile unsigned char *)0xD7)
- #define RTCNTM (*(volatile unsigned char *)0xD6)
- #define RTCNTL (*(volatile unsigned char *)0xD5)
- #define RTCTOPH (*(volatile unsigned char *)0xD4)
- #define RTCTOPM (*(volatile unsigned char *)0xD3)
- #define RTCTOPL (*(volatile unsigned char *)0xD2)
- #define RTCISR (*(volatile unsigned char *)0xD1)
- #define IEN 0
- #define IF 1
- #define WKUF 7
- #define RTCSR (*(volatile unsigned char *)0xD0)
- #define POWOFF 0
- #define EN 1
- #define CWEN 2
- #define PWEN 3
- #define LOAD 4
- #define WREN 7
- /* ADC */
- #define ADTM (*(volatile unsigned char *)0x7D)
- #define ADCTM2 2
- #define ADCTM1 1
- #define ADCTM0 0
- /* Oscillator Calibration Register */
- //#define OSCCAL (*(volatile unsigned char *)0x66)
- #define PRESETN 6
- #define OSCCAL5 5
- #define OSCCAL4 4
- #define OSCCAL3 3
- #define OSCCAL2 2
- #define OSCCAL1 1
- #define OSCCAL0 0
- /* MCU Control */
- //#define MCUCR (*(volatile unsigned char *)0x55)
- #define SWDD 7
- /* MCU Status */
- #define MCUCSR (*(volatile unsigned char *)0x54)
- #define SWRF 5
- #define OCDRF 4
- #define JTRF 4
- #define WDRF 3
- //#define EXTRF 1
- //#define PORF 0
- /* EEPROM */
- #define EEDRH (*(volatile unsigned char *)0x49)
- //#define EECR (*(volatile unsigned char *)0x3F)
- #define EEPEN 7
- /* GTCCR */
- //#define GTCCR (*(volatile unsigned char *)0x43)
- #define PSR10 0
- /* Interrupt Vector Numbers */
- #define iv_RTC 28 // for iccavr
- #define RTC_vect _VECTOR(27)
- #define SIG_RTC_READY _VECTOR(27)
- /* */
- #endif
复制代码
这里也提供该头文件的下载:
FOR WINAVR
1. iolgt8f0xa.h是库头文件io.h和iomxx4的补充, 它定义了LGT8F0XA所特有的寄存器和中断向量.
2. 在工程中同时包含头文件io.h和iolgt8f08xa.h就可包所有LGT8F08XA的寄存器和中断向量定义,
(iomxx4.h在io.h中根据MCU型号自动包含).
FOR ICCAVR
1. iolgt8f0xa.h是库头文件iom164v.h的补充, 它定义了LGT8F0XA所特有的寄存器和中断向量.
2. 在工程中同时包含头文件iom164v.h和iolgt8f08a.h就可包所有LGT8F08XA的寄存器和中断向量定义.
附录:GCC 里头文件的使用方法。
GCC里的前面两句话是:
#include <io.h> // GCC的标准io.h
#include <iolgt8f0xa.h> // LGT的头文件
当然,你需要先配置好GCC里的 include directories , 这个范例已经有详细描述 (教程2).LGT编程、编译、烧录、仿真的第一个范例:流水灯,
进入菜单 Project ---> Configuration Options
General 选项中,唯一需要芯片的是芯片选 ATmega164P, 这点非常重要,不要选错,因为这一款LGT芯片(LGT8F08A)的寄存器位置是与 ATMEGA164P 相同的。
检查一下(教程1)中描述的 Include Direcories 是否配置好
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|