Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

LCD.c

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation.
00024 #include "LCD.h"
00025 #include "USI_TWI_Master.h"
00026 
00027 extern unsigned char messageBuf[];
00028 
00029 
00030 unsigned char LCD_Init(void)
00031 {       
00032 
00033   messageBuf[0] = LCD_ADR | (FALSE<<TWI_READ_BIT);  // slave address + R/W mode
00034   messageBuf[1] = 0x00;               // control byte
00035   messageBuf[2] = 0x34;               // command: 16 characters x 2 lines
00036   messageBuf[3] = 0x0C;               // command: display on, cursor off
00037   messageBuf[4] = 0x06;               // command: increment, no shift
00038   messageBuf[5] = 0x35;               // command: extended instruction set
00039   messageBuf[6] = 0x04;               // command: left-to-right, top-to-bottom
00040   messageBuf[7] = 0x10;               // command: TC1=0, TC2=0
00041   messageBuf[8] = 0x42;               // command: HV stage 3
00042   messageBuf[9] = 0x9F;               // command: set VLCD, store VA
00043   messageBuf[10] = 0x34;              // command: normal instruction set
00044   messageBuf[11] = 0x80;              // command: DDRAM address = 0x00
00045   messageBuf[12] = 0x02;              // command: return home
00046 
00047   return (USI_TWI_Start_Transceiver_With_Data(messageBuf,13));
00048 }
00049 
00050 unsigned char LCD_ClearDisplay(void)
00051 {
00052   unsigned char statusTWI;
00053 
00054   statusTWI = LCD_ClearLine(0);
00055   if (statusTWI)
00056     return (LCD_ClearLine(1));
00057   else
00058     return (statusTWI);
00059 }
00060 
00061 unsigned char LCD_ClearLine(unsigned char row)
00062 {
00063   unsigned char i=0, statusTWI;
00064 
00065   do
00066     statusTWI = LCD_PutXY_Raw(0xA0,i%16,row);
00067   while ((i++ < 16) & statusTWI);
00068   return (statusTWI);
00069 }
00070 
00071 unsigned char LCD_PutXY(unsigned char ch, unsigned char column, unsigned char row)
00072 {
00073   return (LCD_PutXY_Raw(ASCIItoLCD(ch),column,row));
00074 }
00075 
00076 unsigned char LCD_PutXY_Raw(unsigned char ch, unsigned char column, unsigned char row)
00077 {
00078   unsigned char statusTWI;
00079 
00080   messageBuf[0] = LCD_ADR | (FALSE<<TWI_READ_BIT);  // slave address + R/W mode
00081   messageBuf[1] = 0x00;               // control byte
00082   if (row == 0)
00083     messageBuf[2] = 0x80 + column;    // set DDRAM address to 0x00 + X offset
00084   else
00085     messageBuf[2] = 0xC0 + column;    // set DDRAM address to 0x10 + X offset
00086   statusTWI = USI_TWI_Start_Transceiver_With_Data(messageBuf,3);
00087   if (!statusTWI)
00088     return (statusTWI);
00089 
00090   messageBuf[0] = LCD_ADR | (FALSE<<TWI_READ_BIT);  // slave address + R/W mode
00091   messageBuf[1] = 0x40;               // control byte for data
00092   messageBuf[2] = ch;
00093   return (USI_TWI_Start_Transceiver_With_Data(messageBuf,3));
00094 }
00095 
00096 unsigned char LCD_WriteLine(unsigned char *msg, unsigned char row)
00097 {
00098   unsigned char i, statusTWI;
00099 
00100   messageBuf[0] = LCD_ADR | (FALSE<<TWI_READ_BIT);  // slave address + R/W mode
00101   messageBuf[1] = 0x00;               // control byte
00102   if (row == 0)
00103     messageBuf[2] = 0x80;             // command: set DDRAM address to 0x00
00104   else
00105     messageBuf[2] = 0xC0;             // command: set DDRAM address to 0x10
00106   statusTWI = USI_TWI_Start_Transceiver_With_Data(messageBuf,3);
00107   if (!statusTWI)
00108     return (statusTWI);
00109 
00110   messageBuf[0] = LCD_ADR | (FALSE<<TWI_READ_BIT);  // slave address + R/W mode
00111   messageBuf[1] = 0x40;               // control byte for data
00112   for (i=0;i<16;i++)
00113     messageBuf[2+i] = ASCIItoLCD(*(msg++));
00114   return (USI_TWI_Start_Transceiver_With_Data(messageBuf,18));
00115 }
00116 
00117 unsigned char ASCIItoLCD(unsigned char ch)
00118 {
00119   unsigned char c;
00120 
00121   c = 0x40;
00122   if ((ch >= 0x20) & (ch <= 0x3F))
00123     c = 0x80 + ch;
00124   if ((ch >= 0x41) & (ch <= 0x5A))
00125     c = 0x80 + ch;
00126   if ((ch >= 0x61) & (ch <= 0x7A))
00127     c = 0x80 + ch;
00128 
00129   return c;
00130 }

Generated on Mon Oct 10 15:25:09 2005 for AVR245: Code Lock with 4x4 Keypad and I2C(TM) LCD by  doxygen 1.4.4