LCD_driver.c File Reference


Detailed Description

Functions used to control the STK502 LCD.

Application note:
AVR065: LCD Driver for the STK502
Documentation:
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
RELEASE_1_1
Revision
1.3
RCSfile
LCD_driver.c,v
Date
2006/02/16 18:14:01

Definition in file LCD_driver.c.

#include "defines.h"
#include "LCD_driver.h"

Include dependency graph for LCD_driver.c:

Go to the source code of this file.

Functions

void LCD_AllSegments (unsigned char input)
 display all or hide all LCD segments on the STK502 LCD.
void LCD_Init (void)
 Initialize LCD_displayData buffer. Set up the LCD (timing, contrast, etc.).
__interrupt void LCD_SOF_interrupt (void)
 Latch the LCD_displayData and Set LCD_status.updateComplete.
void LCD_WriteDigit (unsigned char c, unsigned char digit)
 Stores LCD control data in the LCD_displayData buffer. (The LCD_displayData is latched in the LCD_SOF interrupt).

Variables

__flash unsigned int LCD_character_table []
 Look-up table used when converting ASCII to LCD display data (segment control).
unsigned char LCD_displayData [LCD_REGISTER_COUNT]
 LCD display buffer (for double buffering).
_LCD_status LCD_status = {0x01}
 LCD_status = {0, 0, 0, 0, 0, 0, FALSE, TRUE};.
unsigned char LCD_timer = LCD_TIMER_SEED
 Determine the delay to next LCD update.


Function Documentation

void LCD_AllSegments unsigned char  input  ) 
 

display all or hide all LCD segments on the STK502 LCD.

Parameters:
input - [TRUE;FALSE]=[DISPLAY;HIDE].

Definition at line 176 of file LCD_driver.c.

References LCD_displayData.

Referenced by LCD_Init().

00177 {
00178         unsigned char i;
00179         unsigned char *ptr;
00180 
00181         if( input )                                 // if input == TRUE
00182                 input = 0xFF;                   // set setgemts to 0xFF
00183                                                                 // (else set segments to 0x00)
00184         
00185         ptr = LCD_displayData;
00186         i = 20;
00187         do                                                      // Set all LCD segment register to the variable ucSegments
00188         {
00189                 *ptr++ = input;         // Set/clear the bits in all LCD registers
00190         } while ( --i );
00191 }

void LCD_Init void   ) 
 

Initialize LCD_displayData buffer. Set up the LCD (timing, contrast, etc.).

Definition at line 98 of file LCD_driver.c.

References FALSE, LCD_AllSegments(), LCD_CONTRAST_LEVEL, and LCD_INITIAL_CONTRAST.

Referenced by main().

00099 {
00100         LCD_AllSegments( FALSE );       // Clear segment buffer.
00101         LCDCRA = (1<<LCDEN);            // Enable LCD.
00102 
00103     LCD_CONTRAST_LEVEL(LCD_INITIAL_CONTRAST);    //Set the LCD contrast level
00104 
00105         // Select asynchronous clock source, enable all COM pins and enable all segment pins.
00106         LCDCRB = (1<<LCDCS) | (1<<LCDMUX1) | (1<<LCDMUX0) | (1<<LCDPM2) | (1<<LCDPM1)| (1<<LCDPM0);
00107         LCDFRR = (1<<LCDPS0);                       // Set LCD prescaler to CLK(lcd)/64 = 64Hz.
00108 
00109         LCDCRA |= (1<<LCDIE);                       //Enable LCD_Start_frame interrupt
00110 }

Here is the call graph for this function:

__interrupt void LCD_SOF_interrupt void   ) 
 

Latch the LCD_displayData and Set LCD_status.updateComplete.

Definition at line 197 of file LCD_driver.c.

References FALSE, LCD_displayData, LCD_timer, LCD_TIMER_SEED, pLCDREG, TRUE, _LCD_status::updateComplete, and _LCD_status::updateRequired.

