[DemoCode下载] N76E616 LCD 操作

[复制链接]
2189|5
 楼主| 小灵通2018 发表于 2018-11-6 18:28 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Sep/1/2015
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E616 LCD demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include <N76E616.h>
  17. #include "Version.h"
  18. #include "Typedef.h"
  19. #include "Define.h"
  20. #include "SFR_Macro.h"
  21. #include "Common.h"
  22. #include "Delay.h"

  23. /*
  24. //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
  25. //
  26. //<e0> System Clock Source Configuration
  27. // <o1> System Clock Source Selection
  28. //      <0=> 2~16   MHz  XTAL (HXT)
  29. //      <1=> 32.768 kHz  XTAL (LXT)
  30. //      <2=> 11.059 MHz  Internal (HIRC)
  31. //</e>
  32. //
  33. //<e2> Clock Divider Configuration
  34. //     <o3.0..7>  System Clock Source Devider  <1-255:1>
  35. //                     <i> Fsys = (System Clock Source) / (2 * Devider)
  36. //</e>
  37. //
  38. // <o4> Port0 Mode Selection (P0[7:0])
  39. //      <0=> Quasi-Bidirectional
  40. //      <1=> Push-Pull
  41. //      <2=> Input-Only (high-impedance)
  42. //      <3=> Open-Drain
  43. //
  44. // <o5> Port1 Mode Selection (P1[7:0])
  45. //      <0=> Quasi-Bidirectional
  46. //      <1=> Push-Pull
  47. //      <2=> Input-Only (high-impedance)
  48. //      <3=> Open-Drain
  49. //
  50. // <o6> Port2 Mode Selection (P2[7:0])
  51. //      <0=> Quasi-Bidirectional
  52. //      <1=> Push-Pull
  53. //      <2=> Input-Only (high-impedance)
  54. //      <3=> Open-Drain
  55. //
  56. // <o7> Port3 Mode Selection (P3[5:0])
  57. //      <0=> Quasi-Bidirectional
  58. //      <1=> Push-Pull
  59. //      <2=> Input-Only (high-impedance)
  60. //      <3=> Open-Drain
  61. //
  62. // <o8> Port4 Mode Selection (P4[6:0])
  63. //      <0=> Quasi-Bidirectional
  64. //      <1=> Push-Pull
  65. //      <2=> Input-Only (high-impedance)
  66. //      <3=> Open-Drain
  67. //
  68. // <o9> Port5 Mode Selection (P5[7:0])
  69. //      <0=> Quasi-Bidirectional
  70. //      <1=> Push-Pull
  71. //      <2=> Input-Only (high-impedance)
  72. //      <3=> Open-Drain
  73. //-------- <<< end of configuration section >>> ------------------------------
  74. */


  75. #include <absacc.h>  

  76. #define SYS_CLK_EN      1
  77. #define SYS_SEL         1
  78. #define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
  79. #define SYS_DIV         1

  80. #define PORT0_MODE      2
  81. #define PORT1_MODE      2
  82. #define PORT2_MODE      2
  83. #define PORT3_MODE      2
  84. #define PORT4_MODE      2
  85. #define PORT5_MODE      2

  86. #define COM0    0x01
  87. #define COM1    0x02
  88. #define COM2    0x04
  89. #define COM3    0x08

  90. bit BIT_TMP;
  91. void Show_Pattern_In_LCD(void)
  92. {
  93.     //--------------------------------------
  94.    
  95.     //show "nuvoTon"
  96.     LCDSEG3 |= SET_BIT1;                    //MCU's SEG25 enable
  97.     LCDPTR  = 25;                           //MCU's SEG25 -- LCD's SEG37
  98.     LCDDAT  = COM0;                         //LCD's COM0
  99.    
  100.     //--------------------------------------
  101.    
  102.     //show "N" -- 1'st 13seg Display
  103.     LCDSEG0 |= SET_BIT0;                    //MCU's SEG0 enable
  104.     LCDPTR  = 0;                            //MCU's SEG0 -- LCD's SEG1
  105.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
  106.    
  107.     LCDSEG0 |= SET_BIT1;                    //MCU's SEG1 enable
  108.     LCDPTR  = 1;                            //MCU's SEG1 -- LCD's SEG2
  109.     LCDDAT  = COM0;                         //LCD's COM0
  110.    
  111.     LCDSEG3 |= SET_BIT4;                    //MCU's SEG28 enable
  112.     LCDPTR  = 28;                           //MCU's SEG1 -- LCD's SEG43
  113.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
  114.    
  115.     LCDSEG3 |= SET_BIT7;                    //MCU's SEG31 enable
  116.     LCDPTR  = 31;                           //MCU's SEG1 -- LCD's SEG44
  117.     LCDDAT  = COM3;                         //LCD's COM3
  118.    
  119.     //--------------------------------------
  120.    
  121.     //show "7" -- 2'nd 13seg Display
  122.     LCDSEG0 |= SET_BIT4;                    //MCU's SEG4 enable
  123.     LCDPTR  = 4;                            //MCU's SEG4 -- LCD's SEG5
  124.     LCDDAT  = (COM1 + COM2 + COM3);         //LCD's COM1/2/3
  125.    
  126.     //--------------------------------------
  127.    
  128.     //show "6" -- 3'th 13seg Display
  129.     LCDSEG0 |= SET_BIT6;                    //MCU's SEG6 enable
  130.     LCDPTR  = 6;                            //MCU's SEG6 -- LCD's SEG7
  131.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

  132.     LCDSEG0 |= SET_BIT7;                    //MCU's SEG7 enable
  133.     LCDPTR  = 7;                            //MCU's SEG7 -- LCD's SEG8
  134.     LCDDAT  = COM2;                         //LCD's COM2  
  135.    
  136.     LCDSEG1 |= SET_BIT0;                    //MCU's SEG8 enable
  137.     LCDPTR  = 8;                            //MCU's SEG8 -- LCD's SEG9
  138.     LCDDAT  = (COM0 + COM1 + COM3);         //LCD's COM0/1/3
  139.    
  140.     LCDSEG1 |= SET_BIT1;                    //MCU's SEG9 enable
  141.     LCDPTR  = 9;                            //MCU's SEG9 -- LCD's SEG10
  142.     LCDDAT  = COM1;                         //LCD's COM1
  143.    
  144.     //--------------------------------------
  145.    
  146.     //show "E" -- 4'th 13seg Display
  147.     LCDSEG1 |= SET_BIT2;                    //MCU's SEG10 enable
  148.     LCDPTR  = 10;                           //MCU's SEG10 -- LCD's SEG11
  149.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

  150.     LCDSEG1 |= SET_BIT3;                    //MCU's SEG11 enable
  151.     LCDPTR  = 11;                           //MCU's SEG11 -- LCD's SEG12
  152.     LCDDAT  = COM2;                         //LCD's COM2  
  153.    
  154.     LCDSEG1 |= SET_BIT4;                    //MCU's SEG12 enable
  155.     LCDPTR  = 12;                           //MCU's SEG12 -- LCD's SEG13
  156.     LCDDAT  = (COM0 + COM3);                //LCD's COM0/3
  157.    
  158.     LCDSEG1 |= SET_BIT5;                    //MCU's SEG13 enable
  159.     LCDPTR  = 13;                           //MCU's SEG13 -- LCD's SEG14
  160.     LCDDAT  = COM1;                         //LCD's COM1   

  161.     //--------------------------------------
  162.    
  163. //     //show "0" -- 8'th 7seg Display
  164. //     LCDSEG2 |= SET_BIT5;                    //MCU's SEG21 enable
  165. //     LCDPTR  = 21;                           //MCU's SEG21 -- LCD's SEG33
  166. //     LCDDAT  = (COM0 + COM1 + COM2);         //LCD's COM0/1/2   

  167. //     LCDSEG2 |= SET_BIT6;                    //MCU's SEG22 enable
  168. //     LCDPTR  = 22;                           //MCU's SEG22 -- LCD's SEG34
  169. //     LCDDAT  = (COM0 + COM2 + COM3);         //LCD's COM0/2/3

  170.     //--------------------------------------
  171.    
  172.     //show "6" -- 9'th 7seg Display
  173.     LCDSEG2 |= SET_BIT3;                    //MCU's SEG19 enable
  174.     LCDPTR  = 19;                           //MCU's SEG19 -- LCD's SEG31
  175.     LCDDAT  = (COM0 + COM2);                //LCD's COM0/2

  176.     LCDSEG2 |= SET_BIT4;                    //MCU's SEG20 enable
  177.     LCDPTR  = 20;                           //MCU's SEG20 -- LCD's SEG32
  178.     LCDDAT  = (COM0 + COM1 + COM2 + COM3);  //LCD's COM0/1/2/3      

  179.     //--------------------------------------
  180.    
  181.     //show "1" -- 10'th 7seg Display
  182.     LCDSEG2 |= SET_BIT2;                    //MCU's SEG18 enable
  183.     LCDPTR  = 18;                           //MCU's SEG18 -- LCD's SEG30
  184.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2

  185.      //--------------------------------------
  186.    
  187.     //show "6" -- 9'th 7seg Display
  188.     LCDSEG1 |= SET_BIT7;                    //MCU's SEG15 enable
  189.     LCDPTR  = 15;                           //MCU's SEG15 -- LCD's SEG27
  190.     LCDDAT  = (COM1 + COM2 + COM3);         //LCD's COM1/2/3

  191.     LCDSEG2 |= SET_BIT0;                    //MCU's SEG16 enable
  192.     LCDPTR  = 16;                           //MCU's SEG16 -- LCD's SEG28
  193.     LCDDAT  = (COM0 + COM1 + COM2);         //LCD's COM0/1/2      
  194. }
  195. //-----------------------------------------------------------------------------------
  196. void LCD_Initial(void)
  197. {
  198.     LCDCON = 0x40;      //;VLCD = 0.9VDD (VDD = 3.3V, VLCD = 3.0V)
  199.                         //;1/4 duty, 1/3 bias, 150kO resistor ladder
  200.    
  201.     LCDCLK = 0x13;      //;Select LXT as LCD clock source
  202.     LCDCON |= SET_BIT7;  //LCDEN = 1
  203. }
  204. //------------------------------------------------
  205. void LCD_Blank(void)
  206. {
  207.     LCDSEG0 = 0x00;
  208.     LCDSEG1 = 0x00;
  209.     LCDSEG2 = 0x00;
  210.     LCDSEG3 = 0x00;
  211. }   
  212. /*------------------------------------------------
  213. The main C function.  Program execution starts
  214. here after stack initialization.
  215. ------------------------------------------------*/
  216. void main (void)
  217. {
  218.     /* Note
  219.        MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
  220.     */

  221.      Set_All_GPIO_Quasi_Mode();   

  222.     #if DEBUG_PORT == 0
  223.         InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
  224.     #elif DEBUG_PORT == 1
  225.         InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
  226.     #endif
  227.     Show_FW_Version_Number_To_PC();
  228.    
  229.     printf ("\n*===================================================================");
  230.     printf ("\n*  Name: N76E616 LCD Demo Code.");
  231.     printf ("\n*===================================================================\n");

  232.     LCD_Initial();

  233.     /* Change system closk source */
  234.     #if SYS_CLK_EN == 1
  235.         #if   SYS_SEL == 0
  236.             System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
  237.         #elif SYS_SEL == 1
  238.             System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
  239.         #elif SYS_SEL == 2
  240.             System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
  241.         #endif
  242.     #endif

  243. //    set_CLOEN;      //Clock out on P0.7
  244.   
  245.     #if SYS_DIV_EN == 1
  246.         CKDIV = SYS_DIV;                    //Fsys = Fosc / (2* CLKDIV) = Fcpu
  247.     #endif


  248.   #if 0
  249.     Set_All_GPIO_Quasi_Mode();
  250.   #else
  251.     #if   PORT0_MODE == 0                   //Quasi-Bidirectional
  252.         P0M1 = 0x00;
  253.         P0M2 = 0x00;
  254.     #elif PORT0_MODE == 1                   //Push-Pull
  255.         P0M1 = 0x00;
  256.         P0M2 = 0xFF;
  257.     #elif PORT0_MODE == 2                   //Input-Only
  258.         P0M1 = 0xFF;
  259.         P0M2 = 0x00;
  260.     #elif PORT0_MODE == 3                   //Open-Drain
  261.         P0M1 = 0xFF;
  262.         P0M2 = 0xFF;
  263.     #endif

  264.     #if   PORT1_MODE == 0                   //Quasi-Bidirectional
  265.         P1M1 = 0x00;
  266.         P1M2 = 0x00;
  267.     #elif PORT1_MODE == 1                   //Push-Pull
  268.         P1M1 = 0x00;
  269.         P1M2 = 0xFF;
  270.     #elif PORT1_MODE == 2                   //Input-Only
  271.         P1M1 = 0xFF;
  272.         P1M2 = 0x00;
  273.     #elif PORT1_MODE == 3                   //Open-Drain
  274.         P1M1 = 0xFF;
  275.         P1M2 = 0xFF;
  276.     #endif

  277.     #if   PORT2_MODE == 0                   //Quasi-Bidirectional
  278.         P2M1 = 0x00;
  279.         P2M2 = 0x00;
  280.     #elif PORT2_MODE == 1                   //Push-Pull
  281.         P2M1 = 0x00;
  282.         P2M2 = 0xFF;
  283.     #elif PORT2_MODE == 2                   //Input-Only
  284.         P2M1 = 0xFF;
  285.         P2M2 = 0x00;
  286.     #elif PORT2_MODE == 3                   //Open-Drain
  287.         P2M1 = 0xFF;
  288.         P2M2 = 0xFF;
  289.     #endif

  290.     #if   PORT3_MODE == 0                   //Quasi-Bidirectional
  291.         P3M1 = 0x00;
  292.         P3M2 = 0x00;
  293.     #elif PORT3_MODE == 1                   //Push-Pull
  294.         P3M1 = 0x00;
  295.         P3M2 = 0x3F;
  296.     #elif PORT3_MODE == 2                   //Input-Only
  297.         P3M1 = 0x3F;
  298.         P3M2 = 0x00;
  299.     #elif PORT3_MODE == 3                   //Open-Drain
  300.         P3M1 = 0x3F;
  301.         P3M2 = 0x3F;
  302.     #endif

  303.     #if   PORT4_MODE == 0                   //Quasi-Bidirectional
  304.         P4M1 = 0x00;
  305.         P4M2 = 0x00;
  306.     #elif PORT3_MODE == 1                   //Push-Pull
  307.         P4M1 = 0x00;
  308.         P4M2 = 0x3F;
  309.     #elif PORT3_MODE == 2                   //Input-Only
  310.         P4M1 = 0x3F;
  311.         P4M2 = 0x00;
  312.     #elif PORT3_MODE == 3                   //Open-Drain
  313.         P4M1 = 0x3F;
  314.         P4M2 = 0x3F;
  315.     #endif

  316.     #if   PORT5_MODE == 0                   //Quasi-Bidirectional
  317.         P5M1 = 0x00;
  318.         P5M2 = 0x00;
  319.     #elif PORT3_MODE == 1                   //Push-Pull
  320.         P5M1 = 0x00;
  321.         P5M2 = 0xFF;
  322.     #elif PORT3_MODE == 2                   //Input-Only
  323.         P5M1 = 0xFF;
  324.         P5M2 = 0x00;
  325.     #elif PORT3_MODE == 3                   //Open-Drain
  326.         P5M1 = 0xFF;
  327.         P5M2 = 0xFF;
  328.     #endif
  329.   #endif

  330.     while(1)
  331.     {
  332.         Show_Pattern_In_LCD();
  333.         Timer0_Delay1ms(400);
  334.         LCD_Blank();
  335.         Timer0_Delay1ms(400);
  336.     }
  337. }


 楼主| 小灵通2018 发表于 2018-11-6 18:29 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Sep/1/2015
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E616 LCD demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include <N76E616.h>
  17. #include "Version.h"
  18. #include "Typedef.h"
  19. #include "Define.h"
  20. #include "SFR_Macro.h"
  21. #include "Common.h"
  22. #include "Delay.h"

  23. /*
  24. //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
  25. //
  26. //<e0> System Clock Source Configuration
  27. // <o1> System Clock Source Selection
  28. //      <0=> 2~16   MHz  XTAL (HXT)
  29. //      <1=> 32.768 kHz  XTAL (LXT)
  30. //      <2=> 11.059 MHz  Internal (HIRC)
  31. //</e>
  32. //
  33. //<e2> Clock Divider Configuration
  34. //     <o3.0..7>  System Clock Source Devider  <1-255:1>
  35. //                     <i> Fsys = (System Clock Source) / (2 * Devider)
  36. //</e>
  37. //
  38. // <o4> Port0 Mode Selection (P0[7:0])
  39. //      <0=> Quasi-Bidirectional
  40. //      <1=> Push-Pull
  41. //      <2=> Input-Only (high-impedance)
  42. //      <3=> Open-Drain
  43. //
  44. // <o5> Port1 Mode Selection (P1[7:0])
  45. //      <0=> Quasi-Bidirectional
  46. //      <1=> Push-Pull
  47. //      <2=> Input-Only (high-impedance)
  48. //      <3=> Open-Drain
  49. //
  50. // <o6> Port2 Mode Selection (P2[7:0])
  51. //      <0=> Quasi-Bidirectional
  52. //      <1=> Push-Pull
  53. //      <2=> Input-Only (high-impedance)
  54. //      <3=> Open-Drain
  55. //
  56. // <o7> Port3 Mode Selection (P3[5:0])
  57. //      <0=> Quasi-Bidirectional
  58. //      <1=> Push-Pull
  59. //      <2=> Input-Only (high-impedance)
  60. //      <3=> Open-Drain
  61. //
  62. // <o8> Port4 Mode Selection (P4[6:0])
  63. //      <0=> Quasi-Bidirectional
  64. //      <1=> Push-Pull
  65. //      <2=> Input-Only (high-impedance)
  66. //      <3=> Open-Drain
  67. //
  68. // <o9> Port5 Mode Selection (P5[7:0])
  69. //      <0=> Quasi-Bidirectional
  70. //      <1=> Push-Pull
  71. //      <2=> Input-Only (high-impedance)
  72. //      <3=> Open-Drain
  73. //-------- <<< end of configuration section >>> ------------------------------
  74. */


  75. #include <absacc.h>  

  76. #define SYS_CLK_EN      1
  77. #define SYS_SEL         2
  78. #define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
  79. #define SYS_DIV         1

  80. #define PORT0_MODE      2
  81. #define PORT1_MODE      2
  82. #define PORT2_MODE      2
  83. #define PORT3_MODE      2
  84. #define PORT4_MODE      2
  85. #define PORT5_MODE      2

  86. #define COM0    0x01
  87. #define COM1    0x02
  88. #define COM2    0x04
  89. #define COM3    0x08

  90. bit BIT_TMP;

  91. void Show_Pattern_In_LCD(void)
  92. {
  93.     //--------------------------------------
  94.    
  95.     //show "nuvoTon"
  96.     LCDSEG3 |= SET_BIT3;                    //MCU's SEG27 enable
  97.     LCDPTR  = 27;                           //MCU's SEG27 -- LCD's SEG37
  98.     LCDDAT  = COM0;                         //LCD's COM0
  99.    
  100.     //--------------------------------------
  101.    
  102.     //show "N" -- 1'st 13seg Display
  103.     LCDSEG0 |= SET_BIT0;                    //MCU's SEG0 enable
  104.     LCDPTR  = 0;                            //MCU's SEG0 -- LCD's SEG1
  105.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
  106.    
  107.     LCDSEG0 |= SET_BIT1;                    //MCU's SEG1 enable
  108.     LCDPTR  = 1;                            //MCU's SEG1 -- LCD's SEG2
  109.     LCDDAT  = COM0;                         //LCD's COM0
  110.    
  111.     LCDSEG3 |= SET_BIT4;                    //MCU's SEG28 enable
  112.     LCDPTR  = 28;                           //MCU's SEG1 -- LCD's SEG43
  113.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
  114.    
  115.     LCDSEG3 |= SET_BIT7;                    //MCU's SEG31 enable
  116.     LCDPTR  = 31;                           //MCU's SEG1 -- LCD's SEG44
  117.     LCDDAT  = COM3;                         //LCD's COM3
  118.    
  119.     //--------------------------------------
  120.    
  121.     //show "7" -- 2'nd 13seg Display
  122.     LCDSEG0 |= SET_BIT4;                    //MCU's SEG4 enable
  123.     LCDPTR  = 4;                            //MCU's SEG4 -- LCD's SEG5
  124.     LCDDAT  = (COM1 + COM2 + COM3);         //LCD's COM1/2/3
  125.    
  126.     LCDSEG0 |= SET_BIT2;                    //MCU's SEG2 enable
  127.     LCDPTR  = 2;                            //MCU's SEG2 -- LCD's SEG3
  128.     LCDDAT  = COM2;                         //LCD's COM2

  129.     //--------------------------------------
  130.    
  131.     //show "6" -- 3'th 13seg Display
  132.     LCDSEG0 |= SET_BIT6;                    //MCU's SEG6 enable
  133.     LCDPTR  = 6;                            //MCU's SEG6 -- LCD's SEG7
  134.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

  135.     LCDSEG0 |= SET_BIT7;                    //MCU's SEG7 enable
  136.     LCDPTR  = 7;                            //MCU's SEG7 -- LCD's SEG8
  137.     LCDDAT  = COM2;                         //LCD's COM2  
  138.    
  139.     LCDSEG1 |= SET_BIT0;                    //MCU's SEG8 enable
  140.     LCDPTR  = 8;                            //MCU's SEG8 -- LCD's SEG9
  141.     LCDDAT  = (COM0 + COM1 + COM3);         //LCD's COM0/1/3
  142.    
  143.     LCDSEG1 |= SET_BIT1;                    //MCU's SEG9 enable
  144.     LCDPTR  = 9;                            //MCU's SEG9 -- LCD's SEG10
  145.     LCDDAT  = COM1;                         //LCD's COM1
  146.    
  147.     //--------------------------------------
  148.    
  149.     //show "E" -- 4'th 13seg Display
  150.     LCDSEG1 |= SET_BIT2;                    //MCU's SEG10 enable
  151.     LCDPTR  = 10;                           //MCU's SEG10 -- LCD's SEG11
  152.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

  153.     LCDSEG1 |= SET_BIT3;                    //MCU's SEG11 enable
  154.     LCDPTR  = 11;                           //MCU's SEG11 -- LCD's SEG12
  155.     LCDDAT  = COM2;                         //LCD's COM2  
  156.    
  157.     LCDSEG1 |= SET_BIT4;                    //MCU's SEG12 enable
  158.     LCDPTR  = 12;                           //MCU's SEG12 -- LCD's SEG13
  159.     LCDDAT  = (COM0 + COM3);                //LCD's COM0/3
  160.    
  161.     LCDSEG1 |= SET_BIT5;                    //MCU's SEG13 enable
  162.     LCDPTR  = 13;                           //MCU's SEG13 -- LCD's SEG14
  163.     LCDDAT  = COM1;                         //LCD's COM1   

  164.     //--------------------------------------
  165.    
  166.     //show "6" -- 9'th 7seg Display
  167.     LCDSEG1 |= SET_BIT6;                    //MCU's SEG14 enable
  168.     LCDPTR  = 14;                           //MCU's SEG14 -- LCD's SEG15
  169.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2

  170.     LCDSEG1 |= SET_BIT7;                    //MCU's SEG15 enable
  171.     LCDPTR  = 15;                           //MCU's SEG15 -- LCD's SEG16
  172.     LCDDAT  = COM2;                         //LCD's COM2      

  173.     LCDSEG2 |= SET_BIT0;                    //MCU's SEG16 enable
  174.     LCDPTR  = 16;                           //MCU's SEG16 -- LCD's SEG17
  175.     LCDDAT  = (COM0 + COM1 + COM3);         //LCD's COM0/1/3      

  176.     LCDSEG2 |= SET_BIT1;                    //MCU's SEG17 enable
  177.     LCDPTR  = 17;                           //MCU's SEG17 -- LCD's SEG18
  178.     LCDDAT  = COM1;                         //LCD's COM1      

  179.     //--------------------------------------
  180.    
  181.     //show "1" -- 10'th 7seg Display
  182.     LCDSEG2 |= SET_BIT4;                    //MCU's SEG20 enable
  183.     LCDPTR  = 20;                           //MCU's SEG20 -- LCD's SEG21
  184.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2

  185.      //--------------------------------------
  186.    
  187.     //show "6" -- 9'th 7seg Display
  188.     LCDSEG2 |= SET_BIT6;                    //MCU's SEG22 enable
  189.     LCDPTR  = 22;                           //MCU's SEG22 -- LCD's SEG23
  190.     LCDDAT  = (COM1 + COM2);                //LCD's COM1/2

  191.     LCDSEG2 |= SET_BIT7;                    //MCU's SEG23 enable
  192.     LCDPTR  = 23;                           //MCU's SEG23 -- LCD's SEG24
  193.     LCDDAT  = COM2;                         //LCD's COM2      

  194.     LCDSEG3 |= SET_BIT0;                    //MCU's SEG23 enable
  195.     LCDPTR  = 24;                           //MCU's SEG23 -- LCD's SEG24
  196.     LCDDAT  = (COM0 + COM1 + COM3);                //LCD's COM0/1/3

  197.     LCDSEG3 |= SET_BIT1;                    //MCU's SEG25 enable
  198.     LCDPTR  = 25;                           //MCU's SEG25 -- LCD's SEG26
  199.     LCDDAT  = COM1;                         //LCD's COM1      
  200.    
  201.     //--------------------------------------
  202.    
  203.     //show "Welcome"
  204.     LCDSEG2 |= SET_BIT6;                    //MCU's SEG22 enable
  205.     LCDPTR  = 22;                           //MCU's SEG22 -- LCD's SEG23
  206.     LCDDAT  |= COM3;                         //LCD's COM03
  207. }
  208. //-----------------------------------------------------------------------------------
  209. void LCD_Initial(void)
  210. {
  211.     Set_All_GPIO_Input_Mode();

  212.     //step1: enable clock source
  213.     clr_EXTEN1;
  214.     set_EXTEN0;
  215.    
  216.     //step2: check ready
  217.     while((CKSWT&SET_BIT6)==0);

  218.    
  219.     LCDCON = 0x40;      //;VLCD = 0.9VDD (VDD = 3.3V, VLCD = 3.0V)
  220.                         //;1/4 duty, 1/3 bias, 150kO resistor ladder
  221.    
  222.     LCDCLK = 0x13;      //;Select LXT as LCD clock source
  223.     LCDCON |= SET_BIT7;  //LCDEN = 1
  224. }
  225. //------------------------------------------------
  226. void LCD_Blank(void)
  227. {
  228.     LCDSEG0 = 0x00;
  229.     LCDSEG1 = 0x00;
  230.     LCDSEG2 = 0x00;
  231.     LCDSEG3 = 0x00;
  232. }   
  233. /*------------------------------------------------
  234. The main C function.  Program execution starts
  235. here after stack initialization.
  236. ------------------------------------------------*/
  237. void main (void)
  238. {
  239.     /* Note
  240.        MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
  241.     */

  242. #if 0   
  243.     Set_All_GPIO_Quasi_Mode();   

  244.     #if DEBUG_PORT == 0
  245.         InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
  246.     #elif DEBUG_PORT == 1
  247.         InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
  248.     #endif
  249.     Show_FW_Version_Number_To_PC();
  250.    
  251.     printf ("\n*===================================================================");
  252.     printf ("\n*  Name: N76E616 LCD Demo Code.");
  253.     printf ("\n*===================================================================\n");
  254. #endif
  255.    
  256.     LCD_Initial();

  257.     /* Change system closk source */
  258.     #if SYS_CLK_EN == 1
  259.         #if   SYS_SEL == 0
  260.             System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
  261.         #elif SYS_SEL == 1
  262.             System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
  263.         #elif SYS_SEL == 2
  264.             System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
  265.         #endif
  266.     #endif

  267. //    set_CLOEN;      //Clock out on P0.7
  268.   
  269.     #if SYS_DIV_EN == 1
  270.         CKDIV = SYS_DIV;                    //Fsys = Fosc / (2* CLKDIV) = Fcpu
  271.     #endif

  272.   #if 0
  273.     Set_All_GPIO_Quasi_Mode();
  274.   #else
  275.     #if   PORT0_MODE == 0                   //Quasi-Bidirectional
  276.         P0M1 = 0x00;
  277.         P0M2 = 0x00;
  278.     #elif PORT0_MODE == 1                   //Push-Pull
  279.         P0M1 = 0x00;
  280.         P0M2 = 0xFF;
  281.     #elif PORT0_MODE == 2                   //Input-Only
  282.         P0M1 = 0xFF;
  283.         P0M2 = 0x00;
  284.     #elif PORT0_MODE == 3                   //Open-Drain
  285.         P0M1 = 0xFF;
  286.         P0M2 = 0xFF;
  287.     #endif

  288.     #if   PORT1_MODE == 0                   //Quasi-Bidirectional
  289.         P1M1 = 0x00;
  290.         P1M2 = 0x00;
  291.     #elif PORT1_MODE == 1                   //Push-Pull
  292.         P1M1 = 0x00;
  293.         P1M2 = 0xFF;
  294.     #elif PORT1_MODE == 2                   //Input-Only
  295.         P1M1 = 0xFF;
  296.         P1M2 = 0x00;
  297.     #elif PORT1_MODE == 3                   //Open-Drain
  298.         P1M1 = 0xFF;
  299.         P1M2 = 0xFF;
  300.     #endif

  301.     #if   PORT2_MODE == 0                   //Quasi-Bidirectional
  302.         P2M1 = 0x00;
  303.         P2M2 = 0x00;
  304.     #elif PORT2_MODE == 1                   //Push-Pull
  305.         P2M1 = 0x00;
  306.         P2M2 = 0xFF;
  307.     #elif PORT2_MODE == 2                   //Input-Only
  308.         P2M1 = 0xFF;
  309.         P2M2 = 0x00;
  310.     #elif PORT2_MODE == 3                   //Open-Drain
  311.         P2M1 = 0xFF;
  312.         P2M2 = 0xFF;
  313.     #endif

  314.     #if   PORT3_MODE == 0                   //Quasi-Bidirectional
  315.         P3M1 = 0x00;
  316.         P3M2 = 0x00;
  317.     #elif PORT3_MODE == 1                   //Push-Pull
  318.         P3M1 = 0x00;
  319.         P3M2 = 0x7F;
  320.     #elif PORT3_MODE == 2                   //Input-Only
  321.         P3M1 = 0x7F;
  322.         P3M2 = 0x00;
  323.     #elif PORT3_MODE == 3                   //Open-Drain
  324.         P3M1 = 0x7F;
  325.         P3M2 = 0x7F;
  326.     #endif

  327.     #if   PORT4_MODE == 0                   //Quasi-Bidirectional
  328.         P4M1 = 0x00;
  329.         P4M2 = 0x00;
  330.     #elif PORT4_MODE == 1                   //Push-Pull
  331.         P4M1 = 0x00;
  332.         P4M2 = 0x7F;
  333.     #elif PORT4_MODE == 2                   //Input-Only
  334.         P4M1 = 0x7F;
  335.         P4M2 = 0x00;
  336.     #elif PORT4_MODE == 3                   //Open-Drain
  337.         P4M1 = 0x7F;
  338.         P4M2 = 0x7F;
  339.     #endif

  340.     #if   PORT5_MODE == 0                   //Quasi-Bidirectional
  341.         P5M1 = 0x00;
  342.         P5M2 = 0x00;
  343.     #elif PORT5_MODE == 1                   //Push-Pull
  344.         P5M1 = 0x00;
  345.         P5M2 = 0xFF;
  346.     #elif PORT5_MODE == 2                   //Input-Only
  347.         P5M1 = 0xFF;
  348.         P5M2 = 0x00;
  349.     #elif PORT5_MODE == 3                   //Open-Drain
  350.         P5M1 = 0xFF;
  351.         P5M2 = 0xFF;
  352.     #endif
  353.   #endif

  354.     while(1)
  355.     {
  356.         Show_Pattern_In_LCD();
  357.         Timer0_Delay1ms(500);
  358.         LCD_Blank();
  359.         Timer0_Delay1ms(500);
  360.     }
  361. }
 楼主| 小灵通2018 发表于 2018-11-6 18:31 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Sep/1/2015
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E616 LCD Display Temperature Demo Code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include <N76E616.h>
  17. #include "Version.h"
  18. #include "Typedef.h"
  19. #include "Define.h"
  20. #include "SFR_Macro.h"
  21. #include "Common.h"
  22. #include "Delay.h"
  23. #include "Display.h"

  24. #define SCL            P06
  25. #define SDA            P05

  26. #define TMP421_Addr     0x98
  27. #define LT_PTR          0x00
  28. #define STATUS_PTR      0x08
  29. #define CR1_PTR         0x09
  30. #define CR2_PTR         0x0A
  31. #define ONE_SHOT_PTR    0x0F
  32. #define SWRST_PTR       0xFC
  33. #define MID_PTR         0xFE
  34. #define DID_PTR         0xFF
  35. #define TMP421_Addr     0x98


  36. //Global variables
  37. volatile unsigned char LED_phase = 0;
  38. volatile float temperature;
  39. volatile bit I2C_error = 0;
  40. volatile bit TMP421_error = 0;

  41. volatile unsigned char temp = 0;

  42. bit  bdata I2C_Ack;   //??????

  43. /*
  44. //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
  45. //
  46. //<e0> System Clock Source Configuration
  47. // <o1> System Clock Source Selection
  48. //      <0=> 2~16   MHz  XTAL (HXT)
  49. //      <1=> 32.768 kHz  XTAL (LXT)
  50. //      <2=> 11.059 MHz  Internal (HIRC)
  51. //</e>
  52. //
  53. //<e2> Clock Divider Configuration
  54. //     <o3.0..7>  System Clock Source Devider  <1-255:1>
  55. //                     <i> Fsys = (System Clock Source) / (2 * Devider)
  56. //</e>
  57. //
  58. // <o4> Port0 Mode Selection (P0[7:0])
  59. //      <0=> Quasi-Bidirectional
  60. //      <1=> Push-Pull
  61. //      <2=> Input-Only (high-impedance)
  62. //      <3=> Open-Drain
  63. //
  64. // <o5> Port1 Mode Selection (P1[7:0])
  65. //      <0=> Quasi-Bidirectional
  66. //      <1=> Push-Pull
  67. //      <2=> Input-Only (high-impedance)
  68. //      <3=> Open-Drain
  69. //
  70. // <o6> Port2 Mode Selection (P2[7:0])
  71. //      <0=> Quasi-Bidirectional
  72. //      <1=> Push-Pull
  73. //      <2=> Input-Only (high-impedance)
  74. //      <3=> Open-Drain
  75. //
  76. // <o7> Port3 Mode Selection (P3[5:0])
  77. //      <0=> Quasi-Bidirectional
  78. //      <1=> Push-Pull
  79. //      <2=> Input-Only (high-impedance)
  80. //      <3=> Open-Drain
  81. //
  82. // <o8> Port4 Mode Selection (P4[6:0])
  83. //      <0=> Quasi-Bidirectional
  84. //      <1=> Push-Pull
  85. //      <2=> Input-Only (high-impedance)
  86. //      <3=> Open-Drain
  87. //
  88. // <o9> Port5 Mode Selection (P5[7:0])
  89. //      <0=> Quasi-Bidirectional
  90. //      <1=> Push-Pull
  91. //      <2=> Input-Only (high-impedance)
  92. //      <3=> Open-Drain
  93. //-------- <<< end of configuration section >>> ------------------------------
  94. */


  95. #include <absacc.h>  

  96. #define SYS_CLK_EN      1
  97. #define SYS_SEL         2
  98. #define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
  99. #define SYS_DIV         1

  100. #define PORT0_MODE      2
  101. #define PORT1_MODE      2
  102. #define PORT2_MODE      2
  103. #define PORT3_MODE      2
  104. #define PORT4_MODE      2
  105. #define PORT5_MODE      2

  106. bit BIT_TMP;

  107. //------------------------------------------------
  108. void Init_I2C(void)
  109. {
  110.     P0M1 |= 0x60;                               //Configure SDA(P05) and SCL(P06) pins open-drain
  111.     P0M2 |= 0x60;   
  112. }
  113. //------------------------------------------------
  114. void I2C_Start()
  115. {
  116.         SDA = 1;     
  117.     _nop_();
  118.         SCL = 1;
  119.     _nop_();
  120.     _nop_();
  121.     _nop_();
  122.     _nop_();
  123.     _nop_();
  124.         SDA = 0;     
  125.     _nop_();
  126.     _nop_();
  127.     _nop_();
  128.     _nop_();
  129.     _nop_();
  130.         SCL = 0;     
  131.     _nop_();
  132.     _nop_();
  133. }
  134. //------------------------------------------------
  135. void I2C_Stop()
  136. {
  137.         SDA = 0;     
  138.     _nop_();
  139.         SCL = 1;     
  140.     _nop_();
  141.     _nop_();
  142.     _nop_();
  143.     _nop_();
  144.     _nop_();
  145.         SDA = 1;     
  146.     _nop_();
  147.     _nop_();
  148.     _nop_();
  149.     _nop_();
  150. }
  151. //------------------------------------------------
  152. bit I2C_CheckAck(void)
  153. {
  154.         UINT8 errtime = 255;   
  155.         SDA = 1;
  156.     _nop_();
  157.     _nop_();
  158.     _nop_();
  159.         SCL = 1;
  160.     _nop_();
  161.     _nop_();
  162.     _nop_();
  163.     _nop_();
  164.     _nop_();
  165.         while(SDA)
  166.         {
  167.                 errtime--;
  168.                 if(errtime==0)
  169.                 {
  170.                         I2C_Stop();
  171.                         return(0);
  172.                 }
  173.         }
  174.         SCL = 0;
  175.     _nop_();
  176.         return(1);
  177. }
  178. //------------------------------------------------
  179. void I2C_SendB(UINT8 c)
  180. {
  181.         UINT8 BitCnt;
  182.         for (BitCnt=0; BitCnt<8; BitCnt++)  
  183.         {
  184.                 if((c<<BitCnt)&0x80)   
  185.                 {
  186.                         SDA = 1;
  187.                 }
  188.                 else
  189.                 {
  190.                         SDA = 0;
  191.                 }
  192.         _nop_();
  193.         _nop_();
  194.                 SCL = 1;      
  195.         _nop_();
  196.         _nop_();
  197.         _nop_();
  198.         _nop_();
  199.         _nop_();
  200.                 SCL = 0;
  201.         }
  202.     _nop_();
  203.     _nop_();
  204.         I2C_Ack = I2C_CheckAck();   
  205.     _nop_();
  206.     _nop_();
  207. }
  208. //------------------------------------------------
  209. UINT8 I2C_RcvB()
  210. {
  211.         UINT8 retc;
  212.         UINT8 BitCnt;        
  213.         retc = 0;
  214.         SDA = 1;         
  215.         for(BitCnt=0;BitCnt<8;BitCnt++)
  216.         {
  217.         _nop_();
  218.                 SCL = 0;        
  219.         _nop_();
  220.         _nop_();
  221.         _nop_();
  222.         _nop_();
  223.         _nop_();
  224.                 SCL = 1;        
  225.         _nop_();
  226.         _nop_();
  227.                 retc = retc<<1;
  228.                 if(SDA==1)
  229.                 {
  230.                         retc = retc + 1;     
  231.                 }
  232.         _nop_();
  233.         _nop_();
  234.         }
  235.         SCL = 0;
  236.     _nop_();
  237.     _nop_();
  238.         return(retc);
  239. }
  240. //------------------------------------------------
  241. void I2C_Ackn(bit a)
  242. {
  243.         if(a==0)     
  244.         {
  245.                 SDA = 0;
  246.         }
  247.         else
  248.         {
  249.                 SDA = 1;
  250.         }
  251.     _nop_();
  252.     _nop_();
  253.     _nop_();
  254.         SCL = 1;
  255.     _nop_();
  256.     _nop_();
  257.     _nop_();
  258.     _nop_();
  259.     _nop_();
  260.         SCL = 0;     
  261.     _nop_();
  262.     _nop_();
  263. }
  264. //------------------------------------------------
  265. unsigned char TMP421_reg_write(unsigned char u8AddrByte, unsigned char u8PtrRegByte, unsigned char u8DataByte)
  266. {
  267.         I2C_Start();   
  268.         I2C_SendB(u8AddrByte);   
  269.         if(!I2C_Ack)
  270.         {
  271.                 return(0);
  272.         }
  273.         I2C_SendB(u8PtrRegByte);   
  274.         if(!I2C_Ack)
  275.         {
  276.                 return(0);
  277.         }
  278.         I2C_SendB(u8DataByte);   
  279.         if(!I2C_Ack)
  280.         {
  281.                 return(0);
  282.         }
  283.         I2C_Stop();     
  284.         return(1);
  285. }
  286. //------------------------------------------------
  287. unsigned char TMP421_reg_read(unsigned char u8AddrByte, unsigned char u8PtrRegByte)
  288. {
  289.         unsigned char u8RtnValue=0;
  290.    
  291.     I2C_Start();     
  292.         I2C_SendB(u8AddrByte);
  293.         if(!I2C_Ack)
  294.         {
  295.                 return(0);
  296.         }
  297.         I2C_SendB(u8PtrRegByte);   
  298.         if(!I2C_Ack)
  299.         {
  300.                 return(0);
  301.         }
  302.         I2C_Start();     
  303.         I2C_SendB(u8AddrByte+1);   
  304.         if(!I2C_Ack)
  305.         {
  306.                 return(0);
  307.         }
  308.         u8RtnValue = I2C_RcvB();   
  309.         I2C_Ackn(1);     
  310.         I2C_Stop();
  311.         return(u8RtnValue);
  312. }
  313. //------------------------------------------------
  314. unsigned char Read_Temperature(unsigned char u8AddrByte, unsigned char u8PtrRegByte)
  315. {
  316.     unsigned char u8ReadHiByte, u8ReadLoByte;

  317.     TMP421_reg_write(TMP421_Addr, ONE_SHOT_PTR, 0xFF);   //One-shot conversion
  318.    
  319.     do
  320.     {
  321.         I2C_error = 0;
  322.         
  323.         I2C_Start();     
  324.         I2C_SendB(u8AddrByte);
  325.         if(!I2C_Ack)
  326.         {
  327.             return(0);
  328.         }
  329.         I2C_SendB(u8PtrRegByte);   
  330.         if(!I2C_Ack)
  331.         {
  332.             return(0);
  333.         }
  334.         I2C_Start();     
  335.         I2C_SendB(u8AddrByte+1);   
  336.         if(!I2C_Ack)
  337.         {
  338.             return(0);
  339.         }
  340.         u8ReadHiByte = I2C_RcvB();   
  341.         I2C_Ackn(0);     
  342.         
  343.         u8ReadLoByte = I2C_RcvB()>>4;   
  344. //        I2C_Ackn(1);         
  345.         I2C_Stop();
  346.         
  347.         //Calculate temperature degree
  348.         temperature = (float)((signed int)(u8ReadHiByte - 64) + 0.0625 * u8ReadLoByte);
  349.         
  350.     }while(I2C_error);
  351.    
  352.     return(1);

  353. }
  354. //------------------------------------------------
  355. void Init_TMP421(void)
  356. {
  357.     unsigned char MID, DID, i, status;

  358. #if 1   
  359.     MID = TMP421_reg_read(TMP421_Addr, MID_PTR);
  360.     if(MID != 0x55)
  361.     {
  362.         P02=0;
  363.         while(1);
  364.     }
  365.     else
  366.         P03=0;
  367.    
  368.     DID = TMP421_reg_read(TMP421_Addr, DID_PTR);
  369.     if(DID != 0x21)
  370.     {
  371.         P02=0;
  372.         while(1);
  373.     }
  374.     else
  375.         P03=0;

  376. #endif

  377.     TMP421_reg_write(TMP421_Addr, SWRST_PTR, 0xFF);          //Software reset
  378.     TMP421_reg_write(TMP421_Addr, CR1_PTR, 0x44);            //Change out code as extended binary, enter shutdown mode
  379.     TMP421_reg_write(TMP421_Addr, CR2_PTR, 0x08);            //Enable local sensor, disable others


  380.     for (i = 1; i <= 2; i++)                    //Ignore first two conversions. They are not correct.
  381.     {
  382.         TMP421_reg_write(TMP421_Addr, ONE_SHOT_PTR, 0xFF);   //One-shot conversion

  383.         do                                      //Polling BUSY
  384.         {
  385.             status = TMP421_reg_read(TMP421_Addr, STATUS_PTR);
  386.         } while (status != 0x00);
  387.     }
  388. }
  389. //------------------------------------------------

  390. /*------------------------------------------------
  391. The main C function.  Program execution starts
  392. here after stack initialization.
  393. ------------------------------------------------*/
  394. void main (void)
  395. {
  396.     /* Note
  397.        MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
  398.     */
  399.     signed int tmp;

  400. #if 0
  401.     Set_All_GPIO_Quasi_Mode();   
  402.    
  403.     #if DEBUG_PORT == 0
  404.         InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
  405.     #elif DEBUG_PORT == 1
  406.         InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
  407.     #endif
  408.     Show_FW_Version_Number_To_PC();
  409.    
  410.     printf ("\n*===================================================================");
  411.     printf ("\n*  Name: N76E616 LCD Display Temperature Demo Code.");
  412.     printf ("\n*===================================================================\n");
  413. #endif
  414.        
  415.     /* Change system closk source */
  416.     #if SYS_CLK_EN == 1
  417.         #if   SYS_SEL == 0
  418.             System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
  419.         #elif SYS_SEL == 1
  420.             System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
  421.         #elif SYS_SEL == 2
  422.             System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
  423.         #endif
  424.     #endif

  425. //    set_CLOEN;      //Clock out on P0.7
  426.   
  427.     #if SYS_DIV_EN == 1
  428.         CKDIV = SYS_DIV;                    //Fsys = Fosc / (2* CLKDIV) = Fcpu
  429.     #endif

  430.   #if 0
  431.     Set_All_GPIO_Quasi_Mode();
  432.   #else
  433.     #if   PORT0_MODE == 0                   //Quasi-Bidirectional
  434.         P0M1 = 0x00;
  435.         P0M2 = 0x00;
  436.     #elif PORT0_MODE == 1                   //Push-Pull
  437.         P0M1 = 0x00;
  438.         P0M2 = 0xFF;
  439.     #elif PORT0_MODE == 2                   //Input-Only
  440.         P0M1 = 0xFF;
  441.         P0M2 = 0x00;
  442.     #elif PORT0_MODE == 3                   //Open-Drain
  443.         P0M1 = 0xFF;
  444.         P0M2 = 0xFF;
  445.     #endif

  446.     #if   PORT1_MODE == 0                   //Quasi-Bidirectional
  447.         P1M1 = 0x00;
  448.         P1M2 = 0x00;
  449.     #elif PORT1_MODE == 1                   //Push-Pull
  450.         P1M1 = 0x00;
  451.         P1M2 = 0xFF;
  452.     #elif PORT1_MODE == 2                   //Input-Only
  453.         P1M1 = 0xFF;
  454.         P1M2 = 0x00;
  455.     #elif PORT1_MODE == 3                   //Open-Drain
  456.         P1M1 = 0xFF;
  457.         P1M2 = 0xFF;
  458.     #endif

  459.     #if   PORT2_MODE == 0                   //Quasi-Bidirectional
  460.         P2M1 = 0x00;
  461.         P2M2 = 0x00;
  462.     #elif PORT2_MODE == 1                   //Push-Pull
  463.         P2M1 = 0x00;
  464.         P2M2 = 0xFF;
  465.     #elif PORT2_MODE == 2                   //Input-Only
  466.         P2M1 = 0xFF;
  467.         P2M2 = 0x00;
  468.     #elif PORT2_MODE == 3                   //Open-Drain
  469.         P2M1 = 0xFF;
  470.         P2M2 = 0xFF;
  471.     #endif

  472.     #if   PORT3_MODE == 0                   //Quasi-Bidirectional
  473.         P3M1 = 0x00;
  474.         P3M2 = 0x00;
  475.     #elif PORT3_MODE == 1                   //Push-Pull
  476.         P3M1 = 0x00;
  477.         P3M2 = 0x7F;
  478.     #elif PORT3_MODE == 2                   //Input-Only
  479.         P3M1 = 0x7F;
  480.         P3M2 = 0x00;
  481.     #elif PORT3_MODE == 3                   //Open-Drain
  482.         P3M1 = 0x7F;
  483.         P3M2 = 0x7F;
  484.     #endif

  485.     #if   PORT4_MODE == 0                   //Quasi-Bidirectional
  486.         P4M1 = 0x00;
  487.         P4M2 = 0x00;
  488.     #elif PORT4_MODE == 1                   //Push-Pull
  489.         P4M1 = 0x00;
  490.         P4M2 = 0x7F;
  491.     #elif PORT4_MODE == 2                   //Input-Only
  492.         P4M1 = 0x7F;
  493.         P4M2 = 0x00;
  494.     #elif PORT4_MODE == 3                   //Open-Drain
  495.         P4M1 = 0x7F;
  496.         P4M2 = 0x7F;
  497.     #endif

  498.     #if   PORT5_MODE == 0                   //Quasi-Bidirectional
  499.         P5M1 = 0x00;
  500.         P5M2 = 0x00;
  501.     #elif PORT5_MODE == 1                   //Push-Pull
  502.         P5M1 = 0x00;
  503.         P5M2 = 0xFF;
  504.     #elif PORT5_MODE == 2                   //Input-Only
  505.         P5M1 = 0xFF;
  506.         P5M2 = 0x00;
  507.     #elif PORT5_MODE == 3                   //Open-Drain
  508.         P5M1 = 0xFF;
  509.         P5M2 = 0xFF;
  510.     #endif
  511.   #endif

  512.     LCD_Initial();

  513.     LCD_Try_Run();

  514.     LCD_Display_All_Clear();
  515.     LCD_Display_N76E616_Pattern();
  516.     LCD_Display_Welcome_Pattern();
  517.     Timer0_Delay1ms(1000);
  518.    
  519.     Init_I2C();                               //Initialize I2C
  520.     Init_TMP421();                            //Initialize temperature sensor by I2C commands

  521.     while(1)
  522.     {
  523.         Read_Temperature(TMP421_Addr, LT_PTR);
  524.         tmp = (signed int)(temperature*10);
  525.         
  526.         LCD_Display_All_Clear();

  527.         LCD_Display_Num_2(tmp/100);
  528.         LCD_Display_Num_3(tmp%100/10);
  529.         LCD_Display_Num_4(tmp%100%10);
  530.         
  531.         LCD_Display_3DP();
  532.         LCD_Display_Degree();

  533.         LCD_Display_nuvoTon_**();
  534.         LCD_Display_Welcome_Pattern();

  535.         Timer0_Delay1ms(500);
  536.     }
  537. }
幸福小强 发表于 2018-11-6 20:20 | 显示全部楼层
是不是130的那个板子带LCD
小明的同学 发表于 2018-11-6 22:35 | 显示全部楼层
没看懂。
天灵灵地灵灵 发表于 2018-11-7 13:30 | 显示全部楼层
51内核带LCD的芯片还不多,谢谢分享。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

158

主题

1732

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部