[DemoCode下载]

N76E616 LCD 操作

[复制链接]
1918|5
手机看帖
扫描二维码
随时随地手机跟帖
小灵通2018|  楼主 | 2018-11-6 18:28 | 显示全部楼层 |阅读模式
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

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

//***********************************************************************************************************
//  File Function: N76E616 LCD demo code
//***********************************************************************************************************

#include <stdio.h>
#include <N76E616.h>
#include "Version.h"
#include "Typedef.h"
#include "Define.h"
#include "SFR_Macro.h"
#include "Common.h"
#include "Delay.h"

/*
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
//
//<e0> System Clock Source Configuration
// <o1> System Clock Source Selection
//      <0=> 2~16   MHz  XTAL (HXT)
//      <1=> 32.768 kHz  XTAL (LXT)
//      <2=> 11.059 MHz  Internal (HIRC)
//</e>
//
//<e2> Clock Divider Configuration
//     <o3.0..7>  System Clock Source Devider  <1-255:1>
//                     <i> Fsys = (System Clock Source) / (2 * Devider)
//</e>
//
// <o4> Port0 Mode Selection (P0[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o5> Port1 Mode Selection (P1[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o6> Port2 Mode Selection (P2[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o7> Port3 Mode Selection (P3[5:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o8> Port4 Mode Selection (P4[6:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o9> Port5 Mode Selection (P5[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//-------- <<< end of configuration section >>> ------------------------------
*/


#include <absacc.h>  

#define SYS_CLK_EN      1
#define SYS_SEL         1
#define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
#define SYS_DIV         1

#define PORT0_MODE      2
#define PORT1_MODE      2
#define PORT2_MODE      2
#define PORT3_MODE      2
#define PORT4_MODE      2
#define PORT5_MODE      2

#define COM0    0x01
#define COM1    0x02
#define COM2    0x04
#define COM3    0x08

