Pic876a + hd4478 lcd

Status
Not open for further replies.

A.B.

Newbie level 3
Joined
Feb 6, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,296
Hi!
I have a problem with interfacing PIC with LCD. I use Proteus simulation. The initialization is OK - in simulation the cursor start blinking, But I can not send the characters to display.



Code:
#include <pic.h>

#define E RB4
#define RS RB5
#define D4 RB0
#define D5 RB1
#define D6 RB2
#define D7 RB3

void waitms(int ms)
{
  volatile int i,j;
  for (i=0;i<ms;i++)
    for (j=0;j<60;j++);
}
void wait20us(int ms)
{
RB6=1;
  volatile int i,j;
  for (i=0;i<ms;i++)
    for (j=0;j<2;j++);
RB6=0;
}

void E_pulse(void)
{
  E=1;
  wait20us(5);
  E=0;
  wait20us(5);
}

void LCD_cmd(int cmd)
{

  int pv;

  RS=0; // LCD command mode
  
  pv = cmd>>4;
  PORTB=pv; // high bits
  E_pulse();
 waitms(5);
  pv = cmd&0x0f;
  PORTB=pv; // low bits
  E_pulse();
  waitms(10);
}
void LCD_chr(char data[])
{
  int i;
  int pv;
  int ch;
  E=0;
  RS=1; // LCD data mode
  for(i = 0; data[i] != 0; i++)
  {
    ch=data[i];
    pv=ch>>4;
    PORTB=pv; // high bits
    E_pulse();
    waitms(5);
    pv=ch&0x0f;
    PORTB=pv; // low bits
    E_pulse();
  }
waitms(10);
}
void LCD_locate(int row, int column)
{
 RS=0;
  if(row == 1)
  {
    LCD_cmd(0x80 | (column - 1)&0x0f);
  }
  else
  {
    LCD_cmd(0xc0 | (column - 1)&0x0f);
  }  
  
  waitms(5);  
}
void LCD_init(void)
{
  TRISB=0;
  waitms(40);
  RS=0;
  PORTB=0x3;
  E_pulse();
  waitms(6);
  PORTB=0x3;
  E_pulse(); // init!
  waitms(6);
  PORTB=0x3;
  E_pulse(); // init!
  waitms(6);
  PORTB=0x2;
  E_pulse();
  LCD_cmd(0x28); 
  LCD_cmd(0x08); 
  LCD_cmd(0x01); 
  waitms(5);
  LCD_cmd(0x06);
  LCD_cmd(0x0f);
  waitms(1);
}

void main(){
LCD_init();
waitms(10);
LCD_chr("test");

while(1){
}
}


Thanks for your help!
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…