View previous topic :: View next topic |
Author |
Message |
buler
Joined: 27 Apr 2011 Posts: 10
|
Using Combination of Two Ports to interface w/ LCD [SOLVED] |
Posted: Tue May 03, 2011 1:36 pm |
|
|
I am trying to interface my PIC 16F690 with a 4x20 LCD. Right now I am using Pins A0, A1, A2 as Enable, R/W, & RS Respectively and then using Pins B4-B7 for the Data lines.
I tried editing the the LCD.c file to uncomment out the "#define use_portb_lcd TRUE" part, but as I am also using part of Port A I am getting errors.
I feel like I need to be editing this part of the file:
Code: | struct lcd_pin_map { // This structure is overlayed
BOOLEAN enable; // on to an I/O port to gain
BOOLEAN rs; // access to the LCD pins.
BOOLEAN rw; // The bits are allocated from
BOOLEAN unused; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;
|
But am a little unsure how to work in the port A pins.
Here is the sample code I am using just to try and display some text:
Code: | #include <16F690.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#define LCD_ENABLE_PIN PIN_A0
#define LCD_RS_PIN PIN_A2
#define LCD_RW_PIN PIN_A1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include "lcd420.c"
void main() {
lcd_init(); //Initialise LCD
delay_ms(10);
lcd_putc("\fHello World\n");
while(1);
} |
Last edited by buler on Thu May 05, 2011 9:33 am; edited 4 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
buler
Joined: 27 Apr 2011 Posts: 10
|
|
Posted: Wed May 04, 2011 8:09 am |
|
|
Thanks! I decided to use to flex_lcd420.c driver and sub in my pins. Everything compiled fine but when I go to import the hexfile into the pickit 2 software to load onto my 16F690 I get two errors:
- 1. Sometimes I get "Device Error - Hex File Not Loaded"
- 2. (If I dont get the one above) It loads in, but then the device changes to the 16F882 and then has issues writing it to the PIC.
I have had no issues like this programming my PIC in the past.
Here is the sample code I am using:
Code: | #include <16F690.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#include "flex_lcd420.c"
void main() {
lcd_init(); //Initialise LCD
delay_ms(10);
// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(500);
while(1)
{
// Test the clear screen and newline commands.
// Also test that we can write to all 4 lines.
printf(lcd_putc, "\fThis is the 1st line");
printf(lcd_putc, "\nNext is the 2nd line");
printf(lcd_putc, "\nThis is the 3rd line");
printf(lcd_putc, "\nFinally the 4th line");
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 04, 2011 11:40 am |
|
|
I use Pickit 2 sometimes, and I use it with MPLAB. It works seamlessly.
I don't have to "import" the HEX file. I never have the problem that
you're seeing.
My guess is that maybe you're loading a different HEX file from an old
project, instead of the current project. |
|
|
buler
Joined: 27 Apr 2011 Posts: 10
|
|
Posted: Thu May 05, 2011 7:17 am |
|
|
PCM programmer wrote: | I use Pickit 2 sometimes, and I use it with MPLAB. It works seamlessly.
I don't have to "import" the HEX file. I never have the problem that
you're seeing.
My guess is that maybe you're loading a different HEX file from an old
project, instead of the current project. |
Not sure what the issue was, but it has been resolved. However my LCD screen is now displaying two characters (a "/" and a character I can't make out) to the far right on the first line. I am using the sample code from my post above.
My LCD uses the SPLC780D controller http://www.newhavendisplay.com/app_notes/SPLC780D.pdf
Is this controller compatible with the flex_lcd420.c driver?
Thanks!
EDIT: I have solved this issue and was able to get the defined characters to display. Turns out, I had accidentally assigned the DB4-7 pins backwards in the flex_420.c driver. |
|
|
|