bit BIT_TMP;
void Show_Pattern_In_LCD(void)
{
    //--------------------------------------
   
    //show "nuvoTon"
    LCDSEG3 |= SET_BIT1;                    //MCU's SEG25 enable
    LCDPTR  = 25;                           //MCU's SEG25 -- LCD's SEG37
    LCDDAT  = COM0;                         //LCD's COM0
   
    //--------------------------------------
   
    //show "N" -- 1'st 13seg Display
    LCDSEG0 |= SET_BIT0;                    //MCU's SEG0 enable
    LCDPTR  = 0;                            //MCU's SEG0 -- LCD's SEG1
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
   
    LCDSEG0 |= SET_BIT1;                    //MCU's SEG1 enable
    LCDPTR  = 1;                            //MCU's SEG1 -- LCD's SEG2
    LCDDAT  = COM0;                         //LCD's COM0
   
    LCDSEG3 |= SET_BIT4;                    //MCU's SEG28 enable
    LCDPTR  = 28;                           //MCU's SEG1 -- LCD's SEG43
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
   
    LCDSEG3 |= SET_BIT7;                    //MCU's SEG31 enable
    LCDPTR  = 31;                           //MCU's SEG1 -- LCD's SEG44
    LCDDAT  = COM3;                         //LCD's COM3
   
    //--------------------------------------
   
    //show "7" -- 2'nd 13seg Display
    LCDSEG0 |= SET_BIT4;                    //MCU's SEG4 enable
    LCDPTR  = 4;                            //MCU's SEG4 -- LCD's SEG5
    LCDDAT  = (COM1 + COM2 + COM3);         //LCD's COM1/2/3
   
    //--------------------------------------
   
    //show "6" -- 3'th 13seg Display
    LCDSEG0 |= SET_BIT6;                    //MCU's SEG6 enable
    LCDPTR  = 6;                            //MCU's SEG6 -- LCD's SEG7
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

    LCDSEG0 |= SET_BIT7;                    //MCU's SEG7 enable
    LCDPTR  = 7;                            //MCU's SEG7 -- LCD's SEG8
    LCDDAT  = COM2;                         //LCD's COM2  
   
    LCDSEG1 |= SET_BIT0;                    //MCU's SEG8 enable
    LCDPTR  = 8;                            //MCU's SEG8 -- LCD's SEG9
    LCDDAT  = (COM0 + COM1 + COM3);         //LCD's COM0/1/3
   
    LCDSEG1 |= SET_BIT1;                    //MCU's SEG9 enable
    LCDPTR  = 9;                            //MCU's SEG9 -- LCD's SEG10
    LCDDAT  = COM1;                         //LCD's COM1
   
    //--------------------------------------
   
    //show "E" -- 4'th 13seg Display
    LCDSEG1 |= SET_BIT2;                    //MCU's SEG10 enable
    LCDPTR  = 10;                           //MCU's SEG10 -- LCD's SEG11
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

    LCDSEG1 |= SET_BIT3;                    //MCU's SEG11 enable
    LCDPTR  = 11;                           //MCU's SEG11 -- LCD's SEG12
    LCDDAT  = COM2;                         //LCD's COM2  
   
    LCDSEG1 |= SET_BIT4;                    //MCU's SEG12 enable
    LCDPTR  = 12;                           //MCU's SEG12 -- LCD's SEG13
    LCDDAT  = (COM0 + COM3);                //LCD's COM0/3
   
    LCDSEG1 |= SET_BIT5;                    //MCU's SEG13 enable
    LCDPTR  = 13;                           //MCU's SEG13 -- LCD's SEG14
    LCDDAT  = COM1;                         //LCD's COM1   

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

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

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

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

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

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

    LCDSEG2 |= SET_BIT0;                    //MCU's SEG16 enable
    LCDPTR  = 16;                           //MCU's SEG16 -- LCD's SEG28
    LCDDAT  = (COM0 + COM1 + COM2);         //LCD's COM0/1/2      
}
//-----------------------------------------------------------------------------------
void LCD_Initial(void)
{
    LCDCON = 0x40;      //;VLCD = 0.9VDD (VDD = 3.3V, VLCD = 3.0V)
                        //;1/4 duty, 1/3 bias, 150kO resistor ladder
   
    LCDCLK = 0x13;      //;Select LXT as LCD clock source
    LCDCON |= SET_BIT7;  //LCDEN = 1
}
//------------------------------------------------
void LCD_Blank(void)
{
    LCDSEG0 = 0x00;
    LCDSEG1 = 0x00;
    LCDSEG2 = 0x00;
    LCDSEG3 = 0x00;
}   
/*------------------------------------------------
The main C function.  Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void)
{
    /* Note
       MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
    */

     Set_All_GPIO_Quasi_Mode();   

    #if DEBUG_PORT == 0
        InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
    #elif DEBUG_PORT == 1
        InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
    #endif
    Show_FW_Version_Number_To_PC();
   
    printf ("\n*===================================================================");
    printf ("\n*  Name: N76E616 LCD Demo Code.");
    printf ("\n*===================================================================\n");

    LCD_Initial();

    /* Change system closk source */
    #if SYS_CLK_EN == 1
        #if   SYS_SEL == 0
            System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
        #elif SYS_SEL == 1
            System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
        #elif SYS_SEL == 2
            System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
        #endif
    #endif

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


  #if 0
    Set_All_GPIO_Quasi_Mode();
  #else
    #if   PORT0_MODE == 0                   //Quasi-Bidirectional
        P0M1 = 0x00;
        P0M2 = 0x00;
    #elif PORT0_MODE == 1                   //Push-Pull
        P0M1 = 0x00;
        P0M2 = 0xFF;
    #elif PORT0_MODE == 2                   //Input-Only
        P0M1 = 0xFF;
        P0M2 = 0x00;
    #elif PORT0_MODE == 3                   //Open-Drain
        P0M1 = 0xFF;
        P0M2 = 0xFF;
    #endif

    #if   PORT1_MODE == 0                   //Quasi-Bidirectional
        P1M1 = 0x00;
        P1M2 = 0x00;
    #elif PORT1_MODE == 1                   //Push-Pull
        P1M1 = 0x00;
        P1M2 = 0xFF;
    #elif PORT1_MODE == 2                   //Input-Only
        P1M1 = 0xFF;
        P1M2 = 0x00;
    #elif PORT1_MODE == 3                   //Open-Drain
        P1M1 = 0xFF;
        P1M2 = 0xFF;
    #endif

    #if   PORT2_MODE == 0                   //Quasi-Bidirectional
        P2M1 = 0x00;
        P2M2 = 0x00;
    #elif PORT2_MODE == 1                   //Push-Pull
        P2M1 = 0x00;
        P2M2 = 0xFF;
    #elif PORT2_MODE == 2                   //Input-Only
        P2M1 = 0xFF;
        P2M2 = 0x00;
    #elif PORT2_MODE == 3                   //Open-Drain
        P2M1 = 0xFF;
        P2M2 = 0xFF;
    #endif

    #if   PORT3_MODE == 0                   //Quasi-Bidirectional
        P3M1 = 0x00;
        P3M2 = 0x00;
    #elif PORT3_MODE == 1                   //Push-Pull
        P3M1 = 0x00;
        P3M2 = 0x3F;
    #elif PORT3_MODE == 2                   //Input-Only
        P3M1 = 0x3F;
        P3M2 = 0x00;
    #elif PORT3_MODE == 3                   //Open-Drain
        P3M1 = 0x3F;
        P3M2 = 0x3F;
    #endif

    #if   PORT4_MODE == 0                   //Quasi-Bidirectional
        P4M1 = 0x00;
        P4M2 = 0x00;
    #elif PORT3_MODE == 1                   //Push-Pull
        P4M1 = 0x00;
        P4M2 = 0x3F;
    #elif PORT3_MODE == 2                   //Input-Only
        P4M1 = 0x3F;
        P4M2 = 0x00;
    #elif PORT3_MODE == 3                   //Open-Drain
        P4M1 = 0x3F;
        P4M2 = 0x3F;
    #endif

    #if   PORT5_MODE == 0                   //Quasi-Bidirectional
        P5M1 = 0x00;
        P5M2 = 0x00;
    #elif PORT3_MODE == 1                   //Push-Pull
        P5M1 = 0x00;
        P5M2 = 0xFF;
    #elif PORT3_MODE == 2                   //Input-Only
        P5M1 = 0xFF;
        P5M2 = 0x00;
    #elif PORT3_MODE == 3                   //Open-Drain
        P5M1 = 0xFF;
        P5M2 = 0xFF;
    #endif
  #endif

    while(1)
    {
        Show_Pattern_In_LCD();
        Timer0_Delay1ms(400);
        LCD_Blank();
        Timer0_Delay1ms(400);
    }
}


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

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

