We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I have written some LCD code using Text String method but i do not know how to display the calculated output result using this method. Here is the code using String method and if you have any idea on how to display calculated output result please give suggestion on how to implement .
/* LCD output display of detected gas*/ /* Display the LCD in terms of Character 2x20 (2 line and 20 char)*/ #include <reg51.h> #include <stdio.h> #include <string.h> sbit RS = P1^3; // I/O Pin for P1.3 = RS sbit R_W = P1^4; // I/O Pin for P1.4 = R/W sbit E = P1^5; // I/O Pin for P1.5 = E /* Display-Commands */ #define CLEAR_DISPLAY 0x01 // Clear entire display and set Display Data Address to 0 #define DD_RAM_PTR 0x80 // Address Display Data RAM pointer #define DISP_INIT 0x38 // 8 bit 2 lines #define INC_MODE 0x06 // Display Data RAM pointer incremented after write #define LCD_ON 0x0C // Turn on LCD /*Port C of 8255 Declaration*/ xdata unsigned char PC = 0x4002; //PORT C connect to LCD; xdata unsigned char config = 0x4003; //** Do i need to declare PORT C as output port ?? /*Wait state*/ void wait(unsigned int time) { int i; for (i = 0; i < time ;i++){ } } /* LCD_WriteControl: Write Control to Instruction Register of LCD Display Device*/ static void LCD_WriteControl (unsigned char Instr) { RS = 0; // select instruction register as Write Ins R_W = 0; // write operation E = 0; // give operation start signal**Can i enable the LCD straight away? PC = Instr; // write instruction to PORT C of 8255 E = 1; wait(2); //**How long is the appropriate wait?? is 2ms enough?? } /* LCD_WriteData: Write to Data Register of LCD Display Device */ static void LCD_WriteData (unsigned char val) { RS = 1; // select data register Write Data R_W = 0; // write operation E = 0; // give operation start signal PC = val; // write value TO PORT C OF 8255 E = 1; wait(2); } /* LCD_DisplayCharacter:Display a single character,at the current cursor location.*/ void LCD_DisplayCharacter (char a_char) { LCD_WriteData (a_char); } /* LCD_Cursor: Position the LCD cursor at "row", "column" */ void LCD_Cursor (char row, char column) { switch (row) {//Only 2 row of line case 1: LCD_WriteControl (0x80 + column - 1); break;//same as(0x80) case 2: LCD_WriteControl (0xc0 + column - 1); break;//same as(0xc0)->Nextline=2nd row default: break; } } /* LCD_DisplayString: Display a string at the specified row and column */ void LCD_DisplayString (char row, char column, char *string) { LCD_Cursor (row, column); while (*string) LCD_DisplayCharacter (*string++); } /* LCD_StringCentered: Display a string centered on the specified row */ void LCD_StringCentered (char row, char *string) { char len = strlen (string); if (len <= 20) { // if the string is less than one line, center it ... char i; LCD_Cursor (row, 1); for (i=0; i<20; i++) LCD_DisplayCharacter (' '); LCD_DisplayString(row,((20 - len) / 2)+1,string); } else { // if the string is more than one line, display first 20 characters char temp[21]; strncpy(temp, string, 20); temp[20] = 0; LCD_DisplayString(row,1,temp); } } /* LCD initialization*/ static void LCD_init (void) { LCD_WriteControl (DISP_INIT); //0x38 LCD_WriteControl (DISP_INIT); //0x38 LCD_WriteControl (DISP_INIT); //0x38 LCD_WriteControl (INC_MODE); //0x06 LCD_WriteControl (LCD_ON); //0x0C LCD_WriteControl (CLEAR_DISPLAY); //0x01 LCD_WriteControl (DD_RAM_PTR); //0x80 wait (5); //wait for 5ms } /* Next Line */ /*static void Next_line (void) { LCD_WriteControl (NEXT_LINE); wait (1); }*/ /* Main Program Function : LCD DISPLAY*/ void LCD(float O[]) { /* Declare Message for LCD display*/ //unsigned char msg1a[] = "Gas Chloroform"; //unsigned char msg2a[] = "Gas Aceton"; //unsigned char msg3a[] = "Gas Benzene"; //unsigned char msg4a[] = "Gas Methanol"; /* Check on each neuron Output value, if>0.9 display the detected GAS*/ if ((O[0]>=0.9) && (O[1]<=0.001) && (O[2]<=0.001) && (O[3]<=0.001)) { LCD_init (); LCD_StringCentered (1,"Gas Chloroform"); //row 1,centered LCD_StringCentered (2,"Output = %f");//row2, centered } //**Actually need to display neuorn output value??how to do??? else if ((O[1]>=0.9) && (O[0]<=0.001) && (O[2]<=0.001) && (O[3]<=0.001)) { LCD_init (); LCD_StringCentered (1,"Gas Acetone"); //row 1,centered LCD_StringCentered (2,"Output = %f");//row2, centered } else if ((O[2]>=0.9) && (O[0]<=0.001) && (O[1]<=0.001) && (O[3]<=0.001)) { LCD_init (); LCD_StringCentered (1,"Gas Benzene"); //row 1,centered LCD_StringCentered (2,"Output = %f");//row2, centered } else if ((O[3]>=0.9) && (O[0]<=0.001) && (O[1]<=0.001) && (O[2]<=0.001)) { LCD_init (); LCD_StringCentered (1,"Gas Methanol"); //row 1,centered LCD_StringCentered (2,"Output = %f");//row2, centered } else { LCD_init (); LCD_StringCentered (1,"SORRY "); //row 1,centered LCD_StringCentered (2,"Unknown Gas");//row2, centered } } thanks
convert a number to ASCII code,then store it in an array like
uchar ToBeDisp[3]; i = 20; // result number ToBeDisp[0] = i / 10 + 0x30; ToBeDisp[1] = i % 10 + 0x30; ToBeDisp[2] = 0x00; // the end of the string LCD_DisplayString(ToBeDisp);