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

PICDEM 2 PLUS LCD Help!

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



Joined: 12 Oct 2007
Posts: 5

View user's profile Send private message

PICDEM 2 PLUS LCD Help!
PostPosted: Fri Oct 12, 2007 5:06 pm     Reply with quote

Hi, Im having lots of trouble getting my PICDEM 2 PLUS to display things on the LCD!

Im using the following code:

Hello.c
Quote:

#include <18F452>
#fuses H4,NOOSCSEN,NOPROTECT,NOBROWNOUT,NOWDT,NOSTVREN,NOLVP,PUT
#use delay(clock=40000000)

#include "lcd.c"

void main()
{
lcd_init();
for (;;) {
delay_ms(100);
printf(lcd_putc, "\fHello");
printf(lcd_putc, "\nWorld");
}
}


LCD.c
Quote:

#define en pin_d6
#define rw pin_d5
#define rs pin_d4
#use standard_io(a)

// data lines use D port D0-D3
#define get_data() input_d()&0x0F
#define put_data(q) output_d(q&0x0F)
#use standard_io(d)

#define wait() delay_us(4)

int lcd_read_nibble()
{
int p = 0;
output_bit(rw, 1);
wait();
output_bit(en, 1);
wait();
p = get_data();
output_bit(en, 0);
wait();
return p;
}

