karthi27
Newbie level 5
Hi
I've been working with PIC16F877 and 2x16 JHD162A LCD module for the past 3 days. No success yet.
All that i get is black boxes in row one. And after sometime a portion of black boxes in row 2 is displayed and nothing else happens.
I monitored my EN bit, RS bit, RW bit and busy bit(DB7) with leds. Even the data bus. They are working fine. The PIC controller and ICD2 programmer are fine.
I suspect a bug in my program. Please help me identify the bug. Guess its in the initializing routine. Tried with various delay values. No success.
I've been working with PIC16F877 and 2x16 JHD162A LCD module for the past 3 days. No success yet.
All that i get is black boxes in row one. And after sometime a portion of black boxes in row 2 is displayed and nothing else happens.
I monitored my EN bit, RS bit, RW bit and busy bit(DB7) with leds. Even the data bus. They are working fine. The PIC controller and ICD2 programmer are fine.
I suspect a bug in my program. Please help me identify the bug. Guess its in the initializing routine. Tried with various delay values. No success.
Code:
[b]//Contents of LCDtest.c code:[/b]
#include <16f877.h>
#USE delay(clock=4000000) //SETTING CLOCK FREQUENCY
#FUSES XT,NOWDT,NOBROWNOUT,NOPROTECT,NOPUT //SETTING FUSES
#BYTE porta=5 //LOCATION OF REGISTER PORT A
#BYTE portb=6 //LOCATION OF REGISTER PORT B
#BYTE portc=7 //LOCATION OF REGISTER PORT C
#define LCD_PORT portb
#bit RS=portc.0
#bit EN=portc.1
#bit RW=portc.2
#bit busy=portc.3
[b]//=========Declarations============[/b]
void lcd_init(void);
void write_in(unsigned char inst);
void write_data(unsigned char data);
[u]//Program Code to display alphabet A:[/u]
void main()
{
set_tris_b(0b00000000); set_tris_c(0b00010000);
portb=0x00; portc=0x00;
RS=0; EN=0; RW=0;
delay_ms(1000);
lcd_init();
write_data(0b01000001); //character A
while(1){}
}
[b]//LCD Routines[/b]
void lcd_init(void) [b]//Routine to initialise the lcd[/b]
{
write_in(0b00000001); //clear display screen 0x01
write_in(0b00111000); //function set 2 lines and 5x7 matrix 0x38
write_in(0b00001111); //display on, cursor on and blinking 0x0f
write_in(0b00000110); //cursor move right, display shift disable 0x06
write_in(0b10000000); //Force cursor to beginning to 1st line 0x80
}
void write_in(unsigned char inst) [b]//Routine to write an instruction to LCD[/b]
{
RW=0; EN = 0; RS = 0; //RS =0 for instruction mode
LCD_PORT = inst;
EN = 1; delay_ms(20);
EN = 0; delay_ms(20);
}
void write_data(unsigned char data) [b]//Routine to write a data to LCD[/b]
{
RW=0; EN = 0; RS = 1; //RS =1 for data mode
LCD_PORT = data;
EN = 1; delay_ms(20);
EN = 0; delay_ms(20);
}
[b]//=============PIC6F877 PIN ASSIGNMENT============[/b]
/* PIN DES FUNC PIN Des FUNC
;1 MCLR Reset 40 RB7 DB7
;2 RA0 39 RB6 DB6
;3 RA1 38 RB5 DB5
;4 RA2 37 RB4 DB4
;5 RA3 36 RB3 DB3
;6 RA4 35 RB2 DB2
;7 RA5 34 RB1 DB1
;8 RE0 33 RB0 DB0
;9 RE1 32 VDD 5V
;10 RE2 31 VSS GND
;11 VDD 5V 30 RD7
;12 VSS GND 29 RD6
;13 OSC1 4MHz 28 RD5
;14 OSC2 4MHz 27 RD4
;15 RC0 RS 26 RC7
;16 RC1 EN 25 RC6
;17 RC2 RW 24 RC5
;18 RC3 BUSY(led) 23 RC4
;19 RD0 22 RD3
;20 RD1 21 RD2
*/
/*
[b]Code (Hex) Command to LCD Instruction Register[/b]
80 Force cursor to beginning to 1st line
C0 Force cursor to beginning to 2nd line
38 2 lines and 5x7 matrix
1C Shift the entire display to the right
18 Shift the entire display to the left
14 Shift cursor position to right
10 Shift cursor position to left
F Display on, cursor blinking
E Display on, cursor blinking
C Display on, cursor off
A Display off, cursor on
8 Display off, cursor off
7 Shift display left
5 Shift display right
6 Increment cursor (shift cursor to right)
4 Decrement cursor (shift cursor to left)
2 Return home
1 Clear display screen
*/