极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14851|回复: 1

LGT8P663A OTP 初體驗

[复制链接]
发表于 2019-1-24 18:00:14 | 显示全部楼层 |阅读模式
LGT8P663A 1k OTP SOP8L 是類PIC 的 MIC8S內核,有 RA0~RA5 共6個 I/O,開發時以類PIC12F609作基礎。

步驟:(參考廠商 "LGT8F690A开发指南.pdf")
1) 建議用廠商的SDKBuilder產生根據設備,產出所需基礎代碼,再用較舊的MPLAB IDE v8.92,配合 HI-TECH PICC v9.83作具體完整的編程。

2) 在MPLAB建立工程時,重點包括:
    a) 芯片要選PIC12F609
    b) [Active Toolsuite]下要選[HI-TECH Universal ToolSuite]  
    c) 把頭文件 lgt8p663a.h 放到項目內
    d) 把轉碼工具 XIC2MIC 集成到MPLAB IDE,做法如下:
        i) 在根錄建立檔案夾並把放置,c:\mic8s\xic2mic
       ii) 在項目欄頂的帶 .MCP 名上按鼠標右鍵,在彈出的選單用選 [Build Options…]
      iii) 選 Custom Build 頁內的 Post-Build Step,並在命令行的框內填上:
           c:\mic8s\xic2mic --mh --ma -cm LGT8P663A -f $(TargetDir)u2spi.hex
           注意當中最後的u2spi.hex是原MPLAB IDE產生的hex檔名,不同項目是不同的。
      iv) 最終xic2mic會在MPLAB IDE的output窗內顯示進度和成功的訊息,並產生的 u2spi_mic.hex檔。

3) 使用LGTMix ISP程序配合小白盒,小白盒的VDD、GND、VPP、SWC、SWD要跟LGT8P663A接好,再選 u2spi_mic.hex 檔案進行燒錄。

以下是廠商提供的一個軟件19200串口和 SPI的編程範例 lgt8fp663a_u2spi

u2spi.c
  1. //----------------------------------------------------
  2. // LGT8F684A test cases
  3. // Case name : software SCI
  4. //         decription:
  5. //                UART/TX out of from RA5
  6. //                UART settings:
  7. //                        19200bps/8bit data/1bit stop/no parity
  8. // Conditions:
  9. //                 +----------+
  10. //        VCC =+                        += GND
  11. //        TXD =+                        += MOSI
  12. //        nCS =+                        += MISO
  13. //        LED =+                        += SPCK
  14. //                 +----------+
  15. //----------------------------------------------------

  16. #include "lgt8p663a.h"
  17. #include "usi.h"

  18. // important CFW configuration

  19. // funciton definition
  20. void sys_init(void);
  21. void io_init(void);
  22. void tmr0_init(void);

  23. u8 t0cnt = 0;

  24. // hardware interrupt service
  25. void interrupt hisr(void)
  26. {
  27.         // timer overflow
  28.         if(T0IE && T0IF)
  29.         {
  30.                 T0IF = 0;                               
  31.                 if(++t0cnt == 20) {
  32.                         RA3 = ~RA3;
  33.                         t0cnt = 0;
  34.                 }
  35.         }
  36. }

  37. int main(void)
  38. {
  39.         u8 tmp;
  40.        
  41.         CWOK = 1;
  42.         NOP();
  43.         NOP();

  44.         sys_init();
  45.        
  46.         while(1)
  47.         {
  48.                 spi_putc(0x5a);
  49.                
  50.                 uart_putc(0x55);
  51.                 uart_putc(0xaa);
  52.                
  53.                 tmp = spi_getc();
  54.                 uart_putc(tmp);
  55.                
  56.                 __delay_ms(100);               
  57.         }
  58. }

  59. void sys_init(void)
  60. {
  61.         // disable system clock divider
  62.         // uart/spi interface setup
  63.         usi_init();

  64.         // i/o setup
  65.         io_init();

  66.         // timer0 setup
  67.         tmr0_init();

  68.         // global interrupt enable
  69.         GIE = 1;
  70. }

  71. void io_init(void)
  72. {
  73.         // enable all of RA for digital function
  74.         ANSEL = 0;

  75.         // enable pullup of RA3
  76.         WPUA = 0b00001000;
  77.        
  78.         // enable RA global pullup
  79.         nGPPU = 0;
  80.        
  81.         // RA3 to toggle
  82.         TRISA3 = 0;
  83.        
  84.         // enable RA level change interrupt
  85.         //GPIE = 1;
  86. }

  87. void tmr0_init(void)
  88. {
  89.         // T0CS = 0 : clock by internal osc
  90.         // T0SE = not care
  91.         // PSA = 0 : prescaler for timer0
  92.         // PS = 0 : prescaler 1:256
  93.         OPTION_REG |= 0x7;

  94.         // set timer0 period to 50us
  95.         // 8MHz/256 = 32us       
  96.         // period = 32us * 200 = 16ms
  97.         // PR0H = 1
  98.         T0CON = (T0CON & 0xfc) | 0x1;
  99.         PR0L = 0xD4;

  100.         // enable timer 0 interrupt
  101.         T0IE = 1;
  102. }
