############################################################################### # Title: ezLCD-002 Touch Screen LCD IO Driver # # Authors: Jason Kulatunga, Tyler Best # Group: G3 # Sem: Winter 2010 ############################################################################### This application note will provide instructions regarding the initialization procedure for the ezLCD-002 connected to an ARM AT91M55800A microcontroller using a serial connection. An IO driver written in C is also provided, that implements all the functionality described in the ezLCD002 manual that is included with the LCD hardware. Hardware requirements: 1 ezLCD002 LCD with associated power brick 1 Null Modem Serial Cable 1 AT91M55800A Atmel Microcontroller Board with associated power brick Once the ezLCD has been connected to the second serial port on the Atmel board and both are powered on, the LCDInit() function located in lcd_drv.c can be used to correctly configure and initialize the ezLCD. /*-------------------CODE START-------------------*/ void LCDInit(void) { LCDOpen(); LightOn(); SetColor(LCD_WHITE); Cls(); } /*-------------------CODE END-------------------*/ The initialization function first calls the LCDOpen() function, which first calculates the required clock divider such that the serial port communicates with the LCD at the correct baud rate. The rearranged formula is given in the Atmel Manual on page 127. /*-------------------CODE START-------------------*/ void LCDOpen(){ u_int baudCD; baudCD = 32000000/(16* 115200); at91_usart_open(&USART1_DESC, US_ASYNC_MODE, baudCD, 0); } /*-------------------CODE END-------------------*/ Clock Divider = Selected Clock /(16 * Baud Rate) In our case, the Selected Clock is equal to the Atmel Master clock which is 32000000hz. The Baud Rate is equal to 115200, which is given in the ezLCD manual. This calculated Clock Divider is then used to open USART 1 in asynchronous mode, with a time delay of 0. at91_usart_open(&USART1_DESC, US_ASYNC_MODE, baudCD, 0); Once the USART has been correctly configured, the LCDInit() function calls LightOn(), SetColor() and Cls() which together turn on the backlight, sets the current draw color to white and clears the screen. These three functions are used to provide visual evidence that the LCD has been configured correctly. The LightsOn function is very simple and is defined as follows. /*-------------------CODE START-------------------*/ void LightOn(){ LCDCmd(LCD_LIGHT_ON); } void LCDCmd(u_int cmd) { while(canTrans()==0){ } at91_usart_write (&USART1_DESC, cmd); } int canTrans(){ if((at91_usart_get_status(&USART1_DESC) & US_TXRDY) == 0){ return 0; } else{ return 1; } } /*-------------------CODE END-------------------*/ Each basic function supported by the LCD has an associated hex command code, which were taken from the ezLCD manual. The LCD_LIGHT_ON value and all other command codes are defined in the lcd_drv.h file. The LCDCmd function then takes the command code, waits until the USART is ready to transmit data by polling the canTrans() function, and then writes the command code to the USART using the at91_usart_write() function. Once the USART write command is completed, if everything is connected and working properly, the LCD backlight will be turned on. This basic command tree can be used to implement even more complicated functions such as setting the screen color using the SetColor() function. /*-------------------CODE START-------------------*/ void SetColor(u_int color){ LCDCmd(LCD_SET_COLOR); LCDCmd(color); } /*-------------------CODE END-------------------*/ The LCD_SET_COLOR is defined in the lcd_drv.h file, as said previously. The ezLCD recognizes that the LCD_SET_COLOR command code will be immediately followed by an 8bit color code that is in the form BBGGGRRR. Common color codes are defined in the lcd_drv.h file. The Cls() function can then be called to paint the whole screen with the currently selected color. Having described the general command tree for a executing basic LCD functions, the rest of the functions in the lcd_drv.c are almost self-explanatory. Each command has its own command code, and required parameters are given descriptive names. All basic commands described in the ezLCD manual are implemented in the C code files. Function names follow the ANSI C pseudo code provided in the manual. Included Files: lcd_drv.c //functional code lcd_drv.h //command codes, function prototypes