blackpearl87
Newbie level 5
- Joined
- Jun 8, 2014
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 91
I'm doing a project using Picdem 2 Plus 2010 demo board to simulate a vehicle theft and accident alerting system. GPS receiver and GSM modem are being used to locate the vehicle and send a SMS to pre-determined mobile number. I'm using PIC18F46K22 micro-controller for this project.
the LCD on board is a 4-bit mode. DB4-DB7 pins of the LCD are connected to D0-D3 pins of pic controller. RS, RW, EN and PWR pins are respectively connected to D4-D7. I developed the below code, but I still can't get anything displayed on LCD.
Could anyone please highlight me what's wrong with this code?
the LCD on board is a 4-bit mode. DB4-DB7 pins of the LCD are connected to D0-D3 pins of pic controller. RS, RW, EN and PWR pins are respectively connected to D4-D7. I developed the below code, but I still can't get anything displayed on LCD.
Could anyone please highlight me what's wrong with this code?
Code:
#include <p18f46k22.h>
#include <delays.h>
#define LCD_DATA PORTD
#define LCD_RS PORTDbits.RD4
#define LCD_RW PORTDbits.RD5
#define LCD_EN PORTDbits.RD6
#define LCD_PWR PORTDbits.RD7
void Init_LCD(void);
void disCmd(unsigned char);
void disData(unsigned char);
void lcdCmd(unsigned char);
void lcdData(unsigned char);
void LCD_STROBE(void);
void string(char);
void main()
{
ADCON1 = 0x0f;
OSCCON = 0x36;
TRISD = 0;
Init_LCD();
disCmd(0x80);
string("HELLO WORLD");
disCmd(0xc0);
string("IT IS WORKING:-)");
}
//****************************************************************************************************
/* LCD display initialization */
void Init_LCD()
{
disCmd(0x02);
disCmd(0x82);
disCmd(0x60);
disCmd(0xc0);
disCmd(0x80);
disCmd(0x30);
disCmd(0x10);
}
void LCD_STROBE(void)
{
LCD_EN = 1;
Delay1KTCYx(0.001);
LCD_EN = 0;
}
void string(char q)
{
while(q)
disData(q++);
}
void disCmd(unsigned char cmdValue)
{
unsigned char cmdValue1;
cmdValue1 = PORTD;
cmdValue1 &= 0xf0;
cmdValue1 = cmdValue1 | (cmdValue & 0x0f);
lcdCmd(cmdValue1);
}
void disData(unsigned char dataValue)
{
unsigned char dataValue1;
dataValue1 = PORTD;
dataValue1 &= 0xf0;
dataValue1 = dataValue1 | (dataValue & 0x0f);
lcdData(dataValue1);
}
void lcdCmd(unsigned char cmdOut)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = (cmdOut >> 4);
LCD_STROBE();
LCD_DATA = cmdOut;
LCD_STROBE();
}
void lcdData(unsigned char dataOut)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = (dataOut >> 4);
LCD_STROBE();
LCD_DATA = dataOut;
LCD_STROBE();
}