extern unsigned int DisplayRamPos;
////////////////////////////////////////////////////////////////////////////////////////////// // Function that initializes the Liquid Crystal Display // ////////////////////////////////////////////////////////////////////////////////////////////// void Init_LCD(void) { SetPortDirections(); //Although the initialization of the display is Automatic //But following instructions must be executed
//Display has been turned on DisplayRamPos = 0; WriteCommandtoLCD(0x3F); //Set the first line WriteCommandtoLCD(0xC0);
DisplayRamPos = 64; WriteCommandtoLCD(0x3F); //Set the first line WriteCommandtoLCD(0xC0); } void DisplayChar(unsigned char flagRev, unsigned char Value) { unsigned int i; register unsigned char j;
// calculating the starting index of the array out of which the text is to be displayed for( i = Value*5, j=0; j < 5; i++,j++) { Write_Next_LCD(flagRev?~get_aphabet_data(i):get_aphabet_data(i) ); } Write_Next_LCD(flagRev?0xFF:0x00); }
void DisplayString(unsigned char Row, unsigned char Col, char * str) { unsigned char i; setcursor(Row,Col); for(i=0; *(str+i); i++) DisplayChar(0, *(str+i)); } int main(void) { DDRD = BV(5); TCCR1A = BV(WGM11) | BV(COM1A0) | BV(COM1A1); // Fast PWM Mode TCCR1B = BV(WGM12) | BV(WGM13) | BV(CS11); // Fast PWM Mode //For generating Variable Frequency, fixed
//On Time Pulse train OCR1A = 2; ICR1 = 0x78; // Output Voltage is inversely dependent on the ICR1 Value
Init_LCD();
Clear_Screen(); DisplayString(0, 16, "Graphics Display"); DisplayString(1, 34, "Controller"); DisplayString(2, 58, "on"); DisplayString(3, 16, "AVR Project Book"); DisplayString(5, 58, "by"); DisplayString(6, 13, "DigiSoft Pakistan"); DisplayString(7, 7, "www.digisoft.com.pk");
while(1); }
Header File
#include <avr/pgmspace.h>
void status_read(void ); //Wait_if_Busy void WriteCommandtoLCD(unsigned char cm); void setcursor(unsigned char Line, unsigned char Col); void Write_LCD(unsigned char Line, unsigned char Col, unsigned char dt); void Write_Next_LCD(unsigned char dt); unsigned char Read_LCD(void); unsigned char Read_LCD_With_Dummy(void);
void Init_LCD(void);
void Clear_Screen(void); void DisplayChar(unsigned char flagRev, unsigned char Value); unsigned char get_aphabet_data(unsigned int Addr); void SetPortDirections(void );On Blue LCD Blue LCDs are available on futurlec, that has the similar interface as of the clover LCD discussed above. Blue LCDs have good appearance and Back light, so are more versatile, but expensive. ($19.9 on futurlec). These LCDs have a built in negative voltage supply, so the contrast can be varied using a potentiometer, instead of using a negetive voltage generator (as in the clover LCD above). These LCDs also has a reset line that needs to be attached to the microcontroller, so the initilization of the Blue LCD becomes different than the Clover LCD and a seperate code for the initialization is given below and rest of the code is same .
Code for Blue LCD int main(void) { PORTD = BV(5); DDRD = BV(5) | BV(6); TCCR1A = BV(WGM11) | BV(COM1A0) | BV(COM1A1); // Fast PWM Mode TCCR1B = BV(WGM12) | BV(WGM13) | BV(CS11); // Fast PWM Mode //For generating Variable Frequency, fixed //On Time Pulse train OCR1A = 1; ICR1 = 0x2648; // Output Voltage is inversely dependent on the ICR1 Value PORTD |= BV(6); // reset the LCD Init_LCD();
Clear_Screen(); DisplayString(0, 16, "Graphics Display"); DisplayString(1, 34, "Controller"); DisplayString(2, 58, "on"); DisplayString(3, 16, "AVR Project Book"); DisplayString(5, 58, "by"); DisplayString(6, 13, "DigiSoft Pakistan"); DisplayString(7, 7, "www.digisoft.com.pk"); while(1); }Complete Code can be found here. FAQ Q. Your Code above didn't get compiled. A. The LCD related functions are bundled in GLCD.o file and is included in the code files. You will need to include it to your project files, otherwise it will not get compiled. Also the object file is made according to the Schematic above, i.e. PORTC for Data lines, PORTD for control lines, if your scheme is different than this, this object file will not work. Last Updated: Feb-2009
|