复制代码


usi.c
  1. //-----------------------------------------
  2. // software uart sender
  3. //         bdr: 19200
  4. //        data: 8bits
  5. //        start: 1bit
  6. //        stop: 1bit
  7. //        parity: none
  8. //-----------------------------------------

  9. #include "lgt8p663a.h"
  10. #include "usi.h"

  11. void usi_init()
  12. {
  13.         // uart TXD output
  14.         TXD = 1;
  15.         TXDD = 0;
  16.        
  17.         // spi
  18.         SPI_CS = 1;
  19.         SPI_MO = 0;
  20.         SPI_CK = 0;
  21.        
  22.         SPI_CS_DR = 0;
  23.         SPI_CK_DR = 0;
  24.         SPI_MO_DR = 0;
  25. }

  26. void uart_putc(u8 c)
  27. {
  28.         u8 i;
  29.                        
  30.         // send start bit
  31.         TXD = 0;
  32.         __delay_us(39);

  33.         // send 8bits data
  34.         for(i = 0; i < 8; i++) {
  35.                 TXD = c & 1;
  36.                 c = c >> 1;
  37.                 __delay_us(39);
  38.         }

  39.         // send stop bit
  40.         TXD = 1;
  41.         __delay_us(39);
  42.         __delay_us(39);
  43. }

  44. void uart_puts(char *p)
  45. {
  46.         u8 *ptmp = (u8 *)p;
  47.          
  48.         while(*ptmp != '\0')
  49.                 uart_putc((u8)*ptmp++);
  50. }

  51. u8 spi_transfer(u8 data)
  52. {
  53.         u8 i, rev;
  54.        
  55.         SPI_CK = 0;
  56.         rev = 0;
  57.        
  58.         for(i = 0; i < 8; i++) {
  59.                 if(data & 0x80) SPI_MO = 1;
  60.                 else SPI_MO = 0;
  61.                 rev <<= 1;
  62.                
  63.                 SPI_CK = 1;        // posedge
  64.                  
  65.                 if(SPI_MI) rev |= 1;               
  66.                 data <<= 1;
  67.                
  68.                 SPI_CK = 0; // negedge
  69.         }

  70.         return rev;       
  71. }
复制代码


usi.h
  1. #ifndef __UART_H__
  2. #define __UART_H__

  3. // using RC(n) for uart txd line
  4. #define        TXD RA5
  5. // direction control for TXD
  6. #define TXDD TRISA5

  7. #define SPI_CS                 RA4
  8. #define SPI_CS_DR         TRISA4

  9. #define SPI_CK                 RA2
  10. #define SPI_CK_DR        TRISA2

  11. #define SPI_MI RA1
  12. #define SPI_MI_DR        TRISA1

  13. #define SPI_MO                 RA0
  14. #define SPI_MO_DR         TRISA0

  15. // system clock for 8M1T
  16. #ifndef _XTAL_FREQ
  17. #define _XTAL_FREQ 32000000
  18. #endif

  19. // external interface
  20. void usi_init();

  21. void uart_putc(u8);
  22. void uart_puts(char*);

  23. u8 spi_transfer(u8);
  24. #define spi_putc(value) spi_transfer(value)
  25. #define spi_getc()        spi_transfer(0xff)

  26. #endif
复制代码


