pani212
Newbie level 1
Hi
I am using microchip microstick which uses pic24hj64gp502. there are only 28 pins in the ic and for my application i can afford to use the lcd only in 4 bit mode. with my code i think there is some problem with initialization(i am not sure though). the clock that i am using is of 40MHz. all i can see flickering screen.
my code is as below:
#include "pic24_all.h"
#define RS_HIGH() _LATB9 = 1
#define RS_LOW() _LATB9 = 0
#define CONFIG_RS() CONFIG_RB9_AS_DIG_OUTPUT()
#define RW_HIGH() _LATB13 = 1
#define RW_LOW() _LATB13 = 0
#define CONFIG_RW() CONFIG_RB13_AS_DIG_OUTPUT()
#define En _LATB14
#define CONFIG_E() CONFIG_RB14_AS_DIG_OUTPUT()
#define LCD4O _LATB5
#define LCD5O _LATB6
#define LCD6O _LATB7
#define LCD7O _LATB8
#define LCD8 _LATB15
#define CONFIG_LCD4_AS_OUTPUT() CONFIG_RB5_AS_DIG_OUTPUT()
#define CONFIG_LCD5_AS_OUTPUT() CONFIG_RB6_AS_DIG_OUTPUT()
#define CONFIG_LCD6_AS_OUTPUT() CONFIG_RB7_AS_DIG_OUTPUT()
#define CONFIG_LCD7_AS_OUTPUT() CONFIG_RB8_AS_DIG_OUTPUT()
#define CONFIG_LCD8_AS_OUTPUT() CONFIG_RB15_AS_DIG_OUTPUT()
#define strobe() ((En=1),(En=0))
void configBusAsOutLCD(void)
{
RW_LOW(); //RW=0 to stop LCD from driving pins
CONFIG_LCD4_AS_OUTPUT(); //D4
CONFIG_LCD5_AS_OUTPUT(); //D5
CONFIG_LCD6_AS_OUTPUT(); //D6
CONFIG_LCD7_AS_OUTPUT(); //D7
}
void LCDbus(uint8_t u8_c)
{
LCD4O = u8_c & 0x01; //D4
LCD5O = (u8_c >> 1)& 0x01; //D5
LCD6O = (u8_c >> 2)& 0x01; //D6
LCD7O = (u8_c >> 3)& 0x01; //D7
}
void writeLCD(unsigned char c)
{
configBusAsOutLCD();
RS_HIGH();
LCDbus(c >>4);
strobe();
LCDbus(c);
strobe();
}
void initLCD()
{
RS_HIGH();
RW_LOW();
En =0;
DELAY_MS(50);
writeLCD(0x20); // 4 bit interface
DELAY_US(40);
writeLCD(0x28); // 2 line display, 5x7 font
DELAY_US(40);
writeLCD(0x06); // set entry mode
DELAY_US(40);
writeLCD(0x0E);
DELAY_US(40);
writeLCD(0x01); // clear display, move cursor to home
DELAY_MS(2);
}
void writeString(char *data)
{
RS_HIGH();
while(*data)
{
writeLCD(*data);
data++;
}
}
int main ()
{
configBasic(HELLO_MSG); // Set up heartbeat, UART, print hello message and diags
CONFIG_LCD8_AS_OUTPUT();
doHeartbeat();
initLCD(); //initialize the LCD
writeString("******Hello, my name is Bob********");
LCD8=1;
DELAY_MS(2000);
writeLCD(0xC0); // cursor to 2nd line
writeString("-----these lines are moving!-------");
while (1)
{
writeLCD(0x18); // shift left
DELAY_MS(200);
doHeartbeat();
}
return 0;
}
I am using microchip microstick which uses pic24hj64gp502. there are only 28 pins in the ic and for my application i can afford to use the lcd only in 4 bit mode. with my code i think there is some problem with initialization(i am not sure though). the clock that i am using is of 40MHz. all i can see flickering screen.
my code is as below:
#include "pic24_all.h"
#define RS_HIGH() _LATB9 = 1
#define RS_LOW() _LATB9 = 0
#define CONFIG_RS() CONFIG_RB9_AS_DIG_OUTPUT()
#define RW_HIGH() _LATB13 = 1
#define RW_LOW() _LATB13 = 0
#define CONFIG_RW() CONFIG_RB13_AS_DIG_OUTPUT()
#define En _LATB14
#define CONFIG_E() CONFIG_RB14_AS_DIG_OUTPUT()
#define LCD4O _LATB5
#define LCD5O _LATB6
#define LCD6O _LATB7
#define LCD7O _LATB8
#define LCD8 _LATB15
#define CONFIG_LCD4_AS_OUTPUT() CONFIG_RB5_AS_DIG_OUTPUT()
#define CONFIG_LCD5_AS_OUTPUT() CONFIG_RB6_AS_DIG_OUTPUT()
#define CONFIG_LCD6_AS_OUTPUT() CONFIG_RB7_AS_DIG_OUTPUT()
#define CONFIG_LCD7_AS_OUTPUT() CONFIG_RB8_AS_DIG_OUTPUT()
#define CONFIG_LCD8_AS_OUTPUT() CONFIG_RB15_AS_DIG_OUTPUT()
#define strobe() ((En=1),(En=0))
void configBusAsOutLCD(void)
{
RW_LOW(); //RW=0 to stop LCD from driving pins
CONFIG_LCD4_AS_OUTPUT(); //D4
CONFIG_LCD5_AS_OUTPUT(); //D5
CONFIG_LCD6_AS_OUTPUT(); //D6
CONFIG_LCD7_AS_OUTPUT(); //D7
}
void LCDbus(uint8_t u8_c)
{
LCD4O = u8_c & 0x01; //D4
LCD5O = (u8_c >> 1)& 0x01; //D5
LCD6O = (u8_c >> 2)& 0x01; //D6
LCD7O = (u8_c >> 3)& 0x01; //D7
}
void writeLCD(unsigned char c)
{
configBusAsOutLCD();
RS_HIGH();
LCDbus(c >>4);
strobe();
LCDbus(c);
strobe();
}
void initLCD()
{
RS_HIGH();
RW_LOW();
En =0;
DELAY_MS(50);
writeLCD(0x20); // 4 bit interface
DELAY_US(40);
writeLCD(0x28); // 2 line display, 5x7 font
DELAY_US(40);
writeLCD(0x06); // set entry mode
DELAY_US(40);
writeLCD(0x0E);
DELAY_US(40);
writeLCD(0x01); // clear display, move cursor to home
DELAY_MS(2);
}
void writeString(char *data)
{
RS_HIGH();
while(*data)
{
writeLCD(*data);
data++;
}
}
int main ()
{
configBasic(HELLO_MSG); // Set up heartbeat, UART, print hello message and diags
CONFIG_LCD8_AS_OUTPUT();
doHeartbeat();
initLCD(); //initialize the LCD
writeString("******Hello, my name is Bob********");
LCD8=1;
DELAY_MS(2000);
writeLCD(0xC0); // cursor to 2nd line
writeString("-----these lines are moving!-------");
while (1)
{
writeLCD(0x18); // shift left
DELAY_MS(200);
doHeartbeat();
}
return 0;
}