int lcd_read_byte()
{
int low, high;
high = lcd_read_nibble();
low = lcd_read_nibble();
return ((high <<4>> 4);
lcd_write_nibble(q);
}

void wait_busy()
{
output_bit(rs, 0);
while (bit_test(lcd_read_byte(), 7));
}

void lcd_write_data(int q)
{
wait_busy();
output_bit(rs, 1);
lcd_write_byte(q);
}

void lcd_write_command(int q)
{
wait_busy();
output_bit(rs, 0);
lcd_write_byte(q);
}

int lcd_read_data()
{
output_bit(rs, 1);
return lcd_read_byte();
}

void lcd_clear()
{
lcd_write_command(0x01);
}

void lcd_home()
{
lcd_write_command(0x06);
}

void lcd_backspace()
{
lcd_write_command(0x10);
}

void lcd_panleft()
{
lcd_write_command(0x18);
}

void lcd_panright()
{
lcd_write_command(0x1c);
}

void lcd_set_mode()
{
lcd_write_command(0x28);
}

void lcd_display_on()
{
lcd_write_command(0x0c);
}

void lcd_init()
{
int i;
output_bit(rs, 0);
output_bit(rw, 0);
output_bit(en, 0);
delay_ms(15);
for (i = 1; i <= 3; ++i) {
lcd_write_nibble(0x03);
delay_ms(5);
}
lcd_write_nibble(0x02);
lcd_set_mode();
lcd_display_on();
lcd_home();
lcd_clear();
}

void lcd_gotoxy(int x, int y)
{
int address;
address = x - 1;
if (y != 1)
address |= 0x40;
lcd_write_command(0x80 | address);
}

void lcd_putc(char c)
{
switch (c) {
case '\f':
lcd_clear();
delay_ms(2);
break;
case '\n':
lcd_gotoxy(1, 2);
break;
case '\b':
lcd_backspace();
break;
default:
lcd_write_data(c);
break;
}
}


I've looked at the following Schamatic http://ww1.microchip.com/downloads/en/DeviceDoc/PICDEM%202%20Plus%20RoHS.pdf

And the following user guide http://ww1.microchip.com/downloads/en/DeviceDoc/PICDEM_2_Plus_Users_Guide_51275c.pdf

But Im still stuck! There also seems to be 2 types of PICDEM 2 PLUS boards from what Iv gathered! The older (Red) board with LCD pinouts A1, A2, A3. And the newer (Green) board with LCD pinouts D6, D5, D4.

I have the newer green type board. And im pretty sure that the above shematic and user guide are for my board!

I've also tried using this code that I got from here for my LCD.c file
http://www.ccsinfo.com/forum/viewtopic.php?t=24661

But I'm still not getting anything displayed on the LCD! I'm using MPLAB v7.50 and CCS PIC C Compiler 4.013

Any help appreciated!

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 12, 2007 5:12 pm     Reply with quote

There are instructions at the end of the Flex driver post in the Code
library that explain how to use it with the new PicDem2-Plus board.
Just follow those instructions.
H3rmaN



Joined: 12 Oct 2007
Posts: 5

View user's profile Send private message

PostPosted: Fri Oct 12, 2007 5:44 pm     Reply with quote

thanks, after using your code I can now get something on the LCD, but its not what its supposed to be!

Your code was made for a PIC18F4520, but I am using a PIC18F452!

So I changed a couple of lines as shown below

I changed

Code:
#include <18F4520.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP


to

Code:
#include <18F452.H>
#fuses H4, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP


So instead of displaying

Quote:
Hello World


I get

Quote:
0ooo/0.ooo./?0


Any ideas??

Thanks for the help so far! Iv not been able to display ANYTHING on this LCD till now! Been annoying me for 2 days!
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Fri Oct 12, 2007 8:22 pm     Reply with quote

Try delay_ms(100); before initializing the display
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 12, 2007 8:27 pm     Reply with quote

Make sure the Flex driver has these define statements in it.
Also make sure the line for USE_LCD_RW is commented out.
Code:

// These are the pin assignments used for the "Rohs"
// PicDem2-Plus:
#define LCD_DB4   PIN_D0
#define LCD_DB5   PIN_D1
#define LCD_DB6   PIN_D2
#define LCD_DB7   PIN_D3

#define LCD_E     PIN_D6
#define LCD_RS    PIN_D4
#define LCD_RW    PIN_D5

// The following line must be commented out for
// the "Rohs" board.

// #define USE_LCD_RW   1



Use this as a test program. I assume you have a 10 MHz crystal.
Don't try to run the program in PLL mode at 40 MHz initially.
Try running it at 10 MHz. Also, after programming the PIC, remove
power from the board for a few seconds. The 18F452 must have
the power turned off and then on again, after programming, in order
to activate or de-activate the PLL mode.
Code:

#include <18F452.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 10000000)

#define LCD_POWER  PIN_D7

#include "Flex_LCD.c"

//============================
void main()
{
output_high(LCD_POWER);  // Turn on power to LCD
output_low(LCD_RW);      // Set R/W pin on LCD to a low level

lcd_init();              // Initialize the LCD

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}
Guest








PostPosted: Sat Oct 13, 2007 1:56 am     Reply with quote

PCM programmer wrote:

Use this as a test program. I assume you have a 10 MHz crystal.
Don't try to run the program in PLL mode at 40 MHz initially.
Try running it at 10 MHz. Also, after programming the PIC, remove
power from the board for a few seconds. The 18F452 must have
the power turned off and then on again, after programming, in order
to activate or de-activate the PLL mode.
Code:

#include <18F452>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 10000000)

#define LCD_POWER  PIN_D7

#include "Flex_LCD.c"

//============================
void main()
{
output_high(LCD_POWER);  // Turn on power to LCD
output_low(LCD_RW);      // Set R/W pin on LCD to a low level

lcd_init();              // Initialize the LCD

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}


Thanks mate!! It works!!! Well sort of! Now I get

Quote:
Hello World


on the fist line, but on the second line I get

Quote:
PLine Number 2@


instead of just


Quote:
Line Number 2


Powering it down before running it makes no difference, and neither does adding a 100ms delay before initialising the display!

And my lcd.c file has the proper #define lines of code already (I had to change it before I would even get that "0ooo./....." on the LCD).
H3rmaN



Joined: 12 Oct 2007
Posts: 5

View user's profile Send private message

PostPosted: Sat Oct 13, 2007 2:05 am     Reply with quote

that was me that posted above! I just forgot to login!!

And Iv also just noticed that even if I comment out line 2 of the LCD, I still get that 'P' on screen! But the '@' goes away!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 13, 2007 2:39 am     Reply with quote

1. Are you certain that you have a 10 MHz crystal on the board ?

2. Are you sure that you commented out the following line in the
Flex driver ? (Also make sure there isn't a duplicate line that
comes after it in the file)
Code:
// #define USE_LCD_RW   1
H3rmaN



Joined: 12 Oct 2007
Posts: 5

View user's profile Send private message

PostPosted: Sat Oct 13, 2007 3:13 am     Reply with quote

1. no, im using a 4MHz crystal, but I changed the clock in the code you posted above from '10000000' (10MHz) to '4000000' (4MHz)

2. yes, that line is commented out, and I cant find any duplicate of it in any of the code.

This is the code im using:

Hello.c
Code:
#include <18F452.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#define LCD_POWER  PIN_D7

#include "lcd.c"

//============================
void main()
{
output_high(LCD_POWER);  // Turn on power to LCD
output_low(LCD_RW);      // Set R/W pin on LCD to a low level

lcd_init();              // Initialize the LCD

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}



LCD.c (Flex_lcd.c)
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
Thanks for all the help so far!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 13, 2007 1:25 pm     Reply with quote

Quote:
I'm using MPLAB v7.50 and CCS PIC C Compiler 4.013

I believe that vs. 4.013 is causing the remaining problem.
See this thread. At the end of the first page, he says he upgraded to
a later version and the problem of "extra characters" was fixed:
http://www.ccsinfo.com/forum/viewtopic.php?t=31617
H3rmaN



Joined: 12 Oct 2007
Posts: 5

View user's profile Send private message

PostPosted: Sat Oct 13, 2007 2:38 pm     Reply with quote

ok, cheers mate!

but the strange thing is it doesn't happen all the time!

Like right now I have it running a program to display room temp, and on the 1st line it shows my name, then on the 2nd line it show "Temp = 18C" or whatever temp it is!

And I have no problems with extra characters!

I also made a program to count up in the format "hh:mm:ss" (a bit like a digital clock)

And when its counting up I only see what I want to see on the LCD and no extra characters....
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