These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lcdtest.c Source File

lcdtest.c

00001 /***********************************************************************//**
00002  * @file        lcdtest.c
00003  * @purpose     This example used to test LCD on IAR-LPC1768-KS board
00004  * @version     3.0
00005  * @date        18. June. 2010
00006  * @author      NXP MCU SW Application Team
00007  *---------------------------------------------------------------------
00008  * Software that is described herein is for illustrative purposes only
00009  * which provides customers with programming information regarding the
00010  * products. This software is supplied "AS IS" without any warranties.
00011  * NXP Semiconductors assumes no responsibility or liability for the
00012  * use of the software, conveys no license or title under any patent,
00013  * copyright, or mask work right to the product. NXP Semiconductors
00014  * reserves the right to make changes in the software without
00015  * notification. NXP Semiconductors also make no representation or
00016  * warranty that such application will be suitable for the specified
00017  * use without further testing or modification.
00018  **********************************************************************/
00019 #include "drv_glcd.h"
00020 #include "glcd_ll.h"
00021 #include "lpc17xx_nvic.h"
00022 #include "core_cm3.h"
00023 #include "lpc17xx_clkpwr.h"
00024 #include "lpc17xx_libcfg.h"
00025 #include "NXP_logo.h"
00026 #include "lpc17xx_timer.h"
00027 #include "lpc17xx_adc.h"
00028 #include "lpc17xx_pinsel.h"
00029 #include "lpc17xx_gpio.h"
00030 
00031 /* Example group ----------------------------------------------------------- */
00032 /** @defgroup LCD_NOKIA6610_LCD NOKIA6610_LCD
00033  * @ingroup LCD_Examples
00034  * @{
00035  */
00036 
00037 /************************** PRIVATE DEFINITIONS *************************/
00038 #define TIMER0_TICK_PER_SEC   20
00039 
00040 /************************** PUBLIC DEFINITIONS *************************/
00041 extern FontType_t Terminal_6_8_6;
00042 extern FontType_t Terminal_9_12_6;
00043 extern FontType_t Terminal_18_24_12;
00044 
00045 /************************** PRIVATE DEFINITIONS *************************/
00046 volatile Bool CntrSel = FALSE;
00047 
00048 /*variable for clitical section entry control*/
00049 uint32_t CriticalSecCntr;
00050 
00051 /************************** PRIVATE FUNCTIONS *************************/
00052 /* Interrupt service routine */
00053 void TIMER0_IRQHandler (void);
00054 
00055 void Dly100us(void *arg);
00056 
00057 
00058 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
00059 /*********************************************************************//**
00060  * @brief       TIMER0 IRQ Handler
00061  * @param[in]   None
00062  * @return      None
00063  **********************************************************************/
00064 void TIMER0_IRQHandler (void)
00065 {
00066     //check BUT1
00067     if(!(GPIO_ReadValue(0)&(1<<23)))
00068     {
00069         CntrSel = FALSE;
00070     }
00071     //Check BUT2
00072     else if (!(GPIO_ReadValue(2)&(1<<13)))
00073     {
00074         CntrSel = TRUE;
00075     }
00076   // clear interrupt
00077     TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
00078     NVIC_ClearPendingIRQ(TIMER0_IRQn);
00079 }
00080 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
00081 /*********************************************************************//**
00082  * @brief       Delay 100us
00083  * @param[in]   void *arg
00084  * @return      None
00085  **********************************************************************/
00086 void Dly100us(void *arg)
00087 {
00088     volatile uint32_t Dly = (uint32_t)arg, Dly100;
00089     for(;Dly;Dly--)
00090     for(Dly100 = 500; Dly100; Dly100--);
00091 }
00092 
00093 /*-------------------------MAIN FUNCTION------------------------------*/
00094 /*********************************************************************//**
00095  * @brief       c_entry: Main LCD program body
00096  * @param[in]   None
00097  * @return      int
00098  **********************************************************************/
00099 int c_entry(void)
00100 {
00101     Bool SelHold;
00102     uint32_t AdcData, timer_tick;
00103     PINSEL_CFG_Type PinCfg;
00104     TIM_TIMERCFG_Type TimerCfg;
00105     TIM_MATCHCFG_Type MatchCfg;
00106 
00107     // But 0,1 init
00108     GPIO_SetDir(0, (1<<23), 0); //Setting BUT0 (P0.23) as input
00109     GPIO_SetDir(2, (1<<13), 0); //Setting BUT1 (P2.13) as input
00110 
00111     /* ADC Pin select
00112      * P1.31 as AD0.5
00113      */
00114     PinCfg.Funcnum = 3;
00115     PinCfg.OpenDrain = 0;
00116     PinCfg.Pinmode = 2; //Pin has neither pull-up nor pull-down
00117     PinCfg.Pinnum = 31;
00118     PinCfg.Portnum = 1;
00119     PINSEL_ConfigPin(&PinCfg);
00120 
00121     // Enable ADC clock
00122     CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCAD, ENABLE);
00123 
00124     /* Initialize ADC peripheral */
00125     ADC_Init(LPC_ADC, 100000);
00126 
00127     /* Enable ADC channel 5 */
00128     ADC_ChannelCmd (LPC_ADC, 5, ENABLE);
00129 
00130     /* Start ADC */
00131     ADC_StartCmd(LPC_ADC, ADC_START_NOW);
00132 
00133     /* Initialize TIMER0
00134      * Timer channel: TIMER0
00135      * Timer mode: every rising PCLK edge
00136      * Prescale option: TICKVAL
00137      * Prescale value = 0
00138      */
00139     TimerCfg.PrescaleOption = TIM_PRESCALE_TICKVAL;
00140     TimerCfg.PrescaleValue = 0;
00141     TIM_Init(LPC_TIM0, TIM_COUNTER_RISING_MODE, &TimerCfg);
00142 
00143     //disable timer counter
00144     TIM_Cmd(LPC_TIM0, DISABLE);
00145 
00146     /* Initalize Match MR0
00147      * - Enable interrupt
00148      * - Enable reset
00149      * - Disable stop
00150      * - Match value = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_TIMER0)/(TIMER0_TICK_PER_SEC)
00151      */
00152     timer_tick = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_TIMER0)/(TIMER0_TICK_PER_SEC);
00153     MatchCfg.MatchChannel = 0;
00154     MatchCfg.IntOnMatch = ENABLE;
00155     MatchCfg.ResetOnMatch = ENABLE;
00156     MatchCfg.StopOnMatch = DISABLE;
00157     MatchCfg.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
00158     MatchCfg.MatchValue = timer_tick;
00159     TIM_ConfigMatch(LPC_TIM0,&MatchCfg);
00160 
00161     // Clear MR0 interrupt pending
00162     TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
00163 
00164     //Enable TIMER0 interrupt
00165     NVIC_EnableIRQ(TIMER0_IRQn);
00166 
00167     // Enable TIMER0 counter
00168     TIM_Cmd(LPC_TIM0, ENABLE);
00169 
00170     // GLCD init
00171     GLCD_PowerUpInit((unsigned char *)NXP_Logo.pPicStream);
00172     GLCD_Backlight(BACKLIGHT_ON);
00173 
00174     GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
00175     GLCD_SetWindow(10,116,131,131);
00176     GLCD_TextSetPos(0,0);
00177 
00178     if(CntrSel)
00179     {
00180         SelHold = TRUE;
00181         GLCD_print("\fContrast adj.\r");
00182     }
00183     else
00184     {
00185         SelHold = FALSE;
00186         GLCD_print("\fBacklight adj.\r");
00187     }
00188 
00189     while(1)
00190     {
00191         AdcData = ADC_GlobalGetData(LPC_ADC);
00192         if(AdcData & (1UL << 31))
00193         {
00194             //AD0 start conversion
00195             ADC_StartCmd(LPC_ADC, ADC_START_NOW);
00196             AdcData >>= 10;
00197             AdcData  &= 0xFF;
00198             if(SelHold)
00199             {
00200                 // Contract adj
00201                 GLCD_SendCmd(SETCON,(unsigned char *)&AdcData,0);
00202             }
00203             else
00204             {
00205                 // Backlight adj
00206                 AdcData >>= 1;
00207                 GLCD_Backlight(AdcData);
00208             }
00209         }
00210         if(SelHold != CntrSel)
00211         {
00212             SelHold ^= 1;
00213             if(SelHold)
00214             {
00215                 GLCD_print("\fContrast adj.\r");
00216             }
00217             else
00218             {
00219                 GLCD_print("\fBacklight adj.\r");
00220             }
00221         }
00222     }
00223     return 1;
00224 }
00225 
00226 /* With ARM and GHS toolsets, the entry point is main() - this will
00227    allow the linker to generate wrapper code to setup stacks, allocate
00228    heap area, and initialize and copy code and data segments. For GNU
00229    toolsets, the entry point is through __start() in the crt0_gnu.asm
00230    file, and that startup code will setup stacks and data */
00231 int main(void)
00232 {
00233     return c_entry();
00234 }
00235 
00236 #ifdef  DEBUG
00237 /*******************************************************************************
00238 * @brief        Reports the name of the source file and the source line number
00239 *               where the CHECK_PARAM error has occurred.
00240 * @param[in]    file Pointer to the source file name
00241 * @param[in]    line assert_param error line source number
00242 * @return       None
00243 *******************************************************************************/
00244 void check_failed(uint8_t *file, uint32_t line)
00245 {
00246     /* User can add his own implementation to report the file name and line number,
00247      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00248 
00249     /* Infinite loop */
00250     while(1);
00251 }
00252 #endif
00253 
00254 /*
00255  * @}
00256  */