//***********************************************************************************************************
//  File Function: N76E616 LCD demo code
//***********************************************************************************************************

#include <stdio.h>
#include <N76E616.h>
#include "Version.h"
#include "Typedef.h"
#include "Define.h"
#include "SFR_Macro.h"
#include "Common.h"
#include "Delay.h"

/*
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
//
//<e0> System Clock Source Configuration
// <o1> System Clock Source Selection
//      <0=> 2~16   MHz  XTAL (HXT)
//      <1=> 32.768 kHz  XTAL (LXT)
//      <2=> 11.059 MHz  Internal (HIRC)
//</e>
//
//<e2> Clock Divider Configuration
//     <o3.0..7>  System Clock Source Devider  <1-255:1>
//                     <i> Fsys = (System Clock Source) / (2 * Devider)
//</e>
//
// <o4> Port0 Mode Selection (P0[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o5> Port1 Mode Selection (P1[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o6> Port2 Mode Selection (P2[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o7> Port3 Mode Selection (P3[5:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o8> Port4 Mode Selection (P4[6:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o9> Port5 Mode Selection (P5[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//-------- <<< end of configuration section >>> ------------------------------
*/


#include <absacc.h>  

#define SYS_CLK_EN      1
#define SYS_SEL         2
#define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
#define SYS_DIV         1

#define PORT0_MODE      2
#define PORT1_MODE      2
#define PORT2_MODE      2
#define PORT3_MODE      2
#define PORT4_MODE      2
#define PORT5_MODE      2

#define COM0    0x01
#define COM1    0x02
#define COM2    0x04
#define COM3    0x08

bit BIT_TMP;

