CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Using Combination of Two Ports to interface w/ LCD [SOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
buler



Joined: 27 Apr 2011
Posts: 10

View user's profile Send private message

Using Combination of Two Ports to interface w/ LCD [SOLVED]
PostPosted: Tue May 03, 2011 1:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue May 03, 2011 1:41 pm     Reply with quote

I assume you're using the CCS driver, lcd420.c ? That driver is not set
up to use split ports in the structure. But Mark posted a method to do
that in the Code Library for lcd.c. You can use the same idea to modify
lcd420.c:
http://www.ccsinfo.com/forum/viewtopic.php?t=20182

Or if that's too much trouble then just use the 4x20 Flex lcd driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268
buler



Joined: 27 Apr 2011
Posts: 10

View user's profile Send private message

PostPosted: Wed May 04, 2011 8:09 am     Reply with quote

PCM programmer wrote:
I assume you're using the CCS driver, lcd420.c ? That driver is not set
up to use split ports in the structure. But Mark posted a method to do
that in the Code Library for lcd.c. You can use the same idea to modify
lcd420.c:
http://www.ccsinfo.com/forum/viewtopic.php?t=20182

Or if that's too much trouble then just use the 4x20 Flex lcd driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268


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

View user's profile Send private message

PostPosted: Wed May 04, 2011 11:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 05, 2011 7:17 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group