/*############################################################# Program Name : ex2_LM6029ACW_char_functions Author : Grant Phillips Date Modified : 08/02/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example program that demonstrates the use of the character functions in the LM6029ACW class library (ClrScr, GotoXY, PutChar, PutStr) and the use of string function sprintf(). Requirements : * STM32F4-Discovery Board Circuit : * The LM6029ACW is connected as described in ex1_LM6029ACW_HelloWorld. ##############################################################*/ #include "mbed.h" #include "LM6029ACW.h" LM6029ACW lcd(PD_7, PE_2, PD_6, PD_3, PD_2, PC_15, PC_14, PC_13, PC_11, PC_9, PC_8, PC_6, PC_2); //Create a LM6029ACW object called lcd // CS1 RES RS WR RD DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 DigitalOut backlight(PB_7); //if the lcd's backlight is connected to a transistor/FET circuit to switch it on and off int main() { char buf[21]; //declare a string variable of 21 chars unsigned char i; backlight = 0; //turn on the lcd's backlight while(1) { lcd.ClrScr(0); //clear the display and clear the dots (=0) wait(1.0); lcd.GotoXY(0,0); //set the character cursor to col=0, row=0 lcd.PutStr("Hello World!", 1); //display text in normal mode wait(0.5); lcd.GotoXY(0,1); //set the character cursor to col=0, row=1 for(i=1;i<=10;i++) { sprintf(buf, "%d " , i); //print a integer value and space to the buf string lcd.PutStr(buf,1); //write a string variable to the LCD in normal mode wait(0.5); } sprintf(buf, "Good Bye"); //store a string constant into the buf string variable lcd.GotoXY(0,2); //set the character cursor to col=0, row=2 for(i=0;i<=7;i++) { lcd.PutChar(buf[i], 1); //display a character on the LCD in normal mode wait(0.5); } lcd.GotoXY(12,2); //set the character cursor to col=12, row=2 for(i=65;i<=72;i++) { lcd.PutChar(i, 1); //display a integer value as a byte onn the LCD in normal mode //driver will convert it to the correpsonding ASCII char wait(0.5); } // repeat, but clear LCD with black dots. Print normal mode // lcd.ClrScr(1); //clear the display and fill with dots (=1) wait(1.0); lcd.GotoXY(0,0); //set the character cursor to col=0, row=0 lcd.PutStr("Hello World!", 1); //display text in normal mode wait(0.5); lcd.GotoXY(0,1); //set the character cursor to col=0, row=1 for(i=1;i<=10;i++) { sprintf(buf, "%d " , i); //print a integer value and space to the buf string lcd.PutStr(buf,1); //write a string variable to the LCD in normal mode wait(0.5); } sprintf(buf, "Good Bye"); //store a string constant into the buf string variable lcd.GotoXY(0,2); //set the character cursor to col=0, row=2 for(i=0;i<=7;i++) { lcd.PutChar(buf[i], 1); //display a character on the LCD in normal mode wait(0.5); } lcd.GotoXY(12,2); //set the character cursor to col=12, row=2 for(i=65;i<=72;i++) { lcd.PutChar(i, 1); //display a integer value as a byte onn the LCD in normal mode //driver will convert it to the correpsonding ASCII char wait(0.5); } // repeat, but clear LCD with clear dots. Print inverted mode // lcd.ClrScr(0); //clear the display and fill with clear dots (=0) wait(1.0); lcd.GotoXY(0,0); //set the character cursor to col=0, row=0 lcd.PutStr("Hello World!", 0); //display text in inverted mode wait(0.5); lcd.GotoXY(0,1); //set the character cursor to col=0, row=1 for(i=1;i<=10;i++) { sprintf(buf, "%d " , i); //print a integer value and space to the buf string lcd.PutStr(buf,0); //write a string variable to the LCD in inverted mode wait(0.5); } sprintf(buf, "Good Bye"); //store a string constant into the buf string variable lcd.GotoXY(0,2); //set the character cursor to col=0, row=2 for(i=0;i<=7;i++) { lcd.PutChar(buf[i], 0); //display a character on the LCD in inverted mode wait(0.5); } lcd.GotoXY(12,2); //set the character cursor to col=12, row=2 for(i=65;i<=72;i++) { lcd.PutChar(i, 0); //display a integer value as a byte onn the LCD in inverted mode //driver will convert it to the correpsonding ASCII char wait(0.5); } // repeat, but clear LCD with black dots. Print inverted mode // lcd.ClrScr(1); //clear the display and fill with dots (=1) wait(1.0); lcd.GotoXY(0,0); //set the character cursor to col=0, row=0 lcd.PutStr("Hello World!", 0); //display text in inverted mode wait(0.5); lcd.GotoXY(0,1); //set the character cursor to col=0, row=1 for(i=1;i<=10;i++) { sprintf(buf, "%d " , i); //print a integer value and space to the buf string lcd.PutStr(buf,0); //write a string variable to the LCD in inverted mode wait(0.5); } sprintf(buf, "Good Bye"); //store a string constant into the buf string variable lcd.GotoXY(0,2); //set the character cursor to col=0, row=2 for(i=0;i<=7;i++) { lcd.PutChar(buf[i], 0); //display a character on the LCD in inverted mode wait(0.5); } lcd.GotoXY(12,2); //set the character cursor to col=12, row=2 for(i=65;i<=72;i++) { lcd.PutChar(i, 0); //display a integer value as a byte onn the LCD in inverted mode //driver will convert it to the correpsonding ASCII char wait(0.5); } } }