void Show_Pattern_In_LCD(void)
{
    //--------------------------------------
   
    //show "nuvoTon"
    LCDSEG3 |= SET_BIT3;                    //MCU's SEG27 enable
    LCDPTR  = 27;                           //MCU's SEG27 -- LCD's SEG37
    LCDDAT  = COM0;                         //LCD's COM0
   
    //--------------------------------------
   
    //show "N" -- 1'st 13seg Display
    LCDSEG0 |= SET_BIT0;                    //MCU's SEG0 enable
    LCDPTR  = 0;                            //MCU's SEG0 -- LCD's SEG1
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
   
    LCDSEG0 |= SET_BIT1;                    //MCU's SEG1 enable
    LCDPTR  = 1;                            //MCU's SEG1 -- LCD's SEG2
    LCDDAT  = COM0;                         //LCD's COM0
   
    LCDSEG3 |= SET_BIT4;                    //MCU's SEG28 enable
    LCDPTR  = 28;                           //MCU's SEG1 -- LCD's SEG43
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2
   
    LCDSEG3 |= SET_BIT7;                    //MCU's SEG31 enable
    LCDPTR  = 31;                           //MCU's SEG1 -- LCD's SEG44
    LCDDAT  = COM3;                         //LCD's COM3
   
    //--------------------------------------
   
    //show "7" -- 2'nd 13seg Display
    LCDSEG0 |= SET_BIT4;                    //MCU's SEG4 enable
    LCDPTR  = 4;                            //MCU's SEG4 -- LCD's SEG5
    LCDDAT  = (COM1 + COM2 + COM3);         //LCD's COM1/2/3
   
    LCDSEG0 |= SET_BIT2;                    //MCU's SEG2 enable
    LCDPTR  = 2;                            //MCU's SEG2 -- LCD's SEG3
    LCDDAT  = COM2;                         //LCD's COM2

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

    LCDSEG0 |= SET_BIT7;                    //MCU's SEG7 enable
    LCDPTR  = 7;                            //MCU's SEG7 -- LCD's SEG8
    LCDDAT  = COM2;                         //LCD's COM2  
   
    LCDSEG1 |= SET_BIT0;                    //MCU's SEG8 enable
    LCDPTR  = 8;                            //MCU's SEG8 -- LCD's SEG9
    LCDDAT  = (COM0 + COM1 + COM3);         //LCD's COM0/1/3
   
    LCDSEG1 |= SET_BIT1;                    //MCU's SEG9 enable
    LCDPTR  = 9;                            //MCU's SEG9 -- LCD's SEG10
    LCDDAT  = COM1;                         //LCD's COM1
   
    //--------------------------------------
   
    //show "E" -- 4'th 13seg Display
    LCDSEG1 |= SET_BIT2;                    //MCU's SEG10 enable
    LCDPTR  = 10;                           //MCU's SEG10 -- LCD's SEG11
    LCDDAT  = (COM1 + COM2);                //LCD's COM1/2   

    LCDSEG1 |= SET_BIT3;                    //MCU's SEG11 enable
    LCDPTR  = 11;                           //MCU's SEG11 -- LCD's SEG12
    LCDDAT  = COM2;                         //LCD's COM2  
   
    LCDSEG1 |= SET_BIT4;                    //MCU's SEG12 enable
    LCDPTR  = 12;                           //MCU's SEG12 -- LCD's SEG13
    LCDDAT  = (COM0 + COM3);                //LCD's COM0/3
   
    LCDSEG1 |= SET_BIT5;                    //MCU's SEG13 enable
    LCDPTR  = 13;                           //MCU's SEG13 -- LCD's SEG14
    LCDDAT  = COM1;                         //LCD's COM1   

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

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

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

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

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

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

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

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

    LCDSEG3 |= SET_BIT1;                    //MCU's SEG25 enable
    LCDPTR  = 25;                           //MCU's SEG25 -- LCD's SEG26
    LCDDAT  = COM1;                         //LCD's COM1      
   
    //--------------------------------------
   
    //show "Welcome"
    LCDSEG2 |= SET_BIT6;                    //MCU's SEG22 enable
    LCDPTR  = 22;                           //MCU's SEG22 -- LCD's SEG23
    LCDDAT  |= COM3;                         //LCD's COM03
}
//-----------------------------------------------------------------------------------
void LCD_Initial(void)
{
    Set_All_GPIO_Input_Mode();

    //step1: enable clock source
    clr_EXTEN1;
    set_EXTEN0;
   
    //step2: check ready
    while((CKSWT&SET_BIT6)==0);

   
    LCDCON = 0x40;      //;VLCD = 0.9VDD (VDD = 3.3V, VLCD = 3.0V)
                        //;1/4 duty, 1/3 bias, 150kO resistor ladder
   
    LCDCLK = 0x13;      //;Select LXT as LCD clock source
    LCDCON |= SET_BIT7;  //LCDEN = 1
}
//------------------------------------------------
void LCD_Blank(void)
{
    LCDSEG0 = 0x00;
    LCDSEG1 = 0x00;
    LCDSEG2 = 0x00;
    LCDSEG3 = 0x00;
}   
/*------------------------------------------------
The main C function.  Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void)
{
    /* Note
       MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
    */

