|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 1:23 pm |
|
|
Ok. I'm assuming the program works with the HD44780 (2x16) model. Nothing happens, the LCD just remains in its power-up state.
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 1:41 pm |
|
|
Look at the LCD schematic on the PicDem2-Plus board.
http://www.cis.upenn.edu/~lee/06cse480/data/picdem2.pdf
It's in the upper left corner of page 16 (page 20 in the Acrobat Reader).
Do you have your LCD wired correctly, as shown in that schematic ?
The schematic shows two ways to set the contrast. You can either
use a 10K trimpot (and set it near the low end of its range), or you
can use two resistors (10K and 300 ohms). In other words, the
contrast voltage should be somewhere between 0 and 0.5 volts.
The proper setting will depend upon your brand of LCD.
Also, make sure that you're using pins DB4-DB7 on the LCD, as the
data bus pins. In 4-bit mode, it's the upper 4 bits of the LCD data
bus that are used. The drivers in the code library use 4-bit mode.
The schematic linked above also uses 4-bit mode.
One more thing. Make sure you call the lcd_init() function at the start
of main(). |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 2:20 pm |
|
|
For the Vee, I have just connected it to Gnd for maximum contrast. (Does it affect?)
Pins DB4-7 have already been wired. I have also called the lcd_init();
My redefined main C program file has the following:
===============================================
#include <picsettings.h>
#include <LCDChar.h>
#include <math.h>
#define PortA_Config1 0x2
#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_B6
#define LCD_DB7 PIN_B7
#define LCD_E PIN_A5
#define LCD_RS PIN_A3
#define LCD_RW PIN_A2
.
.
.
.
.
.
void main()
{
set_tris_a(PortA_Config1);
output_a(0x00);
lcd_init();
}
===============================================
Just for you to note I have included these in the <picsettings.h> file
===============================================
#use delay(clock=4000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
===============================================
For pins DB4-7, I have connected it to pins RB4-7 of the PIC. Please advise...Thanks for answering my queries so far...
PCM programmer wrote: | Look at the LCD schematic on the PicDem2-Plus board.
http://www.cis.upenn.edu/~lee/06cse480/data/picdem2.pdf
It's in the upper left corner of page 16 (page 20 in the Acrobat Reader).
Do you have your LCD wired correctly, as shown in that schematic ?
The schematic shows two ways to set the contrast. You can either
use a 10K trimpot (and set it near the low end of its range), or you
can use two resistors (10K and 300 ohms). In other words, the
contrast voltage should be somewhere between 0 and 0.5 volts.
The proper setting will depend upon your brand of LCD.
Also, make sure that you're using pins DB4-DB7 on the LCD, as the
data bus pins. In 4-bit mode, it's the upper 4 bits of the LCD data
bus that are used. The drivers in the code library use 4-bit mode.
The schematic linked above also uses 4-bit mode.
One more thing. Make sure you call the lcd_init() function at the start
of main(). |
|
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 3:26 pm |
|
|
By the way PCM Programmer, is there a way to check if the PIC is sending out the correct signals? I am thinking of linking it up to an oscilloscope. I welcome any suggestions... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 4:08 pm |
|
|
Are you using #fast_io mode ? You shouldn't do that with this driver.
Don't set the TRIS on port A. Don't output to Port A. Just do the
call to lcd_init(). Also don't let the code fall off the end of main().
Use a test program similar to this. Notice how simple it is.
Code: |
#include <16F876A.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#include "flex_lcd.c"
//==============================
void main()
{
lcd_init();
printf(lcd_putc, "\fHello World\nLine 2");
while(1);
} |
Also, you're using pins B6 and B7 for the LCD. Keep in mind that
your debugger or programmer (ICD, ICD2, etc.) uses those pins.
Notice the #fuses settings. Make sure you have the NOLVP fuse. |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 4:46 pm |
|
|
I did as advised. But still, there isn't anything else showing up.
I have reconfigured the pins to:
====================
#define LCD_DB4 PIN_B0
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_B2
#define LCD_DB7 PIN_B3
====================
So my main file will have the following codes:
====================
#include <16F876A>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000) // 4MHz resonator used
#include "flex_lcd.c"
void main()
{
lcd_init();
printf(lcd_putc, "\fHello World\nLine2");
while (1);
}
====================
Errors during compilation included the following
-------------------------------------
Error 128 "C:\....\flex_lcd.c" Line 27(1,42): A #DEVICE required before this line
-------------------------------------
I know for sure the LCD driver is working as it has the usual blacked out boxes on the first line.
Am really puzzled why. I hope i it isn't the microcontroller that needs replacing...
Listening attentively to your answers....
PCM programmer wrote: | Are you using #fast_io mode ? You shouldn't do that with this driver.
Don't set the TRIS on port A. Don't output to Port A. Just do the
call to lcd_init(). Also don't let the code fall off the end of main().
Use a test program similar to this. Notice how simple it is.
Code: |
#include <16F876A>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#include "flex_lcd.c"
//==============================
void main()
{
lcd_init();
printf(lcd_putc, "\fHello World\nLine 2");
while(1);
} |
Also, you're using pins B6 and B7 for the LCD. Keep in mind that
your debugger or programmer (ICD, ICD2, etc.) uses those pins.
Notice the #fuses settings. Make sure you have the NOLVP fuse. |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 5:00 pm |
|
|
Quote: | Errors during compilation included the following
-------------------------------------
Error 128 "C:\....\flex_lcd.c" Line 27(1,42): A #DEVICE required before this line |
You will get that error if you "added" the Flex_lcd.c file to the list
of source files in MPLAB.
You should only have the main source file listed in the Source Files list.
You can add the Flex_lcd.c file to the "Other Files" section in the Project
files window.
Regarding the black boxes, read this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=27246
Post your compiler version. It's a number such as 3.191, 3.249, 4.018,
etc. You can find it at the top of your .LST file, which is in your project
directly. The "x.xxx" is the complete version number. You don't need
to post any additional numbers that follow after it in the .LST file. |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 5:08 pm |
|
|
Ok, I have corrected the file.
My compiler version is 4.016. I just found some updates for the compiler. So i'm gonna update it now....
I'll check out the link u gave me.
PCM programmer wrote: | Quote: | Errors during compilation included the following
-------------------------------------
Error 128 "C:\....\flex_lcd.c" Line 27(1,42): A #DEVICE required before this line |
You will get that error if you "added" the Flex_lcd.c file to the list
of source files in MPLAB.
You should only have the main source file listed in the Source Files list.
You can add the Flex_lcd.c file to the "Other Files" section in the Project
files window.
Regarding the black boxes, read this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=27246
Post your compiler version. It's a number such as 3.191, 3.249, 4.018,
etc. You can find it at the top of your .LST file, which is in your project
directly. The "x.xxx" is the complete version number. You don't need
to post any additional numbers that follow after it in the .LST file. |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 5:21 pm |
|
|
I have tested the code on a PicDem2-Plus board with PCM vs. 4.016
and it works. |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 5:25 pm |
|
|
Tks...I'm doing my own breadboarding now...Erm, i somehow get the 4 identical error messages
*** Error 12 "C:\...\flex_lcd.c" Line 48(2,10): Undefined identifier delay_ms
Any way to resolve it?
PCM programmer wrote: | I have tested the code on a PicDem2-Plus board with PCM vs. 4.016
and it works. |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 5:33 pm |
|
|
You need to follow my example. Everything in the example is important.
The order of the statements above main() is important.
The #include files must go below the #use delay() statement.
That statement invokes the CCS delay library code. Any #include
files that use delay statements must occur after the #use delay() line.
Put all #include files below that line. (except for the main .H file for
the PIC, which goes as the first line in the file.) Example:
Code: |
#include <16F876A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include "flex_lcd.c"
|
|
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Mon Jan 08, 2007 5:44 pm |
|
|
Ok. I have corrected my programming errors and reconnected all the LCD lines to prevent hardware error....
Just plugged in the PIC to the board and fired it up..........*holds breath*
Nothing's happening...I guess it just might be the microcontroller which has probably died... Just curious, should the resonator not function properly, would it cause the PIC not to work?
I have connected the R/W line to Gnd.
PCM programmer wrote: | You need to follow my example. Everything in the example is important.
The order of the statements above main() is important.
The #include files must go below the #use delay() statement.
That statement invokes the CCS delay library code. Any #include
files that use delay statements must occur after the #use delay() line.
Put all #include files below that line. (except for the main .H file for
the PIC, which goes as the first line in the file.) Example:
Code: |
#include <16F876A>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include "flex_lcd.c"
|
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 5:49 pm |
|
|
Quote: | I have connected the R/W line to Gnd. |
Did you comment out the #define statement which enables that line ?
You need to do that if you connect the LCD's R/W line to ground.
You should comment it out like this. Then re-compile and re-program
the PIC:
Code: | // #define USE_RW_PIN 1 |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 08, 2007 5:58 pm |
|
|
In that case, I suspect a wiring error or some other hardware problem.
Do you know that the PIC works ? Have you ever been able to run
a small program that just blinks an LED ? Here's an example.
This program will blink the LED on pin B0:
Code: |
#include <16F876A.H>
#fuses XT, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//=========================
void main()
{
while(1)
{
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
delay_ms(500);
}
} |
|
|
|
|
|
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
|