bicibici1
Newbie level 4
- Joined
- Nov 6, 2009
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- United Kingdom
- Activity points
- 1,335
Hi everyone, I have a problem regarding my design. I have recently designed a development board (similar to Explorer 16) using the bits and pieces of Explorer 16 schematic. As I couldn't find the LCD used on the Explorer 16 kit or the Microchip suggested LCDs I went for the 20x4 Winstar 2004a Alphanumeric LCD display. After a long debugging process I have tried to get something on the LCD. I have used the schematic from Explorer 16 user guide which is below. On the LCD datasheet I see that this is correct. So it looks like I have no problem with the hardware.
View attachment LCD module.bmp
I have than added a variable resistor to the pin 3 o adjust the contrast which is fine. When I power up the PCB I see black rectangles on 1st and 3rd line which is I believe how it is supposed to be. I have been trying the code below. I tried the same code on an actual Explorer 16 board and it works but when I try it on my board, the rectangles disappear and nothing comes up on the display. I tried debuggng it using Mplab and looks like it initialises it and completes the code but than I still cant see anything on the display. I have no idea what the problem is. I know the addresses on 2 line LCD and 4line LCD are different but there should still be things visible somewhere on the display right? Any suggestions would be amazing. Here is the code I am using and again this works on 16x2 LCD on Explorer 16 board.
View attachment LCD module.bmp
I have than added a variable resistor to the pin 3 o adjust the contrast which is fine. When I power up the PCB I see black rectangles on 1st and 3rd line which is I believe how it is supposed to be. I have been trying the code below. I tried the same code on an actual Explorer 16 board and it works but when I try it on my board, the rectangles disappear and nothing comes up on the display. I tried debuggng it using Mplab and looks like it initialises it and completes the code but than I still cant see anything on the display. I have no idea what the problem is. I know the addresses on 2 line LCD and 4line LCD are different but there should still be things visible somewhere on the display right? Any suggestions would be amazing. Here is the code I am using and again this works on 16x2 LCD on Explorer 16 board.
Code:
#include <p24Fxxxx.h>
#if defined( __PIC24FJ256GB110__ ) || defined( __PIC24FJ256GB106__ )
#define PLL_96MHZ_ON 0xF7FF
_CONFIG1(ICS_PGx2 & JTAGEN_OFF & FWDTEN_OFF) // JTAG off, watchdog timer off
_CONFIG2( FNOSC_PRIPLL & PLL_96MHZ_ON & PLLDIV_DIV2 & OSCIOFNC_OFF & FCKSM_CSDCMD & POSCMOD_XT)
#else // PIC24FJ128GA010 and PIC24FJ256GA110
_CONFIG1( ICS_PGx2 & JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF)
_CONFIG2( FNOSC_PRIPLL & OSCIOFNC_OFF & FCKSM_CSDCMD & POSCMOD_HS)
#endif
#define LCDDATA 1
#define LCDCMD 0
#define PMDATA PMDIN1
void initLCD( void)
{
// PMP initialization
PMCON = 0x83BF; // Enable the PMP, long waits
PMMODE = 0x3FF; // Master Mode 1
PMAEN = 0x0001; // PMA0 enabled
// init TMR1
T1CON = 0x8030; // Fosc/2, prescaled 1:256, 16us/tick
// wait for >30ms
TMR1 = 0; while( TMR1<2000);// 2000 x 16us = 32ms
//initiate the HD44780 display 8-bit init sequence
PMADDR = LCDCMD; // command register
PMDATA = 0b00111000; // 8-bit interface, 2 lines, 5x7
TMR1 = 0; while( TMR1<3); // 3 x 16us = 48us
PMDATA = 0b00001100; // display ON, cursor off, blink off
TMR1 = 0; while( TMR1<3); // 3 x 16us = 48us
PMDATA = 0b00000001; // clear display
TMR1 = 0; while( TMR1<100); // 100 x 16us = 1.6ms
PMDATA = 0b00000110; // increment cursor, no shift
TMR1 = 0; while( TMR1<100); // 100 x 16us = 1.6ms
} // initLCD
char readLCD( int addr)
{
int dummy;
while( PMMODEbits.BUSY); // wait for PMP to be available
PMADDR = addr; // select the command address
dummy = PMDATA; // initiate a read cycle, dummy read
while( PMMODEbits.BUSY); // wait for PMP to be available
return( PMDATA); // read the status register
} // readLCD
#define busyLCD() readLCD( LCDCMD) & 0x80
#define addrLCD() readLCD( LCDCMD) & 0x7F
#define getLCD() readLCD( LCDDATA)
void writeLCD( int addr, char c)
{
while( busyLCD());
while( PMMODEbits.BUSY); // wait for PMP to be available
PMADDR = addr;
PMDATA = c;
} // writeLCD
#define putLCD( d) writeLCD( LCDDATA, (d))
#define cmdLCD( c) writeLCD( LCDCMD, (c))
#define homeLCD() writeLCD( LCDCMD, 2)
#define clrLCD() writeLCD( LCDCMD, 1)
#define setLCDG( a) writeLCD( LCDCMD, (a & 0x3F) | 0x40)
#define setLCDC( a) writeLCD( LCDCMD, (a & 0x7F) | 0x80)
void putsLCD( char *s)
{
while( *s) putLCD( *s++);
} //putsLCD
main( void)
{
int i;
// initializations
initLCD();
putsLCD( "Why is\n");
putsLCD( "my LCD\n");
putsLCD( "not working???\n");
} // main