#if 0   
    Set_All_GPIO_Quasi_Mode();   

    #if DEBUG_PORT == 0
        InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
    #elif DEBUG_PORT == 1
        InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
    #endif
    Show_FW_Version_Number_To_PC();
   
    printf ("\n*===================================================================");
    printf ("\n*  Name: N76E616 LCD Demo Code.");
    printf ("\n*===================================================================\n");
#endif
   
    LCD_Initial();

    /* Change system closk source */
    #if SYS_CLK_EN == 1
        #if   SYS_SEL == 0
            System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
        #elif SYS_SEL == 1
            System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
        #elif SYS_SEL == 2
            System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
        #endif
    #endif

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

  #if 0
    Set_All_GPIO_Quasi_Mode();
  #else
    #if   PORT0_MODE == 0                   //Quasi-Bidirectional
        P0M1 = 0x00;
        P0M2 = 0x00;
    #elif PORT0_MODE == 1                   //Push-Pull
        P0M1 = 0x00;
        P0M2 = 0xFF;
    #elif PORT0_MODE == 2                   //Input-Only
        P0M1 = 0xFF;
        P0M2 = 0x00;
    #elif PORT0_MODE == 3                   //Open-Drain
        P0M1 = 0xFF;
        P0M2 = 0xFF;
    #endif

    #if   PORT1_MODE == 0                   //Quasi-Bidirectional
        P1M1 = 0x00;
        P1M2 = 0x00;
    #elif PORT1_MODE == 1                   //Push-Pull
        P1M1 = 0x00;
        P1M2 = 0xFF;
    #elif PORT1_MODE == 2                   //Input-Only
        P1M1 = 0xFF;
        P1M2 = 0x00;
    #elif PORT1_MODE == 3                   //Open-Drain
        P1M1 = 0xFF;
        P1M2 = 0xFF;
    #endif

    #if   PORT2_MODE == 0                   //Quasi-Bidirectional
        P2M1 = 0x00;
        P2M2 = 0x00;
    #elif PORT2_MODE == 1                   //Push-Pull
        P2M1 = 0x00;
        P2M2 = 0xFF;
    #elif PORT2_MODE == 2                   //Input-Only
        P2M1 = 0xFF;
        P2M2 = 0x00;
    #elif PORT2_MODE == 3                   //Open-Drain
        P2M1 = 0xFF;
        P2M2 = 0xFF;
    #endif

    #if   PORT3_MODE == 0                   //Quasi-Bidirectional
        P3M1 = 0x00;
        P3M2 = 0x00;
    #elif PORT3_MODE == 1                   //Push-Pull
        P3M1 = 0x00;
        P3M2 = 0x7F;
    #elif PORT3_MODE == 2                   //Input-Only
        P3M1 = 0x7F;
        P3M2 = 0x00;
    #elif PORT3_MODE == 3                   //Open-Drain
        P3M1 = 0x7F;
        P3M2 = 0x7F;
    #endif

    #if   PORT4_MODE == 0                   //Quasi-Bidirectional
        P4M1 = 0x00;
        P4M2 = 0x00;
    #elif PORT4_MODE == 1                   //Push-Pull
        P4M1 = 0x00;
        P4M2 = 0x7F;
    #elif PORT4_MODE == 2                   //Input-Only
        P4M1 = 0x7F;
        P4M2 = 0x00;
    #elif PORT4_MODE == 3                   //Open-Drain
        P4M1 = 0x7F;
        P4M2 = 0x7F;
    #endif

    #if   PORT5_MODE == 0                   //Quasi-Bidirectional
        P5M1 = 0x00;
        P5M2 = 0x00;
    #elif PORT5_MODE == 1                   //Push-Pull
        P5M1 = 0x00;
        P5M2 = 0xFF;
    #elif PORT5_MODE == 2                   //Input-Only
        P5M1 = 0xFF;
        P5M2 = 0x00;
    #elif PORT5_MODE == 3                   //Open-Drain
        P5M1 = 0xFF;
        P5M2 = 0xFF;
    #endif
  #endif

    while(1)
    {
        Show_Pattern_In_LCD();
        Timer0_Delay1ms(500);
        LCD_Blank();
        Timer0_Delay1ms(500);
    }
}

使用特权

评论回复
小灵通2018|  楼主 | 2018-11-6 18:31 | 显示全部楼层
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

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

//***********************************************************************************************************
//  File Function: N76E616 LCD Display Temperature Demo Code
//***********************************************************************************************************

#include <stdio.h>
#include <N76E616.h>
#include "Version.h"
#include "Typedef.h"
#include "Define.h"
#include "SFR_Macro.h"
#include "Common.h"
#include "Delay.h"
#include "Display.h"

