Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to display letters in program

Status
Not open for further replies.

Parth86

Member
How to display letters in embedded c programming? 8051 and keil compiler
For Example
/* Display "E" at 2nd column in first row */
/* Display "T" at 3rd column in first row */
/* Display "0" at 3rd column in second row */
C:
    #include<reg51.h>
    /* Data pins connected to port P1 of 8051 */
    #define  Data_Port_Pins                            (P1)
    sbit    Register_Select_Pin   = P2^0;           /* Register Pin of LCD connected to Pin 0 of Port P2 */
    sbit    Read_Write_Pin        = P2^1;           /* Read/Write Pin of LCD connected to Pin 1 of Port P2 */
    sbit    Enable_Pin            = P2^2;           /* EN pin connected to pin 2 of port P2 */
    /* Function for creating delay in milliseconds */
    void Delay(unsigned int wait)
       {
          unsigned i, j;
          for(i = 0; i < wait; i++)
             for(j = 0; j < 1200; j++);
       }
    
    /* Function to send command instruction to LCD */
    void LCD_Command (unsigned char command)
    {
        Data_Port_Pins = command;
        Register_Select_Pin =0;
        Read_Write_Pin=0;
        Enable_Pin =1;
        Delay (2);
        Enable_Pin =0;
    }
    /* Function to send display data to LCD */
    void LCD_Data (unsigned char Data)
    {
        Data_Port_Pins = Data;
        Register_Select_Pin=1;
        Read_Write_Pin=0;
        Enable_Pin =1;
        Delay(2);
        Enable_Pin =0;
    }
    /* Function to prepare the LCD  and get it ready */
    void LCD_Initialization()
    {
        LCD_Command (0x38);
        LCD_Command (0x0e);
        LCD_Command (0x01);
        LCD_Command (0x81);
    }
       void main()
{
  /* Display "E" at 2nd column in first row */
 /* Display "T" at 3rd column in first row */
/* Display "T" at 3rd column in second row */
}
 
Write a LCD goto function... If you send 0x80 to the LCD the cursor will be at the start position.. If you send 0x80 plus 0x40 (0xCo) you will be at the beginning of the second row... So then add in the columns.
C:
void LCD_goto( char x, char y)
   {
   int addr = 0x80;   // start address
   if(y==2) addr+=0x40;  // are we on second row
   addr += x;    // add in the columns
   LCD_command(addr);   // send to display.
   }
 
Write a LCD goto function... If you send 0x80 to the LCD the cursor will be at the start position.. If you send 0x80 plus 0x40 (0xCo) you will be at the beginning of the second row... So then add in the columns.
C:
void LCD_goto( char x, char y)
   {
   int addr = 0x80;   // start address
   if(y==2) addr+=0x40;  // are we on second row
   addr += x;    // add in the columns
   LCD_command(addr);   // send to display.
   }
sorry but I didn't understand that function. In my opinion It should be like this
C:
 main ()
{
LCD_Initialization();
while (1)
    {
       LCD_Position(row, pos);
       LCD_Data('E');        /* Display "E" at 1nd column in first row */
       LCD_Position(row, pos);
       LCD_Data('T');        /* Display 'T' at 2nd column in first row */
     }
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top