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 *
frank26080115 0:bf7b9fba3924 3 *
frank26080115 0:bf7b9fba3924 4 * (c) Copyright IAR Systems 2006
frank26080115 0:bf7b9fba3924 5 *
frank26080115 0:bf7b9fba3924 6 * File name : glcd_ll.c
frank26080115 0:bf7b9fba3924 7 * Description : GLCD low level functions
frank26080115 0:bf7b9fba3924 8 *
frank26080115 0:bf7b9fba3924 9 * History :
frank26080115 0:bf7b9fba3924 10 * 1. Date : December 2, 2006
frank26080115 0:bf7b9fba3924 11 * Author : Stanimir Bonev
frank26080115 0:bf7b9fba3924 12 * Description : Create
frank26080115 0:bf7b9fba3924 13 *
frank26080115 0:bf7b9fba3924 14 * $Revision: 30123 $
frank26080115 0:bf7b9fba3924 15 **************************************************************************/
frank26080115 0:bf7b9fba3924 16 #include "glcd_ll.h"
frank26080115 0:bf7b9fba3924 17 #include "lpc_types.h"
frank26080115 0:bf7b9fba3924 18 #include "LPC17xx.h"
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_clkpwr.h"
frank26080115 0:bf7b9fba3924 20
frank26080115 0:bf7b9fba3924 21 /*************************************************************************
frank26080115 0:bf7b9fba3924 22 * Function Name: GLCD_SetReset
frank26080115 0:bf7b9fba3924 23 * Parameters: Boolean State
frank26080115 0:bf7b9fba3924 24 * Return: none
frank26080115 0:bf7b9fba3924 25 *
frank26080115 0:bf7b9fba3924 26 * Description: Set reset pin state
frank26080115 0:bf7b9fba3924 27 *
frank26080115 0:bf7b9fba3924 28 *************************************************************************/
frank26080115 0:bf7b9fba3924 29 void GLCD_SetReset (Bool State)
frank26080115 0:bf7b9fba3924 30 {
frank26080115 0:bf7b9fba3924 31 if(State)
frank26080115 0:bf7b9fba3924 32 {
frank26080115 0:bf7b9fba3924 33 LPC_GPIO3->FIOSET |= (1UL<<25);
frank26080115 0:bf7b9fba3924 34 }
frank26080115 0:bf7b9fba3924 35 else
frank26080115 0:bf7b9fba3924 36 {
frank26080115 0:bf7b9fba3924 37 LPC_GPIO3->FIOCLR |= (1<<25);
frank26080115 0:bf7b9fba3924 38 }
frank26080115 0:bf7b9fba3924 39 }
frank26080115 0:bf7b9fba3924 40
frank26080115 0:bf7b9fba3924 41 /*************************************************************************
frank26080115 0:bf7b9fba3924 42 * Function Name: GLCD_Backlight
frank26080115 0:bf7b9fba3924 43 * Parameters: Int8U Light
frank26080115 0:bf7b9fba3924 44 * Return: none
frank26080115 0:bf7b9fba3924 45 *
frank26080115 0:bf7b9fba3924 46 * Description: Set backlight pin state
frank26080115 0:bf7b9fba3924 47 *
frank26080115 0:bf7b9fba3924 48 *************************************************************************/
frank26080115 0:bf7b9fba3924 49 void GLCD_Backlight (uint8_t Light)
frank26080115 0:bf7b9fba3924 50 {
frank26080115 0:bf7b9fba3924 51 LPC_PWM1->MR3 = BACKLIGHT_OFF + Light;
frank26080115 0:bf7b9fba3924 52 LPC_PWM1->LER |= (1<<3);
frank26080115 0:bf7b9fba3924 53 }
frank26080115 0:bf7b9fba3924 54
frank26080115 0:bf7b9fba3924 55 /*************************************************************************
frank26080115 0:bf7b9fba3924 56 * Function Name: GLCD_LLInit
frank26080115 0:bf7b9fba3924 57 * Parameters: none
frank26080115 0:bf7b9fba3924 58 * Return: none
frank26080115 0:bf7b9fba3924 59 *
frank26080115 0:bf7b9fba3924 60 * Description: Init Reset and Backlight control outputs
frank26080115 0:bf7b9fba3924 61 *
frank26080115 0:bf7b9fba3924 62 *************************************************************************/
frank26080115 0:bf7b9fba3924 63 void GLCD_LLInit (void)
frank26080115 0:bf7b9fba3924 64 {
frank26080115 0:bf7b9fba3924 65 // LCD Reset output
frank26080115 0:bf7b9fba3924 66 LPC_GPIO3->FIODIR |= (1UL<<25);
frank26080115 0:bf7b9fba3924 67
frank26080115 0:bf7b9fba3924 68 GLCD_SetReset(0);
frank26080115 0:bf7b9fba3924 69
frank26080115 0:bf7b9fba3924 70 // LCD backlight PWM 8bit init
frank26080115 0:bf7b9fba3924 71 LPC_PINCON->PINSEL7 |= (3<<20) ; // assign P3.26 to PWM1.3
frank26080115 0:bf7b9fba3924 72 LPC_SC->PCONP |= (1<<6); // enable clock of PWM1
frank26080115 0:bf7b9fba3924 73 LPC_PWM1->TCR &= ~(1<<3);
frank26080115 0:bf7b9fba3924 74 LPC_PWM1->TCR &= ~(1<<0); // disable counting
frank26080115 0:bf7b9fba3924 75 LPC_PWM1->TCR |= (1<<1); // reset
frank26080115 0:bf7b9fba3924 76 LPC_PWM1->CTCR &= ~(3<<0); // from prescaler
frank26080115 0:bf7b9fba3924 77 LPC_PWM1->MCR = 2 ; // Reset on PWMMR0
frank26080115 0:bf7b9fba3924 78 LPC_PWM1->PCR &= ~(1<<3); // Selects single edge controlled mode for PWM3
frank26080115 0:bf7b9fba3924 79 LPC_PWM1->PCR |= (1<<11); // The PWM3 output enabled
frank26080115 0:bf7b9fba3924 80
frank26080115 0:bf7b9fba3924 81 LPC_PWM1->PR = 0;
frank26080115 0:bf7b9fba3924 82 LPC_PWM1->MR0 = 0xFF; // 8bit resolution
frank26080115 0:bf7b9fba3924 83 LPC_PWM1->LER |= (1<<0);
frank26080115 0:bf7b9fba3924 84 LPC_PWM1->MR3 = 0;
frank26080115 0:bf7b9fba3924 85 LPC_PWM1->LER |= (1<<3);
frank26080115 0:bf7b9fba3924 86 LPC_PWM1->TCR |= (1<<3); // enable PWM function
frank26080115 0:bf7b9fba3924 87 LPC_PWM1->TCR &= ~(1<<1); // release reset
frank26080115 0:bf7b9fba3924 88 LPC_PWM1->TCR |= (1<<0); // enable counting
frank26080115 0:bf7b9fba3924 89 GLCD_Backlight(0);
frank26080115 0:bf7b9fba3924 90 }
frank26080115 0:bf7b9fba3924 91
frank26080115 0:bf7b9fba3924 92 /*************************************************************************
frank26080115 0:bf7b9fba3924 93 * Function Name: GLCD_SPI_ChipSelect
frank26080115 0:bf7b9fba3924 94 * Parameters: Boolean Select
frank26080115 0:bf7b9fba3924 95 * Return: none
frank26080115 0:bf7b9fba3924 96 *
frank26080115 0:bf7b9fba3924 97 * Description: SSP0 Chip select control
frank26080115 0:bf7b9fba3924 98 * Select = true - Chip is enable
frank26080115 0:bf7b9fba3924 99 * Select = false - Chip is disable
frank26080115 0:bf7b9fba3924 100 *
frank26080115 0:bf7b9fba3924 101 *************************************************************************/
frank26080115 0:bf7b9fba3924 102 void GLCD_SPI_ChipSelect (Bool Select)
frank26080115 0:bf7b9fba3924 103 {
frank26080115 0:bf7b9fba3924 104 if (Select)
frank26080115 0:bf7b9fba3924 105 {
frank26080115 0:bf7b9fba3924 106 LPC_GPIO1->FIOCLR |= (1<<21);
frank26080115 0:bf7b9fba3924 107 }
frank26080115 0:bf7b9fba3924 108 else
frank26080115 0:bf7b9fba3924 109 {
frank26080115 0:bf7b9fba3924 110 LPC_GPIO1->FIOSET |= (1UL<<21);
frank26080115 0:bf7b9fba3924 111 }
frank26080115 0:bf7b9fba3924 112 }
frank26080115 0:bf7b9fba3924 113
frank26080115 0:bf7b9fba3924 114 /*************************************************************************
frank26080115 0:bf7b9fba3924 115 * Function Name: GLCD_SPI_SetWordWidth
frank26080115 0:bf7b9fba3924 116 * Parameters: Int32U Width
frank26080115 0:bf7b9fba3924 117 * Return: Boolean
frank26080115 0:bf7b9fba3924 118 *
frank26080115 0:bf7b9fba3924 119 * Description: Set SSP 0 word width
frank26080115 0:bf7b9fba3924 120 *
frank26080115 0:bf7b9fba3924 121 *************************************************************************/
frank26080115 0:bf7b9fba3924 122 Bool GLCD_SPI_SetWordWidth (uint32_t Width)
frank26080115 0:bf7b9fba3924 123 {
frank26080115 0:bf7b9fba3924 124 if(4 > Width || Width > 16)
frank26080115 0:bf7b9fba3924 125 {
frank26080115 0:bf7b9fba3924 126 return(FALSE);
frank26080115 0:bf7b9fba3924 127 }
frank26080115 0:bf7b9fba3924 128
frank26080115 0:bf7b9fba3924 129 LPC_SSP0->CR0 &= ~(0x0F);
frank26080115 0:bf7b9fba3924 130 LPC_SSP0->CR0 |= (Width - 1) & 0x0F;
frank26080115 0:bf7b9fba3924 131 return(TRUE);
frank26080115 0:bf7b9fba3924 132 }
frank26080115 0:bf7b9fba3924 133
frank26080115 0:bf7b9fba3924 134 /*************************************************************************
frank26080115 0:bf7b9fba3924 135 * Function Name: GLCD_SPI_SetClockFreq
frank26080115 0:bf7b9fba3924 136 * Parameters: Int32U Frequency
frank26080115 0:bf7b9fba3924 137 * Return: Int32U
frank26080115 0:bf7b9fba3924 138 *
frank26080115 0:bf7b9fba3924 139 * Description: Set SSP 0 clock
frank26080115 0:bf7b9fba3924 140 *
frank26080115 0:bf7b9fba3924 141 *************************************************************************/
frank26080115 0:bf7b9fba3924 142 uint32_t GLCD_SPI_SetClockFreq (uint32_t Frequency)
frank26080115 0:bf7b9fba3924 143 {
frank26080115 0:bf7b9fba3924 144 uint32_t Fspi = CLKPWR_GetPCLK(CLKPWR_PCLKSEL_SSP0);
frank26080115 0:bf7b9fba3924 145 uint32_t Div = 2;
frank26080115 0:bf7b9fba3924 146 while((Div * Frequency) < Fspi)
frank26080115 0:bf7b9fba3924 147 {
frank26080115 0:bf7b9fba3924 148 if((Div += 2) == 254)
frank26080115 0:bf7b9fba3924 149 {
frank26080115 0:bf7b9fba3924 150 break;
frank26080115 0:bf7b9fba3924 151 }
frank26080115 0:bf7b9fba3924 152 }
frank26080115 0:bf7b9fba3924 153 LPC_SSP0->CPSR = Div;
frank26080115 0:bf7b9fba3924 154 return(Fspi/Div);
frank26080115 0:bf7b9fba3924 155 }
frank26080115 0:bf7b9fba3924 156
frank26080115 0:bf7b9fba3924 157 /*************************************************************************
frank26080115 0:bf7b9fba3924 158 * Function Name: GLCD_SPI_Init
frank26080115 0:bf7b9fba3924 159 * Parameters: uint32_t Clk, uint32_t Width
frank26080115 0:bf7b9fba3924 160 * Return: none
frank26080115 0:bf7b9fba3924 161 *
frank26080115 0:bf7b9fba3924 162 * Description: Init SSP0
frank26080115 0:bf7b9fba3924 163 *
frank26080115 0:bf7b9fba3924 164 *************************************************************************/
frank26080115 0:bf7b9fba3924 165 void GLCD_SPI_Init(uint32_t Clk, uint32_t Width)
frank26080115 0:bf7b9fba3924 166 {
frank26080115 0:bf7b9fba3924 167 uint32_t i;
frank26080115 0:bf7b9fba3924 168 volatile uint32_t Dummy;
frank26080115 0:bf7b9fba3924 169 // Assign GPIO to SSP0 - SCK, MOSI, MISO
frank26080115 0:bf7b9fba3924 170 LPC_PINCON->PINSEL3 |= (3<<8); // SCK0 - P1.20
frank26080115 0:bf7b9fba3924 171 LPC_PINCON->PINSEL3 |= (3<<14); // MISO0 - P1.23
frank26080115 0:bf7b9fba3924 172 LPC_PINCON->PINSEL3 |= (3<<16); // MOSI0 - P1.24
frank26080115 0:bf7b9fba3924 173
frank26080115 0:bf7b9fba3924 174 // Chip select
frank26080115 0:bf7b9fba3924 175 LPC_GPIO1->FIODIR |= (1UL<<21); //SSEL0 used as GPIOP1.21
frank26080115 0:bf7b9fba3924 176
frank26080115 0:bf7b9fba3924 177 GLCD_SPI_ChipSelect(FALSE);
frank26080115 0:bf7b9fba3924 178
frank26080115 0:bf7b9fba3924 179 // Spi init
frank26080115 0:bf7b9fba3924 180 LPC_SC->PCONP |= (1<<21); // SSP0 clock enable
frank26080115 0:bf7b9fba3924 181 LPC_SSP0->CR1 &= ~(1<<1); // Disable module
frank26080115 0:bf7b9fba3924 182 LPC_SSP0->CR1 &= ~(1<<0); // Disable Loop Back Mode
frank26080115 0:bf7b9fba3924 183 LPC_SSP0->CR1 &= ~(1<<2); // Master mode
frank26080115 0:bf7b9fba3924 184 LPC_SSP0->CR0 &= ~(3<<4); // SPI
frank26080115 0:bf7b9fba3924 185 LPC_SSP0->CR0 &= ~(1<<6); // CPOL = 0
frank26080115 0:bf7b9fba3924 186 LPC_SSP0->CR0 &= ~(1<<7); // CPHA = 0
frank26080115 0:bf7b9fba3924 187 LPC_SSP0->IMSC = 0; // disable all interrupts
frank26080115 0:bf7b9fba3924 188 LPC_SSP0->DMACR = 0; // disable DMA
frank26080115 0:bf7b9fba3924 189 LPC_SSP0->CR1 |= (1<<1); // Enable module
frank26080115 0:bf7b9fba3924 190 for (i = 0; i < 8; i++ )
frank26080115 0:bf7b9fba3924 191 {
frank26080115 0:bf7b9fba3924 192 Dummy = LPC_SSP0->DR; // clear the RxFIFO
frank26080115 0:bf7b9fba3924 193 }
frank26080115 0:bf7b9fba3924 194 // Set SSP clock frequency
frank26080115 0:bf7b9fba3924 195 GLCD_SPI_SetClockFreq(Clk);
frank26080115 0:bf7b9fba3924 196 // Set data width
frank26080115 0:bf7b9fba3924 197 GLCD_SPI_SetWordWidth(Width);
frank26080115 0:bf7b9fba3924 198 }
frank26080115 0:bf7b9fba3924 199
frank26080115 0:bf7b9fba3924 200 /*************************************************************************
frank26080115 0:bf7b9fba3924 201 * Function Name: GLCD_SPI_TranserByte
frank26080115 0:bf7b9fba3924 202 * Parameters: uint32_t Data
frank26080115 0:bf7b9fba3924 203 * Return: uint32_t
frank26080115 0:bf7b9fba3924 204 *
frank26080115 0:bf7b9fba3924 205 * Description: Transfer byte from SSP0
frank26080115 0:bf7b9fba3924 206 *
frank26080115 0:bf7b9fba3924 207 *************************************************************************/
frank26080115 0:bf7b9fba3924 208 uint32_t GLCD_SPI_TranserByte (uint32_t Data)
frank26080115 0:bf7b9fba3924 209 {
frank26080115 0:bf7b9fba3924 210 while(!(LPC_SSP0->SR & (1<<1))); //check bit TNF
frank26080115 0:bf7b9fba3924 211 LPC_SSP0->DR = Data;
frank26080115 0:bf7b9fba3924 212 while((LPC_SSP0->SR & (1<<4))); //check bit BSY
frank26080115 0:bf7b9fba3924 213 return(LPC_SSP0->DR);
frank26080115 0:bf7b9fba3924 214 }
frank26080115 0:bf7b9fba3924 215
frank26080115 0:bf7b9fba3924 216 /*************************************************************************
frank26080115 0:bf7b9fba3924 217 * Function Name: GLCD_SPI_SendBlock
frank26080115 0:bf7b9fba3924 218 * Parameters: pInt8U pData, uint32_t Size
frank26080115 0:bf7b9fba3924 219 *
frank26080115 0:bf7b9fba3924 220 * Return: void
frank26080115 0:bf7b9fba3924 221 *
frank26080115 0:bf7b9fba3924 222 * Description: Write block of data to SSP
frank26080115 0:bf7b9fba3924 223 *
frank26080115 0:bf7b9fba3924 224 *************************************************************************/
frank26080115 0:bf7b9fba3924 225 void GLCD_SPI_SendBlock (unsigned char *pData, uint32_t Size)
frank26080115 0:bf7b9fba3924 226 {
frank26080115 0:bf7b9fba3924 227 volatile uint32_t Dummy;
frank26080115 0:bf7b9fba3924 228 uint32_t OutCount = Size;
frank26080115 0:bf7b9fba3924 229 while (OutCount)
frank26080115 0:bf7b9fba3924 230 {
frank26080115 0:bf7b9fba3924 231 while((LPC_SSP0->SR & (1<<1)) && OutCount)
frank26080115 0:bf7b9fba3924 232 {
frank26080115 0:bf7b9fba3924 233 LPC_SSP0->DR = *pData++ | 0x100; // Data
frank26080115 0:bf7b9fba3924 234 --OutCount;
frank26080115 0:bf7b9fba3924 235 }
frank26080115 0:bf7b9fba3924 236 }
frank26080115 0:bf7b9fba3924 237 while(LPC_SSP0->SR & (1<<4)); //check bit BSY
frank26080115 0:bf7b9fba3924 238 // draining RX Fifo
frank26080115 0:bf7b9fba3924 239 while (LPC_SSP0->SR &(1<<2)) // check bit RNE
frank26080115 0:bf7b9fba3924 240 {
frank26080115 0:bf7b9fba3924 241 Dummy = LPC_SSP0->DR;
frank26080115 0:bf7b9fba3924 242 }
frank26080115 0:bf7b9fba3924 243 }
frank26080115 0:bf7b9fba3924 244
frank26080115 0:bf7b9fba3924 245 /*************************************************************************
frank26080115 0:bf7b9fba3924 246 * Function Name: GLCD_SPI_ReceiveBlock
frank26080115 0:bf7b9fba3924 247 * Parameters: unsigned char * pData, uint32_t Size
frank26080115 0:bf7b9fba3924 248 *
frank26080115 0:bf7b9fba3924 249 * Return: void
frank26080115 0:bf7b9fba3924 250 *
frank26080115 0:bf7b9fba3924 251 * Description: Read block of data from SSP
frank26080115 0:bf7b9fba3924 252 *
frank26080115 0:bf7b9fba3924 253 *************************************************************************/
frank26080115 0:bf7b9fba3924 254 void GLCD_SPI_ReceiveBlock (unsigned char *pData, uint32_t Size)
frank26080115 0:bf7b9fba3924 255 {
frank26080115 0:bf7b9fba3924 256 uint32_t Delta = 0;
frank26080115 0:bf7b9fba3924 257 while (Size || Delta)
frank26080115 0:bf7b9fba3924 258 {
frank26080115 0:bf7b9fba3924 259 while((LPC_SSP0->SR & (1<<1)) && (Delta < SSP_FIFO_SIZE) && Size)
frank26080115 0:bf7b9fba3924 260 {
frank26080115 0:bf7b9fba3924 261 LPC_SSP0->DR = 0xFFFF;
frank26080115 0:bf7b9fba3924 262 --Size; ++Delta;
frank26080115 0:bf7b9fba3924 263 }
frank26080115 0:bf7b9fba3924 264 while (LPC_SSP0->SR & (1<<2)) //check bit RNE
frank26080115 0:bf7b9fba3924 265 {
frank26080115 0:bf7b9fba3924 266 *pData++ = LPC_SSP0->DR;
frank26080115 0:bf7b9fba3924 267 --Delta;
frank26080115 0:bf7b9fba3924 268 }
frank26080115 0:bf7b9fba3924 269 }
frank26080115 0:bf7b9fba3924 270 }