#define SCL            P06
#define SDA            P05

#define TMP421_Addr     0x98
#define LT_PTR          0x00
#define STATUS_PTR      0x08
#define CR1_PTR         0x09
#define CR2_PTR         0x0A
#define ONE_SHOT_PTR    0x0F
#define SWRST_PTR       0xFC
#define MID_PTR         0xFE
#define DID_PTR         0xFF
#define TMP421_Addr     0x98


//Global variables
volatile unsigned char LED_phase = 0;
volatile float temperature;
volatile bit I2C_error = 0;
volatile bit TMP421_error = 0;

volatile unsigned char temp = 0;

bit  bdata I2C_Ack;   //??????

/*
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
//
//<e0> System Clock Source Configuration
// <o1> System Clock Source Selection
//      <0=> 2~16   MHz  XTAL (HXT)
//      <1=> 32.768 kHz  XTAL (LXT)
//      <2=> 11.059 MHz  Internal (HIRC)
//</e>
//
//<e2> Clock Divider Configuration
//     <o3.0..7>  System Clock Source Devider  <1-255:1>
//                     <i> Fsys = (System Clock Source) / (2 * Devider)
//</e>
//
// <o4> Port0 Mode Selection (P0[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o5> Port1 Mode Selection (P1[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o6> Port2 Mode Selection (P2[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o7> Port3 Mode Selection (P3[5:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o8> Port4 Mode Selection (P4[6:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//
// <o9> Port5 Mode Selection (P5[7:0])
//      <0=> Quasi-Bidirectional
//      <1=> Push-Pull
//      <2=> Input-Only (high-impedance)
//      <3=> Open-Drain
//-------- <<< end of configuration section >>> ------------------------------
*/


#include <absacc.h>  

#define SYS_CLK_EN      1
#define SYS_SEL         2
#define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
#define SYS_DIV         1

#define PORT0_MODE      2
#define PORT1_MODE      2
#define PORT2_MODE      2
#define PORT3_MODE      2
#define PORT4_MODE      2
#define PORT5_MODE      2

bit BIT_TMP;

