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

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file lcdtest.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example used to test LCD on IAR-LPC1768-KS board
frank26080115 0:bf7b9fba3924 4 * @version 3.0
frank26080115 0:bf7b9fba3924 5 * @date 18. June. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "drv_glcd.h"
frank26080115 0:bf7b9fba3924 20 #include "glcd_ll.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_nvic.h"
frank26080115 0:bf7b9fba3924 22 #include "core_cm3.h"
frank26080115 0:bf7b9fba3924 23 #include "lpc17xx_clkpwr.h"
frank26080115 0:bf7b9fba3924 24 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 25 #include "NXP_logo.h"
frank26080115 0:bf7b9fba3924 26 #include "lpc17xx_timer.h"
frank26080115 0:bf7b9fba3924 27 #include "lpc17xx_adc.h"
frank26080115 0:bf7b9fba3924 28 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 29 #include "lpc17xx_gpio.h"
frank26080115 0:bf7b9fba3924 30
frank26080115 0:bf7b9fba3924 31 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 32 /** @defgroup LCD_NOKIA6610_LCD NOKIA6610_LCD
frank26080115 0:bf7b9fba3924 33 * @ingroup LCD_Examples
frank26080115 0:bf7b9fba3924 34 * @{
frank26080115 0:bf7b9fba3924 35 */
frank26080115 0:bf7b9fba3924 36
frank26080115 0:bf7b9fba3924 37 /************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 38 #define TIMER0_TICK_PER_SEC 20
frank26080115 0:bf7b9fba3924 39
frank26080115 0:bf7b9fba3924 40 /************************** PUBLIC DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 41 extern FontType_t Terminal_6_8_6;
frank26080115 0:bf7b9fba3924 42 extern FontType_t Terminal_9_12_6;
frank26080115 0:bf7b9fba3924 43 extern FontType_t Terminal_18_24_12;
frank26080115 0:bf7b9fba3924 44
frank26080115 0:bf7b9fba3924 45 /************************** PRIVATE DEFINITIONS *************************/
frank26080115 0:bf7b9fba3924 46 volatile Bool CntrSel = FALSE;
frank26080115 0:bf7b9fba3924 47
frank26080115 0:bf7b9fba3924 48 /*variable for clitical section entry control*/
frank26080115 0:bf7b9fba3924 49 uint32_t CriticalSecCntr;
frank26080115 0:bf7b9fba3924 50
frank26080115 0:bf7b9fba3924 51 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 52 /* Interrupt service routine */
frank26080115 0:bf7b9fba3924 53 void TIMER0_IRQHandler (void);
frank26080115 0:bf7b9fba3924 54
frank26080115 0:bf7b9fba3924 55 void Dly100us(void *arg);
frank26080115 0:bf7b9fba3924 56
frank26080115 0:bf7b9fba3924 57
frank26080115 0:bf7b9fba3924 58 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 59 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 60 * @brief TIMER0 IRQ Handler
frank26080115 0:bf7b9fba3924 61 * @param[in] None
frank26080115 0:bf7b9fba3924 62 * @return None
frank26080115 0:bf7b9fba3924 63 **********************************************************************/
frank26080115 0:bf7b9fba3924 64 void TIMER0_IRQHandler (void)
frank26080115 0:bf7b9fba3924 65 {
frank26080115 0:bf7b9fba3924 66 //check BUT1
frank26080115 0:bf7b9fba3924 67 if(!(GPIO_ReadValue(0)&(1<<23)))
frank26080115 0:bf7b9fba3924 68 {
frank26080115 0:bf7b9fba3924 69 CntrSel = FALSE;
frank26080115 0:bf7b9fba3924 70 }
frank26080115 0:bf7b9fba3924 71 //Check BUT2
frank26080115 0:bf7b9fba3924 72 else if (!(GPIO_ReadValue(2)&(1<<13)))
frank26080115 0:bf7b9fba3924 73 {
frank26080115 0:bf7b9fba3924 74 CntrSel = TRUE;
frank26080115 0:bf7b9fba3924 75 }
frank26080115 0:bf7b9fba3924 76 // clear interrupt
frank26080115 0:bf7b9fba3924 77 TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
frank26080115 0:bf7b9fba3924 78 NVIC_ClearPendingIRQ(TIMER0_IRQn);
frank26080115 0:bf7b9fba3924 79 }
frank26080115 0:bf7b9fba3924 80 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 81 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 82 * @brief Delay 100us
frank26080115 0:bf7b9fba3924 83 * @param[in] void *arg
frank26080115 0:bf7b9fba3924 84 * @return None
frank26080115 0:bf7b9fba3924 85 **********************************************************************/
frank26080115 0:bf7b9fba3924 86 void Dly100us(void *arg)
frank26080115 0:bf7b9fba3924 87 {
frank26080115 0:bf7b9fba3924 88 volatile uint32_t Dly = (uint32_t)arg, Dly100;
frank26080115 0:bf7b9fba3924 89 for(;Dly;Dly--)
frank26080115 0:bf7b9fba3924 90 for(Dly100 = 500; Dly100; Dly100--);
frank26080115 0:bf7b9fba3924 91 }
frank26080115 0:bf7b9fba3924 92
frank26080115 0:bf7b9fba3924 93 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 94 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 95 * @brief c_entry: Main LCD program body
frank26080115 0:bf7b9fba3924 96 * @param[in] None
frank26080115 0:bf7b9fba3924 97 * @return int
frank26080115 0:bf7b9fba3924 98 **********************************************************************/
frank26080115 0:bf7b9fba3924 99 int c_entry(void)
frank26080115 0:bf7b9fba3924 100 {
frank26080115 0:bf7b9fba3924 101 Bool SelHold;
frank26080115 0:bf7b9fba3924 102 uint32_t AdcData, timer_tick;
frank26080115 0:bf7b9fba3924 103 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 104 TIM_TIMERCFG_Type TimerCfg;
frank26080115 0:bf7b9fba3924 105 TIM_MATCHCFG_Type MatchCfg;
frank26080115 0:bf7b9fba3924 106
frank26080115 0:bf7b9fba3924 107 // But 0,1 init
frank26080115 0:bf7b9fba3924 108 GPIO_SetDir(0, (1<<23), 0); //Setting BUT0 (P0.23) as input
frank26080115 0:bf7b9fba3924 109 GPIO_SetDir(2, (1<<13), 0); //Setting BUT1 (P2.13) as input
frank26080115 0:bf7b9fba3924 110
frank26080115 0:bf7b9fba3924 111 /* ADC Pin select
frank26080115 0:bf7b9fba3924 112 * P1.31 as AD0.5
frank26080115 0:bf7b9fba3924 113 */
frank26080115 0:bf7b9fba3924 114 PinCfg.Funcnum = 3;
frank26080115 0:bf7b9fba3924 115 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 116 PinCfg.Pinmode = 2; //Pin has neither pull-up nor pull-down
frank26080115 0:bf7b9fba3924 117 PinCfg.Pinnum = 31;
frank26080115 0:bf7b9fba3924 118 PinCfg.Portnum = 1;
frank26080115 0:bf7b9fba3924 119 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 120
frank26080115 0:bf7b9fba3924 121 // Enable ADC clock
frank26080115 0:bf7b9fba3924 122 CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCAD, ENABLE);
frank26080115 0:bf7b9fba3924 123
frank26080115 0:bf7b9fba3924 124 /* Initialize ADC peripheral */
frank26080115 0:bf7b9fba3924 125 ADC_Init(LPC_ADC, 100000);
frank26080115 0:bf7b9fba3924 126
frank26080115 0:bf7b9fba3924 127 /* Enable ADC channel 5 */
frank26080115 0:bf7b9fba3924 128 ADC_ChannelCmd (LPC_ADC, 5, ENABLE);
frank26080115 0:bf7b9fba3924 129
frank26080115 0:bf7b9fba3924 130 /* Start ADC */
frank26080115 0:bf7b9fba3924 131 ADC_StartCmd(LPC_ADC, ADC_START_NOW);
frank26080115 0:bf7b9fba3924 132
frank26080115 0:bf7b9fba3924 133 /* Initialize TIMER0
frank26080115 0:bf7b9fba3924 134 * Timer channel: TIMER0
frank26080115 0:bf7b9fba3924 135 * Timer mode: every rising PCLK edge
frank26080115 0:bf7b9fba3924 136 * Prescale option: TICKVAL
frank26080115 0:bf7b9fba3924 137 * Prescale value = 0
frank26080115 0:bf7b9fba3924 138 */
frank26080115 0:bf7b9fba3924 139 TimerCfg.PrescaleOption = TIM_PRESCALE_TICKVAL;
frank26080115 0:bf7b9fba3924 140 TimerCfg.PrescaleValue = 0;
frank26080115 0:bf7b9fba3924 141 TIM_Init(LPC_TIM0, TIM_COUNTER_RISING_MODE, &TimerCfg);
frank26080115 0:bf7b9fba3924 142
frank26080115 0:bf7b9fba3924 143 //disable timer counter
frank26080115 0:bf7b9fba3924 144 TIM_Cmd(LPC_TIM0, DISABLE);
frank26080115 0:bf7b9fba3924 145
frank26080115 0:bf7b9fba3924 146 /* Initalize Match MR0
frank26080115 0:bf7b9fba3924 147 * - Enable interrupt
frank26080115 0:bf7b9fba3924 148 * - Enable reset
frank26080115 0:bf7b9fba3924 149 * - Disable stop
frank26080115 0:bf7b9fba3924 150 * - Match value = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_TIMER0)/(TIMER0_TICK_PER_SEC)
frank26080115 0:bf7b9fba3924 151 */
frank26080115 0:bf7b9fba3924 152 timer_tick = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_TIMER0)/(TIMER0_TICK_PER_SEC);
frank26080115 0:bf7b9fba3924 153 MatchCfg.MatchChannel = 0;
frank26080115 0:bf7b9fba3924 154 MatchCfg.IntOnMatch = ENABLE;
frank26080115 0:bf7b9fba3924 155 MatchCfg.ResetOnMatch = ENABLE;
frank26080115 0:bf7b9fba3924 156 MatchCfg.StopOnMatch = DISABLE;
frank26080115 0:bf7b9fba3924 157 MatchCfg.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
frank26080115 0:bf7b9fba3924 158 MatchCfg.MatchValue = timer_tick;
frank26080115 0:bf7b9fba3924 159 TIM_ConfigMatch(LPC_TIM0,&MatchCfg);
frank26080115 0:bf7b9fba3924 160
frank26080115 0:bf7b9fba3924 161 // Clear MR0 interrupt pending
frank26080115 0:bf7b9fba3924 162 TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
frank26080115 0:bf7b9fba3924 163
frank26080115 0:bf7b9fba3924 164 //Enable TIMER0 interrupt
frank26080115 0:bf7b9fba3924 165 NVIC_EnableIRQ(TIMER0_IRQn);
frank26080115 0:bf7b9fba3924 166
frank26080115 0:bf7b9fba3924 167 // Enable TIMER0 counter
frank26080115 0:bf7b9fba3924 168 TIM_Cmd(LPC_TIM0, ENABLE);
frank26080115 0:bf7b9fba3924 169
frank26080115 0:bf7b9fba3924 170 // GLCD init
frank26080115 0:bf7b9fba3924 171 GLCD_PowerUpInit((unsigned char *)NXP_Logo.pPicStream);
frank26080115 0:bf7b9fba3924 172 GLCD_Backlight(BACKLIGHT_ON);
frank26080115 0:bf7b9fba3924 173
frank26080115 0:bf7b9fba3924 174 GLCD_SetFont(&Terminal_9_12_6,0x000F00,0x00FF0);
frank26080115 0:bf7b9fba3924 175 GLCD_SetWindow(10,116,131,131);
frank26080115 0:bf7b9fba3924 176 GLCD_TextSetPos(0,0);
frank26080115 0:bf7b9fba3924 177
frank26080115 0:bf7b9fba3924 178 if(CntrSel)
frank26080115 0:bf7b9fba3924 179 {
frank26080115 0:bf7b9fba3924 180 SelHold = TRUE;
frank26080115 0:bf7b9fba3924 181 GLCD_print("\fContrast adj.\r");
frank26080115 0:bf7b9fba3924 182 }
frank26080115 0:bf7b9fba3924 183 else
frank26080115 0:bf7b9fba3924 184 {
frank26080115 0:bf7b9fba3924 185 SelHold = FALSE;
frank26080115 0:bf7b9fba3924 186 GLCD_print("\fBacklight adj.\r");
frank26080115 0:bf7b9fba3924 187 }
frank26080115 0:bf7b9fba3924 188
frank26080115 0:bf7b9fba3924 189 while(1)
frank26080115 0:bf7b9fba3924 190 {
frank26080115 0:bf7b9fba3924 191 AdcData = ADC_GlobalGetData(LPC_ADC);
frank26080115 0:bf7b9fba3924 192 if(AdcData & (1UL << 31))
frank26080115 0:bf7b9fba3924 193 {
frank26080115 0:bf7b9fba3924 194 //AD0 start conversion
frank26080115 0:bf7b9fba3924 195 ADC_StartCmd(LPC_ADC, ADC_START_NOW);
frank26080115 0:bf7b9fba3924 196 AdcData >>= 10;
frank26080115 0:bf7b9fba3924 197 AdcData &= 0xFF;
frank26080115 0:bf7b9fba3924 198 if(SelHold)
frank26080115 0:bf7b9fba3924 199 {
frank26080115 0:bf7b9fba3924 200 // Contract adj
frank26080115 0:bf7b9fba3924 201 GLCD_SendCmd(SETCON,(unsigned char *)&AdcData,0);
frank26080115 0:bf7b9fba3924 202 }
frank26080115 0:bf7b9fba3924 203 else
frank26080115 0:bf7b9fba3924 204 {
frank26080115 0:bf7b9fba3924 205 // Backlight adj
frank26080115 0:bf7b9fba3924 206 AdcData >>= 1;
frank26080115 0:bf7b9fba3924 207 GLCD_Backlight(AdcData);
frank26080115 0:bf7b9fba3924 208 }
frank26080115 0:bf7b9fba3924 209 }
frank26080115 0:bf7b9fba3924 210 if(SelHold != CntrSel)
frank26080115 0:bf7b9fba3924 211 {
frank26080115 0:bf7b9fba3924 212 SelHold ^= 1;
frank26080115 0:bf7b9fba3924 213 if(SelHold)
frank26080115 0:bf7b9fba3924 214 {
frank26080115 0:bf7b9fba3924 215 GLCD_print("\fContrast adj.\r");
frank26080115 0:bf7b9fba3924 216 }
frank26080115 0:bf7b9fba3924 217 else
frank26080115 0:bf7b9fba3924 218 {
frank26080115 0:bf7b9fba3924 219 GLCD_print("\fBacklight adj.\r");
frank26080115 0:bf7b9fba3924 220 }
frank26080115 0:bf7b9fba3924 221 }
frank26080115 0:bf7b9fba3924 222 }
frank26080115 0:bf7b9fba3924 223 return 1;
frank26080115 0:bf7b9fba3924 224 }
frank26080115 0:bf7b9fba3924 225
frank26080115 0:bf7b9fba3924 226 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 227 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 228 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 229 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 230 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 231 int main(void)
frank26080115 0:bf7b9fba3924 232 {
frank26080115 0:bf7b9fba3924 233 return c_entry();
frank26080115 0:bf7b9fba3924 234 }
frank26080115 0:bf7b9fba3924 235
frank26080115 0:bf7b9fba3924 236 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 237 /*******************************************************************************
frank26080115 0:bf7b9fba3924 238 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 239 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 240 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 241 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 242 * @return None
frank26080115 0:bf7b9fba3924 243 *******************************************************************************/
frank26080115 0:bf7b9fba3924 244 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 245 {
frank26080115 0:bf7b9fba3924 246 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 247 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 248
frank26080115 0:bf7b9fba3924 249 /* Infinite loop */
frank26080115 0:bf7b9fba3924 250 while(1);
frank26080115 0:bf7b9fba3924 251 }
frank26080115 0:bf7b9fba3924 252 #endif
frank26080115 0:bf7b9fba3924 253
frank26080115 0:bf7b9fba3924 254 /*
frank26080115 0:bf7b9fba3924 255 * @}
frank26080115 0:bf7b9fba3924 256 */