00200 {
00201         unsigned char i;
00202         unsigned char *src, *dest;
00203 
00204         LCD_timer--;
00205         if( LCD_timer == 0 )
00206         {
00207             if( LCD_status.updateRequired == TRUE )
00208                 {
00209                         LCD_timer = LCD_TIMER_SEED;
00210                         LCD_status.updateComplete = TRUE;       // Set the ucLCD_ScrollReady to true.
00211 
00212                         // Copy display data buffer to I/O segment registers.
00213                         i = 20;
00214                         dest = &pLCDREG;
00215                         src = LCD_displayData;
00216                         do
00217                         {
00218                                 *dest++ = *src++;
00219                         } while ( --i );
00220                 }
00221                 else
00222                 {
00223                   LCD_timer = 1;              //If LCD timer allows update of the LCD, but update is blocked
00224                                               // by LCD_status.updateRequired == FALSE the LCD_timer is preloaded
00225                                               // with smallest timer seed to ensure fastest LCD update.
00226           LCD_status.updateComplete = FALSE;  //Block for further access to the LCD_displayData until
00227                                               // LCD update has been performed.
00228                 }
00229         }
00230 }

void LCD_WriteDigit unsigned char  c,
unsigned char  digit
 

Stores LCD control data in the LCD_displayData buffer. (The LCD_displayData is latched in the LCD_SOF interrupt).

Parameters:
c - The symbol to be displayed in a LCD digit.
digit - The LCD digit that the symbol should be displayed in.

Definition at line 119 of file LCD_driver.c.

References LCD_character_table, and LCD_displayData.

Referenced by main().

00120 {
00121 
00122         unsigned int seg;
00123         unsigned char i;
00124         unsigned char mask, nibble;
00125         unsigned char *ptr;
00126 
00127         //Lookup character table for segmet data
00128         seg = 0x0000;
00129         if ( (c >= '*') && (c <= 'z') )
00130         {
00131                 // c is in character_table.
00132                 // Convert to upper if necessarry.
00133                 if ( c >= 'a' ) c &= ~0x20;
00134                 c -= '*';
00135                 seg = LCD_character_table[c];
00136         }
00137         else
00138         {
00139                 return;         //ASCII code out of range
00140         }
00141 
00142         // Adjust mask according to digit
00143         mask = 0x0F;            // (1), 3, 5, 7
00144         if ( digit & 0x01 )
00145         {
00146                 //left empty to optimize code size
00147         }
00148         else
00149         {
00150                 mask = 0xF0;            // (0), 2, 4, 6
00151         }
00152 
00153         i = digit-2;            //i used as pointer offset
00154         if ( i >= 6 )           //Test if LCD digit is out of range
00155                 return;
00156         i >>= 1;
00157         ptr = LCD_displayData + i;      // Point to the first relevant LCDDR; i = {0,0,1,1,2,2}
00158 
00159         i = 4;                  //i used as loop counter
00160         do
00161         {
00162                 nibble = seg & 0x000F;
00163                 seg >>= 4;
00164                 if ( digit & 0x01 )
00165                         nibble <<= 4;
00166                 *ptr = (*ptr & mask) | nibble;
00167                 ptr += 5;
00168         } while ( --i );
00169 }


Variable Documentation

__flash unsigned int LCD_character_table[]
 

Look-up table used when converting ASCII to LCD display data (segment control).

Definition at line 37 of file LCD_driver.c.

Referenced by LCD_WriteDigit().

unsigned char LCD_displayData[LCD_REGISTER_COUNT]
 

LCD display buffer (for double buffering).

Definition at line 34 of file LCD_driver.c.

Referenced by LCD_AllSegments(), LCD_SOF_interrupt(), and LCD_WriteDigit().

union _LCD_status LCD_status = {0x01}
 

LCD_status = {0, 0, 0, 0, 0, 0, FALSE, TRUE};.

Definition at line 31 of file LCD_driver.c.

Referenced by LCD_timerDelay(), and main().

unsigned char LCD_timer = LCD_TIMER_SEED
 

Determine the delay to next LCD update.

Definition at line 32 of file LCD_driver.c.

Referenced by LCD_SOF_interrupt(), and LCD_timerDelay().


Generated on Fri Feb 17 12:31:58 2006 for AVR065: LCD Driver for the STK502 by  doxygen 1.4.5