//------------------------------------------------
void Init_I2C(void)
{
    P0M1 |= 0x60;                               //Configure SDA(P05) and SCL(P06) pins open-drain
    P0M2 |= 0x60;   
}
//------------------------------------------------
void I2C_Start()
{
        SDA = 1;     
    _nop_();
        SCL = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
        SDA = 0;     
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
        SCL = 0;     
    _nop_();
    _nop_();
}
//------------------------------------------------
void I2C_Stop()
{
        SDA = 0;     
    _nop_();
        SCL = 1;     
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
        SDA = 1;     
    _nop_();
    _nop_();
    _nop_();
    _nop_();
}
//------------------------------------------------
bit I2C_CheckAck(void)
{
        UINT8 errtime = 255;   
        SDA = 1;
    _nop_();
    _nop_();
    _nop_();
        SCL = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
        while(SDA)
        {
                errtime--;
                if(errtime==0)
                {
                        I2C_Stop();
                        return(0);
                }
        }
        SCL = 0;
    _nop_();
        return(1);
}
//------------------------------------------------
void I2C_SendB(UINT8 c)
{
        UINT8 BitCnt;
        for (BitCnt=0; BitCnt<8; BitCnt++)  
        {
                if((c<<BitCnt)&0x80)   
                {
                        SDA = 1;
                }
                else
                {
                        SDA = 0;
                }
        _nop_();
        _nop_();
                SCL = 1;      
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        _nop_();
                SCL = 0;
        }
    _nop_();
    _nop_();
        I2C_Ack = I2C_CheckAck();   
    _nop_();
    _nop_();
}
//------------------------------------------------
UINT8 I2C_RcvB()
{
        UINT8 retc;
        UINT8 BitCnt;        
        retc = 0;
        SDA = 1;         
        for(BitCnt=0;BitCnt<8;BitCnt++)
        {
        _nop_();
                SCL = 0;        
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        _nop_();
                SCL = 1;        
        _nop_();
        _nop_();
                retc = retc<<1;
                if(SDA==1)
                {
                        retc = retc + 1;     
                }
        _nop_();
        _nop_();
        }
        SCL = 0;
    _nop_();
    _nop_();
        return(retc);
}
//------------------------------------------------
void I2C_Ackn(bit a)
{
        if(a==0)     
        {
                SDA = 0;
        }
        else
        {
                SDA = 1;
        }
    _nop_();
    _nop_();
    _nop_();
        SCL = 1;
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
        SCL = 0;     
    _nop_();
    _nop_();
}
//------------------------------------------------
unsigned char TMP421_reg_write(unsigned char u8AddrByte, unsigned char u8PtrRegByte, unsigned char u8DataByte)
{
        I2C_Start();   
        I2C_SendB(u8AddrByte);   
        if(!I2C_Ack)
        {
                return(0);
        }
        I2C_SendB(u8PtrRegByte);   
        if(!I2C_Ack)
        {
                return(0);
        }
        I2C_SendB(u8DataByte);   
        if(!I2C_Ack)
        {
                return(0);
        }
        I2C_Stop();     
        return(1);
}
//------------------------------------------------
unsigned char TMP421_reg_read(unsigned char u8AddrByte, unsigned char u8PtrRegByte)
{
        unsigned char u8RtnValue=0;
   
    I2C_Start();     
        I2C_SendB(u8AddrByte);
        if(!I2C_Ack)
        {
                return(0);
        }
        I2C_SendB(u8PtrRegByte);   
        if(!I2C_Ack)
        {
                return(0);
        }
        I2C_Start();     
        I2C_SendB(u8AddrByte+1);   
        if(!I2C_Ack)
        {
                return(0);
        }
        u8RtnValue = I2C_RcvB();   
        I2C_Ackn(1);     
        I2C_Stop();
        return(u8RtnValue);
}
//------------------------------------------------
unsigned char Read_Temperature(unsigned char u8AddrByte, unsigned char u8PtrRegByte)
{
    unsigned char u8ReadHiByte, u8ReadLoByte;

    TMP421_reg_write(TMP421_Addr, ONE_SHOT_PTR, 0xFF);   //One-shot conversion
   
    do
    {
        I2C_error = 0;
        
        I2C_Start();     
        I2C_SendB(u8AddrByte);
        if(!I2C_Ack)
        {
            return(0);
        }
        I2C_SendB(u8PtrRegByte);   
        if(!I2C_Ack)
        {
            return(0);
        }
        I2C_Start();     
        I2C_SendB(u8AddrByte+1);   
        if(!I2C_Ack)
        {
            return(0);
        }
        u8ReadHiByte = I2C_RcvB();   
        I2C_Ackn(0);     
        
        u8ReadLoByte = I2C_RcvB()>>4;   
//        I2C_Ackn(1);         
        I2C_Stop();
        
        //Calculate temperature degree
        temperature = (float)((signed int)(u8ReadHiByte - 64) + 0.0625 * u8ReadLoByte);
        
    }while(I2C_error);
   
    return(1);

}
//------------------------------------------------
void Init_TMP421(void)
{
    unsigned char MID, DID, i, status;

#if 1   
    MID = TMP421_reg_read(TMP421_Addr, MID_PTR);
    if(MID != 0x55)
    {
        P02=0;
        while(1);
    }
    else
        P03=0;
   
    DID = TMP421_reg_read(TMP421_Addr, DID_PTR);
    if(DID != 0x21)
    {
        P02=0;
        while(1);
    }
    else
        P03=0;

#endif

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


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

        do                                      //Polling BUSY
        {
            status = TMP421_reg_read(TMP421_Addr, STATUS_PTR);
        } while (status != 0x00);
    }
}
//------------------------------------------------

/*------------------------------------------------
The main C function.  Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void)
{
    /* Note
       MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
    */
    signed int tmp;

#if 0
    Set_All_GPIO_Quasi_Mode();   
   
    #if DEBUG_PORT == 0
        InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
    #elif DEBUG_PORT == 1
        InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
    #endif
    Show_FW_Version_Number_To_PC();
   
    printf ("\n*===================================================================");
    printf ("\n*  Name: N76E616 LCD Display Temperature Demo Code.");
    printf ("\n*===================================================================\n");
