Hi All,
I am trying to wire up and program an LCD with a PIC16F1459. I can not see any errors in the code or the wiring.
Any help would be appreciated.
The Header File;
The Source File;
The wiring has the following connections:
VDD----->5V
VSS------->GND
Vo----------1.2K resistor to GND
Enable----->RC5
RS------->RC4
R/W----->GND
D4------->RC0
D5------>RC1
D6------>RC2
D7---------->RC3
Thanks
JSwale
I am trying to wire up and program an LCD with a PIC16F1459. I can not see any errors in the code or the wiring.
Any help would be appreciated.
The Header File;
Code:
//E on RC5, RS on RC4, D4-7 on RC0-RC3
#include <pic16f1459.h>
#include <xc.h>
#define _XTAL_FREQ 31250
#define CLEAR_SCREEN 0b00000001
#define FOUR_BIT 0b00101100
#define LINES_5X8 0b00111000
#define CURSOR_BLINK 0b00001111
#define CURSOR_RIGHT 0b00000110
#define DISPLAY_ON 0b00001111
#define DISPLAY_OFF 0b00001011
#define CURSOR_ON 0b00001111
#define CURSOR_OFF 0b00001101
#define BLINK_ON 0b00001111
#define BLINK_OFF 0b00001110
#define DATA_PORT PORTC
#define RS_PIN PORTCbits.RC4
#define E_PIN PORTCbits.RC5
void Delay2ms()
{
__delay_ms(2.5);
}
void SetAddr(unsigned char DDaddr) //Sets Character Address of Screen
{
DATA_PORT &=0xf0; //Write upper nibble
DATA_PORT |=((DDaddr|0b10000000>>4)&0x0f);
RS_PIN=0; //Set control bit
Delay2ms();
E_PIN=1; //Clock the cmd and address in
Delay2ms();
E_PIN=0;
DATA_PORT&=0xf0; //Write lower nibble
DATA_PORT|=(DDaddr&0x0f);
Delay2ms();
E_PIN=1; //Clock the cmd and address in
Delay2ms();
E_PIN=0;
}
void WriteCmd(unsigned char cmd) //Writing a Command to the Display
{
DATA_PORT&=0xf0;
DATA_PORT|=(cmd>>4)&0x0f;
RS_PIN=0; //Set control signals for command
Delay2ms();
E_PIN=1; //Clock Command in
Delay2ms();
E_PIN=0;
DATA_PORT&=0xf0;
DATA_PORT|=cmd&0xf0;
Delay2ms();
E_PIN=1; //Clock Command in
Delay2ms();
E_PIN=0;
}
void WriteChar(char data) //Writing a character to the screen
{
DATA_PORT&=0xf0;
DATA_PORT|=((data>>4)&0x0f);
RS_PIN=1; //Set Control bits
Delay2ms();
E_PIN=1; //Clock nibble into LCD
Delay2ms();
E_PIN=0;
DATA_PORT&=0xf0; //Lower interface nibble
DATA_PORT|=(data&0x0f);
Delay2ms();
E_PIN=1; //Clock nibble into LCD
Delay2ms();
E_PIN=0;
}
void WriteString(const char *buffer) //'rom' <Taken Out Writing a string of characters to the screen
{
while(*buffer)
{
Delay2ms();
WriteChar( *buffer);
buffer++;
}
return;
}
Code:
#include <pic16f1459.h>
#include <xc.h>
#include <LCD.h>
void main (void)
{
//Configures display
//SET UP
WriteCmd(0x02); //Sets 4 bit Display
WriteCmd(FOUR_BIT & LINES_5X8);
WriteCmd(CURSOR_BLINK);
WriteCmd(CURSOR_RIGHT);
TRISC=0b00000000;
PORTC=0b00000000;
ANSELC=0b00000000;
SetAddr (0x82);
WriteChar('H');
WriteChar('E');
WriteChar('L');
WriteChar('L');
WriteChar('O');
while(1);
}
VDD----->5V
VSS------->GND
Vo----------1.2K resistor to GND
Enable----->RC5
RS------->RC4
R/W----->GND
D4------->RC0
D5------>RC1
D6------>RC2
D7---------->RC3
Thanks
JSwale