thannara123
Advanced Member level 5
I am trying to make an LCD Interfacing with 4 bit mode ,
But not working I tried a lot of
Data looked in Debug mode good not found wrong
what is the problem ?
Attached Code and Proteus files
But not working I tried a lot of
Data looked in Debug mode good not found wrong
what is the problem ?
Attached Code and Proteus files
C:
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#define _XTAL_FREQ 1000000
#include <xc.h>
#define LCD_PORTB PORTB
#define RS RB0
#define EN RB1
void Strobe (void)
{
EN = 1;
__delay_us(1);
EN = 0;
}
void LCD_cmd( unsigned char cmd)
{
RS = 0;
__delay_ms(1);
LCD_PORTB = (cmd & 0xf0) ;
Strobe();
LCD_PORTB = (cmd << 4 );
Strobe();
}
void LCD_data( unsigned char data)
{
RS = 1;
__delay_ms(1);
LCD_PORTB |= (data & 0xf0);
Strobe();
LCD_PORTB |= (data << 4 );
Strobe();
}
void LCD_init()
{
__delay_ms(20);
LCD_cmd(0x38);
__delay_ms(4);
LCD_cmd(0x38);
__delay_ms(10);
// LCD_cmd(0x38); // Power on Initilization
LCD_cmd(0x28); /* 4bit mode */
LCD_cmd(0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_cmd(0x0C); /* Display ON Cursor OFF */
LCD_cmd(0x06); /* Auto Increment cursor */
}
void string(const char *ptr)
{
while (*ptr)
{
LCD_data(*ptr++);
}
}
void main()
{
TRISB =0;
TRISD =0;
LCD_init();
LCD_cmd(0x80);
//string("HELLO WORLD");
// LINE2;
string("IT IS WORKING:-)");
while(1);
return ;
}