Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial LCD Design and Progrmming

Status
Not open for further replies.

M.Rehan

Full Member level 2
Joined
Feb 10, 2016
Messages
129
Helped
2
Reputation
66
Reaction score
33
Trophy points
28
Activity points
972
I want to design a serial LCD using shift register

Shift Register :CD4015B
LCD : 1602A 16x2
PIC 18F4550
Tool: MikroC

Can someone suggest me helping document and program for communication

I am new to Serial Communication
 

This code to work with 1602 connected to mcu throught 74HC595
lcd.PNG
Code:
#define LCD_BackLight_BIT          (1<<1)
#define LCD_RS_BIT                 (1<<2)
#define LCD_E_BIT                  (1<<3)
#define LCD_Data_Mask               0xF0
#define LCD_CMD_Mask                0x0E
#define LCD_Delay                   5

unsigned char SPI_DAT = LCD_BackLight_BIT;

void LCD_init(void)
{
        delay_ms(17);
        LCD_Write(0x30);
        delay_ms(1);
        LCD_Write(0x30);
        delay_ms(1);
        LCD_Write(0x30);
        delay_ms(1);
        LCD_Write(0x20);  //4 bit wide bus
                  
        LCD_Send_Cmd(0x28);           //4bit wide bus 2 rows
        LCD_Send_Cmd(0x10);
        LCD_Send_Cmd(0x01);
        LCD_Send_Cmd(0x0F);

        LCD_Send_Cmd(LCD_CMD_Cursor_Off);
        LCD_Send_Cmd(LCD_CMD_Clear);
        delay_ms(10);
}

void LCD_Write(unsigned char Dat)
{         
 SPI_DAT&=(LCD_RS_BIT|LCD_BackLight_BIT|LED_BLUE);
 SPI_DAT|=(Dat&LCD_Data_Mask)|LCD_E_BIT;

 PIN_OFF(LCD_CS);
 SPI_SendByte(SPI_DAT);
 PIN_ON(LCD_CS);

 SPI_DAT&=~LCD_E_BIT;
 PIN_OFF(LCD_CS);
 SPI_SendByte(SPI_DAT);
 PIN_ON(LCD_CS);

}
void LCD_Send_Cmd(unsigned char CMD)
{
        delay_ms(5);
        SPI_DAT&=~LCD_RS_BIT;
        LCD_Write((CMD&0xF0));
        LCD_Write(((CMD&0x0F)<<4));
        delay_ms(5);
}

void lcd_set_position(unsigned char row, unsigned char colum)
{
        unsigned char position = 0x80;
        if (row > 0) { position |= 0x40;}
        LCD_Send_Cmd(position | colum);
}

void lcd_write_data(unsigned char dat)
{
        delay_us(50);
        SPI_DAT|=LCD_RS_BIT;
        LCD_Write((dat&0xF0));
        LCD_Write(((dat&0x0F)<<4));
}

void LCD_BackLight (unsigned char State, unsigned char BlueLed)
{
  if (State)  SPI_DAT|=LCD_BackLight_BIT;
  else   SPI_DAT&=~LCD_BackLight_BIT;
  if (BlueLed == 0) SPI_DAT|=LED_BLUE;
  else SPI_DAT&=~LED_BLUE;
}

void lcd_print_char(char dat)
{
   if (dat == '\n') LCD_Send_Cmd(0x80 | 0x40); 
               else lcd_write_data(dat);
}

void lcd_print_string(char * string)
{
   while (*string) lcd_print_char(*string++);
}
 
  • Like
Reactions: M.Rehan

    M.Rehan

    Points: 2
    Helpful Answer Positive Rating
Hi,

decide what serial interface you want to use. (SPI, I2C, UART...)

you want the complete communcation including
* read (you may communicate only "writing")
* busy flag control?

Klaus
 

you want the complete communcation including
* read (you may communicate only "writing")
* busy flag control?
Klaus

Only for writing Purpose


decide what serial interface you want to use. (SPI, I2C, UART...)
Klaus
Don't Know which is better for writing only

- - - Updated - - -

@Easyrider83

Can you Suggest the web page address for explanation of code
 

Hi,

easyrider´s solution uses SPI.
Seems t be O. K. and the code / schematic is almost self explaining.

Klaus
 

For I2c also have. But hard to find. 1602 with microchip's I2c port expander is very popular on ebay. Only two wires needed. But for my purpose 1602 is too slow.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top