lgt8663a.h
  1. #ifndef __LGT8P663A_H__
  2. #define __LGT8P663A_H__

  3. #ifndef _HTC_H_
  4. #include <htc.h>
  5. #endif

  6. #ifndef INPUT
  7. #define        INPUT        1
  8. #endif

  9. #ifndef OUTPUT
  10. #define        OUTPUT        0
  11. #endif

  12. #ifndef ANALOG
  13. #define        ANALOG 1
  14. #endif

  15. #ifndef DIGTIAL
  16. #define DIGTIAL 0
  17. #endif

  18. // WKPF bit of STATUS[7]
  19. volatile bit WKPF                @((unsigned)&STATUS*8)+7;
  20. volatile bit GPA1                @((unsigned)&STATUS*8)+6;
  21. volatile bit GPA0                @((unsigned)&STATUS*8)+5;

  22. // PORTA bit 6/7
  23. volatile unsigned char         PORT                @ 0x005;
  24. volatile unsigned char         L_PORTA                @ 0x005;
  25. volatile bit RA6                @((unsigned)&PORTA*8)+6;
  26. volatile bit RA7                @((unsigned)&PORTA*8)+7;
  27. #ifndef _LIB_BUILD
  28. volatile union {
  29.         struct {
  30.                 unsigned        RA0        : 1;
  31.                 unsigned        RA1        : 1;
  32.                 unsigned        RA2        : 1;
  33.                 unsigned         RA3 : 1;
  34.                 unsigned        RA4        : 1;
  35.                 unsigned         RA5        : 1;
  36.                 unsigned        RA6        : 1;
  37.                 unsigned        RA7        : 1;
  38.         };
  39. } L_PORTAbits @ 0x005;
  40. volatile union {
  41.         struct {
  42.                 unsigned        RA0        : 1;
  43.                 unsigned        RA1        : 1;
  44.                 unsigned        RA2        : 1;
  45.                 unsigned         RA3 : 1;
  46.                 unsigned        RA4        : 1;
  47.                 unsigned         RA5        : 1;
  48.                 unsigned        RA6        : 1;
  49.                 unsigned        RA7        : 1;
  50.         };
  51. } L_PORTbits @ 0x005;
  52. #endif

  53. // INTCON
  54. volatile bit INTIF                @((unsigned)&INTCON*8)+1;
  55. volatile bit INTIE                @((unsigned)&INTCON*8)+4;

  56. // PIR1.CGIF bit instead of EEIF
  57. volatile bit CMIF                @((unsigned)&PIR1*8)+3;
  58. volatile bit ECPIF                @((unsigned)&PIR1*8)+5;
  59. volatile bit TWIF                @((unsigned)&PIR1*8)+7;

  60. // T1CON.T1SYNC bits
  61. volatile bit T1SYNC                @((unsigned)&T1CON*8)+2;
  62. volatile bit nT1SYNC        @((unsigned)&T1CON*8)+2;
  63. volatile bit T1GNV                @((unsigned)&T1CON*8)+7;

  64. // DC0AL
  65. volatile unsigned char         DC0AL                @ 0x011;

  66. // DC0BL
  67. volatile unsigned char         DC0BL                @ 0x012;

  68. // DC1AL
  69. volatile unsigned char         DC1AL                @ 0x013;

  70. // DC1AH
  71. volatile unsigned char         DC1AH                @ 0x014;

  72. // ECP0CON : 0x015
  73. volatile unsigned char         ECP0CON                @ 0x015;
  74. volatile bit P0BPOL                @((unsigned)&ECP0CON*8)+0;
  75. volatile bit P0APOL                @((unsigned)&ECP0CON*8)+1;
  76. volatile bit DC0BH0                @((unsigned)&ECP0CON*8)+2;
  77. volatile bit DC0BH1                @((unsigned)&ECP0CON*8)+3;
  78. volatile bit DC0AH0                @((unsigned)&ECP0CON*8)+4;
  79. volatile bit DC0AH1                @((unsigned)&ECP0CON*8)+5;
  80. volatile bit P0BOEN                @((unsigned)&ECP0CON*8)+6;
  81. volatile bit P0AOEN                @((unsigned)&ECP0CON*8)+7;
  82. #ifndef _LIB_BUILD
  83. volatile union {
  84.         struct {
  85.                 unsigned        P0BPOL        : 1;
  86.                 unsigned        P0APOL        : 1;
  87.                 unsigned        DC0BH        : 2;
  88.                 unsigned         DC0AH        : 2;
  89.                 unsigned        P0BOEN        : 1;
  90.                 unsigned        P0AOEN        : 1;               
  91.         };
  92. } ECP0CONbits @ 0x015;
  93. #endif

  94. // PWM0CON : 0x016
  95. volatile unsigned char         PWM0CON                @ 0x016;
  96. volatile bit PWM0BDB0        @((unsigned)&PWM0CON*8)+0;
  97. volatile bit PWM0BDB1        @((unsigned)&PWM0CON*8)+1;
  98. volatile bit PWM0BDB2        @((unsigned)&PWM0CON*8)+2;
  99. volatile bit PWM0BDB3        @((unsigned)&PWM0CON*8)+3;
  100. volatile bit PWM0ADB0        @((unsigned)&PWM0CON*8)+4;
  101. volatile bit PWM0ADB1        @((unsigned)&PWM0CON*8)+5;
  102. volatile bit PWM0ADB2        @((unsigned)&PWM0CON*8)+6;
  103. volatile bit PWM0M                @((unsigned)&PWM0CON*8)+7;
  104. #ifndef _LIB_BUILD
  105. volatile union {
  106.         struct {
  107.                 unsigned        PWM0BDB        : 4;
  108.                 unsigned        PWM0ADB        : 3;
  109.                 unsigned        PWM0M        : 1;               
  110.         };
  111. } PWM0CONbits @ 0x016;
  112. #endif

  113. // ECP0AS : 0x017
  114. volatile unsigned char         ECP0AS                @ 0x017;
  115. volatile bit PSS0B0                @((unsigned)&ECP0AS*8)+0;
  116. volatile bit PSS0B1                @((unsigned)&ECP0AS*8)+1;
  117. volatile bit PSS0A0                @((unsigned)&ECP0AS*8)+2;
  118. volatile bit PSS0A1                @((unsigned)&ECP0AS*8)+3;
  119. volatile bit INTS0E                @((unsigned)&ECP0AS*8)+4;
  120. volatile bit CMPS0E                @((unsigned)&ECP0AS*8)+5;
  121. volatile bit PSR0EN                @((unsigned)&ECP0AS*8)+6;
  122. volatile bit ECP0ASE        @((unsigned)&ECP0AS*8)+7;
  123. #ifndef _LIB_BUILD
  124. volatile union {
  125.         struct {
  126.                 unsigned        PSS0B        : 2;
  127.                 unsigned        PSS0A        : 2;
  128.                 unsigned        INTS0E        : 1;
  129.                 unsigned         CMPS0E        : 1;
  130.                 unsigned        PSR0EN        : 1;
  131.                 unsigned        ECP0ASE        : 1;               
  132.         };
  133. } ECP0ASbits @ 0x017;
  134. #endif

  135. // PWM1CON : 0x018
  136. volatile unsigned char         PWM1CON                @ 0x018;
  137. volatile bit PWM1BDB0        @((unsigned)&PWM1CON*8)+0;
  138. volatile bit PWM1BDB1        @((unsigned)&PWM1CON*8)+1;
  139. volatile bit PWM1BDB2        @((unsigned)&PWM1CON*8)+2;
  140. volatile bit PWM1BDB3        @((unsigned)&PWM1CON*8)+3;
  141. volatile bit PWM1ADB0        @((unsigned)&PWM1CON*8)+4;
  142. volatile bit PWM1ADB1        @((unsigned)&PWM1CON*8)+5;
  143. volatile bit PWM1ADB2        @((unsigned)&PWM1CON*8)+6;
  144. volatile bit PWM1M                @((unsigned)&PWM1CON*8)+7;
  145. #ifndef _LIB_BUILD
  146. volatile union {
  147.         struct {
  148.                 unsigned        PWM1BDB        : 4;
  149.                 unsigned        PWM1ADB        : 3;
  150.                 unsigned        PWM1M        : 1;               
  151.         };
  152. } PWM1CONbits @ 0x018;
  153. #endif

  154. // VRCON
  155. volatile unsigned char         L_VRCON                @ 0x019;
  156. volatile bit VR0                @ ((unsigned)&VRCON*8)+0;
  157. volatile bit VR1                @ ((unsigned)&VRCON*8)+1;
  158. volatile bit VR2                @ ((unsigned)&VRCON*8)+2;
  159. volatile bit VR3                @ ((unsigned)&VRCON*8)+3;
  160. #ifndef _LIB_BUILD
  161. volatile union {
  162.     struct {
  163.         unsigned        VR0                        : 1;
  164.         unsigned        VR1                        : 1;
  165.         unsigned        VR2                        : 1;
  166.         unsigned        VR3                        : 1;
  167.         unsigned        FVREN                : 1;
  168.         unsigned        VRR                        : 1;
  169.                 unsigned                                : 1;
  170.         unsigned        CMVREN                : 1;
  171.     };
  172.         struct {
  173.                 unsigned        VR                : 4;
  174.         };
  175. } L_VRCONbits @ 0x019;
  176. #endif

  177. // CMCON0 : 0x1A
  178. volatile bit CMCH0                @((unsigned)&CMCON0*8)+0;
  179. volatile bit CMCH1                @((unsigned)&CMCON0*8)+1;

  180. // ECP1CON : 0x01B
  181. volatile unsigned char         ECP1CON                @ 0x01B;
  182. volatile bit P1BPOL                @((unsigned)&ECP1CON*8)+0;
  183. volatile bit P1APOL                @((unsigned)&ECP1CON*8)+1;
  184. volatile bit BUF1BE                @((unsigned)&ECP1CON*8)+2;
  185. volatile bit BUF1AE                @((unsigned)&ECP1CON*8)+3;
  186. volatile bit CAPM                @((unsigned)&ECP1CON*8)+4;
  187. volatile bit CAPEN                @((unsigned)&ECP1CON*8)+5;
  188. volatile bit P1BOEN                @((unsigned)&ECP1CON*8)+6;
  189. volatile bit P1AOEN                @((unsigned)&ECP1CON*8)+7;
  190. #ifndef _LIB_BUILD
  191. volatile union {
  192.         struct {
  193.                 unsigned        P1BPOL        : 1;
  194.                 unsigned        P1APOL        : 1;
  195.                 unsigned        BUF1BE        : 1;
  196.                 unsigned         BUF1AE        : 1;
  197.                 unsigned        CAPM        : 1;
  198.                 unsigned        CAPEN        : 1;
  199.                 unsigned        P1BOEN        : 1;
  200.                 unsigned        P1AOEN        : 1;               
  201.         };
  202. } ECP1CONbits @ 0x01B;
  203. #endif

  204. // CMCON1 : 0x1C
  205. volatile bit CFEN0                @((unsigned)&CMCON1*8)+5;
  206. volatile bit CFEN1                @((unsigned)&CMCON1*8)+6;
  207. #ifndef _LIB_BUILD
  208. volatile union {
  209.         struct {
  210.                 unsigned                        : 5;
  211.                 unsigned        CFEN        : 2;
  212.         };
  213. } L_CMCON1bits @ 0x01C;
  214. #endif

  215. // ECP1AS : 0x01D
  216. volatile unsigned char         ECP1AS                @ 0x01D;
  217. volatile bit PSS1B0                @((unsigned)&ECP1AS*8)+0;
  218. volatile bit PSS1B1                @((unsigned)&ECP1AS*8)+1;
  219. volatile bit PSS1A0                @((unsigned)&ECP1AS*8)+2;
  220. volatile bit PSS1A1                @((unsigned)&ECP1AS*8)+3;
  221. volatile bit INTS1E                @((unsigned)&ECP1AS*8)+4;
  222. volatile bit CMPS1E                @((unsigned)&ECP1AS*8)+5;
  223. volatile bit PSR1EN                @((unsigned)&ECP1AS*8)+6;
  224. volatile bit ECP1ASE        @((unsigned)&ECP1AS*8)+7;
  225. #ifndef _LIB_BUILD
  226. volatile union {
  227.         struct {
  228.                 unsigned        PSS1B        : 2;
  229.                 unsigned        PSS1A        : 2;
  230.                 unsigned        INTS1E        : 1;
  231.                 unsigned         CMPS1E        : 1;
  232.                 unsigned        PSR1EN        : 1;
  233.                 unsigned        ECP1ASE        : 1;               
  234.         };
  235. } ECP1ASbits @ 0x01D;
  236. #endif

  237. // TRISA : 0x85
  238. volatile bit TRIS0                @((unsigned)&TRISA*8)+0;
  239. volatile bit TRIS1                @((unsigned)&TRISA*8)+1;
  240. volatile bit TRIS2                @((unsigned)&TRISA*8)+2;
  241. volatile bit TRIS3                @((unsigned)&TRISA*8)+3;
  242. volatile bit TRIS4                @((unsigned)&TRISA*8)+4;
  243. volatile bit TRIS5                @((unsigned)&TRISA*8)+5;
  244. volatile bit TRIS6                @((unsigned)&TRISA*8)+6;
  245. volatile bit TRIS7                @((unsigned)&TRISA*8)+7;
  246. volatile bit TRISA6                @((unsigned)&TRISA*8)+6;
  247. volatile bit TRISA7                @((unsigned)&TRISA*8)+7;
  248. volatile bit RA0_DIR        @((unsigned)&TRISA*8)+0;
  249. volatile bit RA1_DIR        @((unsigned)&TRISA*8)+1;
  250. volatile bit RA2_DIR        @((unsigned)&TRISA*8)+2;
  251. volatile bit RA3_DIR        @((unsigned)&TRISA*8)+3;
  252. volatile bit RA4_DIR        @((unsigned)&TRISA*8)+4;
  253. volatile bit RA5_DIR        @((unsigned)&TRISA*8)+5;
  254. volatile bit RA6_DIR        @((unsigned)&TRISA*8)+6;
  255. volatile bit RA7_DIR        @((unsigned)&TRISA*8)+7;

  256. // PR1L : 0x88
  257. volatile unsigned char         PR1L                @ 0x088;

  258. // PR1H : 0x89
  259. volatile unsigned char         PR1H                @ 0x089;

  260. // PCHBUF : 0x8A
  261. volatile unsigned char         PCHBUF                @ 0x08A;

  262. // PIE1
  263. volatile bit TWIE                @((unsigned)&PIE1*8)+7;
  264. volatile bit ECPIE                @((unsigned)&PIE1*8)+5;

  265. // TWDR : 0x8D
  266. volatile unsigned char         TWDR                @ 0x08D;

  267. // PCON : 0x8E
  268. volatile bit LVR                @((unsigned)&PCON*8)+0;
  269. volatile bit POR                @((unsigned)&PCON*8)+1;
  270. volatile bit SWDD                @((unsigned)&PCON*8)+2;
  271. volatile bit DPSM0                @((unsigned)&PCON*8)+3;
  272. volatile bit DPSM1                @((unsigned)&PCON*8)+4;
  273. volatile bit LVRE                @((unsigned)&PCON*8)+5;
  274. volatile bit CWOK                @((unsigned)&PCON*8)+6;
  275. volatile bit WDTE                @((unsigned)&PCON*8)+7;
  276. #ifndef _LIB_BUILD
  277. volatile union {
  278.         struct {
  279.                 unsigned                        : 3;
  280.                 unsigned        DPSM        : 2;
  281.         };
  282.         struct {
  283.                 unsigned        : 3;
  284.                 unsigned        DPSM : 2;
  285.         };
  286. } L_PCONbits @ 0x08E;
  287. #endif

  288. // OSCTUNE : 0x90
  289. volatile bit TUN5                @ ((unsigned)&OSCTUNE*8)+5;
  290. volatile bit TUN6                @ ((unsigned)&OSCTUNE*8)+6;
  291. volatile bit TUN7                @ ((unsigned)&OSCTUNE*8)+7;
  292. #ifndef _LIB_BUILD
  293. volatile union {
  294.     struct {
  295.         unsigned        TUN                 : 8;
  296.     };
  297.     struct {
  298.         unsigned        TUN0                : 1;
  299.         unsigned        TUN1                : 1;
  300.         unsigned        TUN2                : 1;
  301.         unsigned        TUN3                : 1;
  302.         unsigned        TUN4                : 1;
  303.         unsigned        TUN5                : 1;
  304.         unsigned        TUN6                : 1;
  305.         unsigned        TUN7                : 1;
  306.     };
  307. } L_OSCTUNEbits @ 0x090;
  308. #endif

  309. // T0CON : 0x91
  310. volatile unsigned char         T0CON                @ 0x091;
  311. volatile bit PR0H0                        @ ((unsigned)&T0CON*8)+0;
  312. volatile bit PR0H1                        @ ((unsigned)&T0CON*8)+1;
  313. volatile bit T0H0           @ ((unsigned)&T0CON*8)+4;
  314. volatile bit T0H1           @ ((unsigned)&T0CON*8)+5;
  315. volatile bit T0D                   @ ((unsigned)&T0CON*8)+7;
  316. #ifndef _LIB_BUILD
  317. volatile union {
  318.     struct {
  319.         unsigned        PR0H        : 2;
  320.                 unsigned                        : 2;
  321.         unsigned        T0H                : 2;
  322.                 unsigned                        : 1;
  323.         unsigned        T0D                : 1;
  324.     };
  325. } T0CONbits @ 0x091;
  326. #endif

  327. // PR0L : 0x92
  328. volatile unsigned char         PR0L                @ 0x092;

  329. // DC1BL : 0x93
  330. volatile unsigned char         DC1BL                @ 0x093;

  331. // DC1BH : 0x94
  332. volatile unsigned char         DC1BH                @ 0x094;

  333. // ANSEL redefine
  334. volatile bit RA0_ANS                @ ((unsigned)&ANSEL*8)+0;
  335. volatile bit RA1_ANS                @ ((unsigned)&ANSEL*8)+1;
  336. volatile bit RA2_ANS                @ ((unsigned)&ANSEL*8)+2;
  337. volatile bit RA4_ANS                @ ((unsigned)&ANSEL*8)+3;
  338. volatile bit RC0_ANS                @ ((unsigned)&ANSEL*8)+4;
  339. volatile bit RC1_ANS                @ ((unsigned)&ANSEL*8)+5;
  340. volatile bit RC2_ANS                @ ((unsigned)&ANSEL*8)+6;
  341. volatile bit APP_ANS                     @ ((unsigned)&ANSEL*8)+6;
  342. volatile bit RC3_ANS                @ ((unsigned)&ANSEL*8)+7;

  343. // PUCR : 0x095
  344. volatile unsigned char         PUCR                @ 0x095;
  345. volatile unsigned char         PUAR                @ 0x095;
  346. volatile bit PUC0                @ ((unsigned)&PUCR*8)+0;
  347. volatile bit PUC1                @ ((unsigned)&PUCR*8)+1;
  348. volatile bit PUC2                @ ((unsigned)&PUCR*8)+2;
  349. volatile bit PUC3                @ ((unsigned)&PUCR*8)+3;
  350. volatile bit PUC4                @ ((unsigned)&PUCR*8)+4;
  351. volatile bit PUC5                @ ((unsigned)&PUCR*8)+5;
  352. volatile bit PUC6                @ ((unsigned)&PUCR*8)+6;
  353. volatile bit PUC7                @ ((unsigned)&PUCR*8)+7;
  354. #ifndef _LIB_BUILD
  355. volatile union {
  356.     struct {
  357.         unsigned        PUC0                : 1;
  358.         unsigned        PUC1                : 1;
  359.         unsigned        PUC2                : 1;
  360.         unsigned        PUC3                : 1;
  361.         unsigned        PUC4                : 1;
  362.         unsigned        PUC5                : 1;
  363.         unsigned        PUC6                : 1;
  364.         unsigned        PUC7                : 1;               
  365.     };       
  366. } PUCRbits @ 0x095;
  367. volatile union {
  368.     struct {
  369.         unsigned        PUA0                : 1;
  370.         unsigned        PUA1                : 1;
  371.         unsigned        PUA2                : 1;
  372.         unsigned        PUA3                : 1;
  373.         unsigned        PUA4                : 1;
  374.         unsigned        PUA5                : 1;
  375.         unsigned        PUA6                : 1;
  376.         unsigned        PUA7                : 1;               
  377.     };
  378. } PUARbits @ 0x095;
  379. #endif

  380. // IOCR : 0x096
  381. volatile unsigned char         IOCR                @ 0x096;
  382. volatile bit IOC0                @ ((unsigned)&IOCR*8)+0;
  383. volatile bit IOC1                @ ((unsigned)&IOCR*8)+1;
  384. volatile bit IOC2                @ ((unsigned)&IOCR*8)+2;
  385. volatile bit IOC3                @ ((unsigned)&IOCR*8)+3;
  386. volatile bit IOC4                @ ((unsigned)&IOCR*8)+4;
  387. volatile bit IOC5                @ ((unsigned)&IOCR*8)+5;
  388. volatile bit IOC6                @ ((unsigned)&IOCR*8)+6;
  389. volatile bit IOC7                @ ((unsigned)&IOCR*8)+7;
  390. volatile bit IOCA6               @ ((unsigned)&IOCR*8)+6;
  391. volatile bit IOCA7               @ ((unsigned)&IOCR*8)+7;
  392. #ifndef _LIB_BUILD
  393. volatile union {
  394.     struct {
  395.         unsigned        IOC0                : 1;
  396.         unsigned        IOC1                : 1;
  397.         unsigned        IOC2                : 1;
  398.         unsigned        IOC3                : 1;
  399.         unsigned        IOC4                : 1;
  400.         unsigned        IOC5                : 1;
  401.         unsigned        IOC6                : 1;
  402.         unsigned        IOC7                : 1;               
  403.     };
  404. } IOCRbits @ 0x096;
  405. #endif

  406. // PDCR : 0x097
  407. volatile unsigned char         PDCR                @ 0x097;
  408. volatile unsigned char         PDAR                @ 0x097;
  409. volatile bit PDC0                @ ((unsigned)&PDCR*8)+0;
  410. volatile bit PDC1                @ ((unsigned)&PDCR*8)+1;
  411. volatile bit PDC2                @ ((unsigned)&PDCR*8)+2;
  412. volatile bit PDC3                @ ((unsigned)&PDCR*8)+3;
  413. volatile bit PDC4                @ ((unsigned)&PDCR*8)+4;
  414. volatile bit PDC5                @ ((unsigned)&PDCR*8)+5;
  415. volatile bit PDC6                @ ((unsigned)&PDCR*8)+6;
  416. volatile bit PDC7                @ ((unsigned)&PDCR*8)+7;
  417. #ifndef _LIB_BUILD
  418. volatile union {
  419.     struct {
  420.         unsigned        PDC0                : 1;
  421.         unsigned        PDC1                : 1;
  422.         unsigned        PDC2                : 1;
  423.         unsigned        PDC3                : 1;
  424.         unsigned        PDC4                : 1;
  425.         unsigned        PDC5                : 1;
  426.         unsigned        PDC6                : 1;
  427.         unsigned        PDC7                : 1;               
  428.     };
  429. } PDCRbits @ 0x097;
  430. volatile union {
  431.     struct {
  432.         unsigned        PDA0                : 1;
  433.         unsigned        PDA1                : 1;
  434.         unsigned        PDA2                : 1;
  435.         unsigned        PDA3                : 1;
  436.         unsigned        PDA4                : 1;
  437.         unsigned        PDA5                : 1;
  438.         unsigned        PDA6                : 1;
  439.         unsigned        PDA7                : 1;               
  440.     };
  441. } PDARbits @ 0x097;
  442. #endif

  443. // TWSR : 0x098
  444. volatile unsigned char         TWSR                @ 0x098;
  445. volatile bit RXS                        @ ((unsigned)&TWSR*8)+0;
  446. volatile bit RXD                        @ ((unsigned)&TWSR*8)+1;
  447. volatile bit TXK                        @ ((unsigned)&TWSR*8)+2;
  448. volatile bit RXP                        @ ((unsigned)&TWSR*8)+3;
  449. volatile bit TXS                        @ ((unsigned)&TWSR*8)+4;
  450. volatile bit TXD                        @ ((unsigned)&TWSR*8)+5;
  451. volatile bit RXK                        @ ((unsigned)&TWSR*8)+6;
  452. volatile bit TXP                        @ ((unsigned)&TWSR*8)+7;
  453. #ifndef _LIB_BUILD
  454. volatile union {
  455.     struct {
  456.         unsigned        RXS                : 1;
  457.         unsigned        RXD                : 1;
  458.         unsigned        TXK                : 1;
  459.         unsigned        RXP                : 1;
  460.         unsigned        TXS                : 1;
  461.         unsigned        TXD                : 1;
  462.         unsigned        RXK                : 1;
  463.         unsigned        TXP                : 1;               
  464.     };
  465. } TWSRbits @ 0x098;
  466. #endif

  467. // EEPDR : 0x09A
  468. volatile unsigned char         EEPDR                @ 0x09A;

  469. // EEPAR : 0x09B
  470. volatile unsigned char         EEPAR                @ 0x09B;

  471. // EEPCR : 0x09C
  472. volatile unsigned char         EEPCR                @ 0x09C;
  473. volatile bit EEPRE                        @ ((unsigned)&EEPCR*8)+0;
  474. volatile bit EEPPE                        @ ((unsigned)&EEPCR*8)+1;
  475. volatile bit EEPWE                        @ ((unsigned)&EEPCR*8)+2;
  476. volatile bit EEPER                        @ ((unsigned)&EEPCR*8)+3;
  477. volatile bit EEPBR                        @ ((unsigned)&EEPCR*8)+4;
  478. volatile bit EEPMD                        @ ((unsigned)&EEPCR*8)+5;
  479. volatile bit EERST                        @ ((unsigned)&EEPCR*8)+6;
  480. volatile bit EEPEN                        @ ((unsigned)&EEPCR*8)+7;
  481. #ifndef _LIB_BUILD
  482. volatile union {
  483.     struct {
  484.         unsigned        EEPRE                : 1;
  485.         unsigned        EEPPE                : 1;
  486.         unsigned        EEPWE                : 1;
  487.         unsigned        EEPER                : 1;
  488.         unsigned        EEPBR                : 1;
  489.         unsigned        EEPMD                : 1;
  490.         unsigned        EERST                : 1;
  491.         unsigned        EEPEN                : 1;               
  492.     };
  493. } EEPCRbits @ 0x09C;
  494. #endif

  495. // TWCR : 0x09E
  496. volatile unsigned char         TWCR                @ 0x09E;
  497. volatile bit CKPS0                        @ ((unsigned)&TWCR*8)+0;
  498. volatile bit CKPS1                        @ ((unsigned)&TWCR*8)+1;
  499. volatile bit RACK                        @ ((unsigned)&TWCR*8)+2;
  500. volatile bit TACK                        @ ((unsigned)&TWCR*8)+3;
  501. volatile bit TWMST                        @ ((unsigned)&TWCR*8)+6;
  502. volatile bit TWEN                        @ ((unsigned)&TWCR*8)+7;
  503. #ifndef _LIB_BUILD
  504. volatile union {
  505.     struct {
  506.         unsigned        CKPS            : 2;       
  507.     };
  508.     struct {
  509.         unsigned        CKPS0           : 1;
  510.         unsigned        CKPS1           : 1;               
  511.         unsigned        RACK            : 1;
  512.         unsigned        TACK            : 1;
  513.         unsigned                                        : 2;
  514.         unsigned        TWMST                        : 1;                               
  515.         unsigned        TWEN                        : 1;               
  516.     };
  517. } TWCRbits @ 0x09E;
  518. #endif

  519. // ANSEL : 0x09F
  520. volatile bit ANS2                @ ((unsigned)&ANSEL*8)+2;
  521. volatile bit ANS4                @ ((unsigned)&ANSEL*8)+4;

  522. #ifndef NOP
  523. #define NOP()        asm("nop")
  524. #endif

  525. typedef        unsigned char u8;
  526. typedef unsigned short u16;

  527. #endif
复制代码

回复

使用道具 举报

 楼主| 发表于 2019-1-25 10:37:13 | 显示全部楼层
另一個參考:LGT8P653A startup guide.pdf

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 20:50 , Processed in 0.037907 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表