#endif
       
    /* Change system closk source */
    #if SYS_CLK_EN == 1
        #if   SYS_SEL == 0
            System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
        #elif SYS_SEL == 1
            System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
        #elif SYS_SEL == 2
            System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
        #endif
    #endif

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

  #if 0
    Set_All_GPIO_Quasi_Mode();
  #else
    #if   PORT0_MODE == 0                   //Quasi-Bidirectional
        P0M1 = 0x00;
        P0M2 = 0x00;
    #elif PORT0_MODE == 1                   //Push-Pull
        P0M1 = 0x00;
        P0M2 = 0xFF;
    #elif PORT0_MODE == 2                   //Input-Only
        P0M1 = 0xFF;
        P0M2 = 0x00;
    #elif PORT0_MODE == 3                   //Open-Drain
        P0M1 = 0xFF;
        P0M2 = 0xFF;
    #endif

    #if   PORT1_MODE == 0                   //Quasi-Bidirectional
        P1M1 = 0x00;
        P1M2 = 0x00;
    #elif PORT1_MODE == 1                   //Push-Pull
        P1M1 = 0x00;
        P1M2 = 0xFF;
    #elif PORT1_MODE == 2                   //Input-Only
        P1M1 = 0xFF;
        P1M2 = 0x00;
    #elif PORT1_MODE == 3                   //Open-Drain
        P1M1 = 0xFF;
        P1M2 = 0xFF;
    #endif

    #if   PORT2_MODE == 0                   //Quasi-Bidirectional
        P2M1 = 0x00;
        P2M2 = 0x00;
    #elif PORT2_MODE == 1                   //Push-Pull
        P2M1 = 0x00;
        P2M2 = 0xFF;
    #elif PORT2_MODE == 2                   //Input-Only
        P2M1 = 0xFF;
        P2M2 = 0x00;
    #elif PORT2_MODE == 3                   //Open-Drain
        P2M1 = 0xFF;
        P2M2 = 0xFF;
    #endif

    #if   PORT3_MODE == 0                   //Quasi-Bidirectional
        P3M1 = 0x00;
        P3M2 = 0x00;
    #elif PORT3_MODE == 1                   //Push-Pull
        P3M1 = 0x00;
        P3M2 = 0x7F;
    #elif PORT3_MODE == 2                   //Input-Only
        P3M1 = 0x7F;
        P3M2 = 0x00;
    #elif PORT3_MODE == 3                   //Open-Drain
        P3M1 = 0x7F;
        P3M2 = 0x7F;
    #endif

    #if   PORT4_MODE == 0                   //Quasi-Bidirectional
        P4M1 = 0x00;
        P4M2 = 0x00;
    #elif PORT4_MODE == 1                   //Push-Pull
        P4M1 = 0x00;
        P4M2 = 0x7F;
    #elif PORT4_MODE == 2                   //Input-Only
        P4M1 = 0x7F;
        P4M2 = 0x00;
    #elif PORT4_MODE == 3                   //Open-Drain
        P4M1 = 0x7F;
        P4M2 = 0x7F;
    #endif

    #if   PORT5_MODE == 0                   //Quasi-Bidirectional
        P5M1 = 0x00;
        P5M2 = 0x00;
    #elif PORT5_MODE == 1                   //Push-Pull
        P5M1 = 0x00;
        P5M2 = 0xFF;
    #elif PORT5_MODE == 2                   //Input-Only
        P5M1 = 0xFF;
        P5M2 = 0x00;
    #elif PORT5_MODE == 3                   //Open-Drain
        P5M1 = 0xFF;
        P5M2 = 0xFF;
    #endif
  #endif

    LCD_Initial();

    LCD_Try_Run();

    LCD_Display_All_Clear();
    LCD_Display_N76E616_Pattern();
    LCD_Display_Welcome_Pattern();
    Timer0_Delay1ms(1000);
   
    Init_I2C();                               //Initialize I2C
    Init_TMP421();                            //Initialize temperature sensor by I2C commands

    while(1)
    {
        Read_Temperature(TMP421_Addr, LT_PTR);
        tmp = (signed int)(temperature*10);
        
        LCD_Display_All_Clear();

        LCD_Display_Num_2(tmp/100);
        LCD_Display_Num_3(tmp%100/10);
        LCD_Display_Num_4(tmp%100%10);
        
        LCD_Display_3DP();
        LCD_Display_Degree();

        LCD_Display_nuvoTon_**();
        LCD_Display_Welcome_Pattern();

        Timer0_Delay1ms(500);
    }
}

使用特权

评论回复
幸福小强| | 2018-11-6 20:20 | 显示全部楼层
是不是130的那个板子带LCD

使用特权

评论回复
小明的同学| | 2018-11-6 22:35 | 显示全部楼层
没看懂。

使用特权

评论回复
天灵灵地灵灵| | 2018-11-7 13:30 | 显示全部楼层
51内核带LCD的芯片还不多,谢谢分享。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

116

主题

1441

帖子

4

粉丝