View previous topic :: View next topic |
Author |
Message |
siphorob
Joined: 12 Oct 2010 Posts: 12 Location: South Africa
|
Problem using LCD.c |
Posted: Wed Oct 13, 2010 12:46 am |
|
|
I'm using a 16x2 lcd RB0 - RB3 are used for data,
RB4 is unused, ENABLE is connected to RB5, RS is connected to RB6 and rw is connected to RB7.
The LCD does not display anything..
There is the source code.
Code: | #include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
// Un-comment the following define to use port B
#define use_portb_lcd TRUE
struct lcd_pin_map { // This structure is overlayed
int data : 4; // be pin B0.
BOOLEAN unused; // low order up. ENABLE will
BOOLEAN enable; // on to an I/O port to gain
BOOLEAN rs; // access to the LCD pins.
BOOLEAN rw; // The bits are allocated from
} lcd;
#locate lcd = getenv("sfr:PORTB")
#define set_tris_lcd(x) set_tris_b(x)
/*
#if defined use_portb_lcd
#locate lcd = getenv("sfr:PORTB") // This puts the entire structure over the port
#ifdef __pch__
#locate lcd = 0xf81
#else
#locate lcd = 6
#endif
#define set_tris_lcd(x) set_tris_b(x)
#else
//#locate lcd = getenv("sfr:PORTD") // This puts the entire structure over the port
#ifdef __pch__
#locate lcd = 0xf83
#else
#locate lcd = 8
#endif
#define set_tris_lcd(x) set_tris_d(x)
#endif
*/
.
.
.
int main() {
lcd_init();
lcd_putc("Yippee I made my LCD work!");
return 0;
} |
++++++++++++++++++++++
Edited to remove segment of lcd.c
Reason: Forum Rule 10
10. Don't post the CCS example code or drivers, or ask for such code and drivers.
Forum rules -
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
-- Forum Moderator
++++++++++++++++++++++
_________________ Regards,
Brandon |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Oct 13, 2010 2:03 am |
|
|
The compiler automatically puts a sleep instruction as the last instruction of main. You need to put an infinate loop in to stop the pic from going to sleep.
Also remove the return as main has nowhere to return to, Unless you are using some sort of booter.
This has been discussed many times on here:-
Code: |
int main() {
lcd_init();
lcd_putc("Yippee I made my LCD work!");
while(true) {}
}
|
|
|
|
siphorob
Joined: 12 Oct 2010 Posts: 12 Location: South Africa
|
|
Posted: Wed Oct 13, 2010 3:45 am |
|
|
Thanks ,
I'll test the code. _________________ Regards,
Brandon |
|
|
siphorob
Joined: 12 Oct 2010 Posts: 12 Location: South Africa
|
|
Posted: Wed Oct 13, 2010 10:40 am |
|
|
The piece of code still did not work. _________________ Regards,
Brandon |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 13, 2010 11:24 am |
|
|
Try using the Flex lcd driver. It's much easier to get it working:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
Make sure the contrast pin on your LCD (Vo) has about 0.4 volts on it.
This contrast voltage will allow you to see characters on the LCD. |
|
|
siphorob
Joined: 12 Oct 2010 Posts: 12 Location: South Africa
|
|
Posted: Wed Oct 13, 2010 1:08 pm |
|
|
Thank you, thank you.
The is the best fourm ever _________________ Regards,
Brandon |
|
|
|