View previous topic :: View next topic |
Author |
Message |
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
LCD configuration |
Posted: Mon Aug 23, 2010 12:33 am |
|
|
Hello,
Am using LCD with pic16f877. I was trying a small example to be sure that it works but the compiler displays many errors and I don't know where the problem is...
This is my code:
Code: |
#include "LCD.c"
#include <16f877.h>
#use delay(clock = 4000000)
main()
{
lcd_init();
lcd_putc("hisham");
}
|
Where the file LDC.c is the driver installed with the ccs compiler. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Mon Aug 23, 2010 2:08 am |
|
|
The processor include, _must_ be first.
Similarly the clock definition, must be before you include anything that uses the clock.
You also need fuse definitions to setup the chip.
Then remember, that in CCS, if the code goes 'off the end', there is no operating system to 'return' to.
Hence your code should remain 'inside' what you are doing.
Change your file to:
Code: |
#include <16f877.h> //Should always be the _first_ include
//Where are your FUSE defintions?. You need to tell the compiler
//How to setup the chip - assuming you have a 4MHz crystal
#fuses XT, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP
#use delay(clock = 4000000) //Must be before anything that uses 'times'
//Now include the LCD driver
#include "LCD.c"
main() {
lcd_init();
lcd_putc("hisham");
while (TRUE) ; //Keep the code from dropping off the end.
}
|
Best Wishes |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Mon Aug 23, 2010 6:35 am |
|
|
Thanks for your reply,
i tried your code, but i still get the following code errors..
*** Error 23 "C:\Program Files (x86)\PICC\devices\16f84.h" Line 2(8,9): Can not change device type this far into the code
*** Error 48 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 43(1,24): Expecting a (
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 43(5,6): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 43(6,7): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 43(7,8): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 44(1,6): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 44(6,7): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 44(7,8): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 44(8,9): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 45(1,2): Expecting a declaration
*** Error 28 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 47(21,22): Expecting an identifier
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 47(22,23): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 48(1,2): Expecting a declaration
*** Error 43 "C:\Program Files (x86)\PICC\drivers\LCD.c" Line 49(1,2): Expecting a declaration
*** Error 90 "prog.c" Line 13(21,22): Attempt to create a pointer to a constant
15 Errors, 0 Warnings |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1938 Location: Norman, OK
|
|
Posted: Mon Aug 23, 2010 6:50 am |
|
|
You did not try it exactly as it is posted because it compiles just fine for me.
This line:
Code: | *** Error 23 "C:\Program Files (x86)\PICC\devices\16f84.h" Line 2(8,9): Can not change device type this far into the code |
says you changed the device type to a 16F84. Why did you do that??
To get the program to compile for a 16F84 you need to remove
just the NOBROWNOUT and NOLVP fuses from the end of the line. (that's all you need to do)
The above message indicates you have some other line prior to the processor declaration
which is not allowed. The processor declaration MUST be the first line in the file.
What version of the CCS compiler are you using?
The version will be in the format 3.xxx or 4.xxx (e.g. 3.249 or 4.109) _________________ Google and Forum Search are some of your best tools!!!! |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Mon Aug 23, 2010 10:32 am |
|
|
I created a project according to the tutorial in the following link using mplab :
http://www.ccsinfo.com/faq.php?page=ccs_mplab
and set the micro controller to pic16f877
and then i wrote the previous code, but i got the previous error i don't know why pic16f84A!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Mon Aug 23, 2010 10:55 am |
|
|
Could MPLAB be picking up a .h file that is listed in the project window but not explicitly called out in the .c file? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 23, 2010 11:14 am |
|
|
No, MPLAB ignores any .h files that you add to the Header Files section
of the Project Window. It doesn't try to compile them just because
they are in the list. |
|
|
hisham.i
Joined: 22 Aug 2010 Posts: 43
|
|
Posted: Mon Aug 23, 2010 12:30 pm |
|
|
My problem was in the driver code, I added few lines of code so the driver was not working properly. When I deleted the modifications the code works properly...
Thank you |
|
|
|