- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2014 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- #include <stdio.h>
- #include "M051Series.h"
- #include "lcd_Driver.h"
- #define PLLCON_SETTING CLK_PLLCON_50MHz_HXT
- #define PLL_CLOCK 50000000
- void SYS_Init(void)
- {
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init System Clock */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Enable Internal RC 22.1184MHz clock */
- CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
- /* Waiting for Internal RC clock ready */
- CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
- /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
- CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
- /* Enable external XTAL 12MHz clock */
- CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
- /* Waiting for external XTAL clock ready */
- CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);
- /* Set core clock as PLL_CLOCK from PLL */
- CLK_SetCoreClock(PLL_CLOCK);
- /* Enable IP clock */
- CLK_EnableModuleClock(UART0_MODULE);
- /* IP clock source */
- CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
- /* Update System Core Clock */
- /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
- //SystemCoreClockUpdate();
- PllClock = PLL_CLOCK; // PLL
- SystemCoreClock = PLL_CLOCK / 1; // HCLK
- CyclesPerUs = PLL_CLOCK / 1000000; // For SYS_SysTickDelay()
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init I/O Multi-function */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Set P3 multi-function pins for UART0 RXD and TXD.*/
- SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0;
- }
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init UART */
- /*---------------------------------------------------------------------------------------------------------*/
- void UART0_Init()
- {
- /* Reset IP */
- SYS_ResetModule(UART0_RST);
- /* Configure UART0 and set UART0 Baudrate */
- UART_Open(UART0, 115200);
- }
- /*---------------------------------------------------------------------------------------------------------*/
- /* MAIN function */
- /*---------------------------------------------------------------------------------------------------------*/
- int main(void)
- {
- /* Unlock protected registers */
- SYS_UnlockReg();
- /* Init System, IP clock and multi-function I/O */
- SYS_Init();
- /* Lock protected registers */
- SYS_LockReg();
- /* Init UART0 for printf */
- UART0_Init();
- printf("LCD demo start.\n");
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init LCD */
- /*---------------------------------------------------------------------------------------------------------*/
- LCD_Init();
- LCD_EnableBackLight();
- LCD_ClearScreen();
- LCD_Print(0, "This is LCD demo");
- ShowChar(1, 4, 'N');
- ShowChar(1, 5, 'u');
- ShowChar(1, 6, 'v');
- ShowChar(1, 7, 'o');
- ShowChar(1, 8, 't');
- ShowChar(1, 9, 'o');
- ShowChar(1, 10, 'n');
- ShowCharCH(2, 2, 0); //in the third row and third column of LCD show '新'
- ShowCharCH(2, 3, 1); //in the third row and fourth column of LCD show '唐'
- ShowCharCH(2, 4, 2); //in the third row and fifth column of LCD show '电'
- ShowCharCH(2, 5, 3); //in the third row and sexth column of LCD show '子'
- while (1);
- }
|