View previous topic :: View next topic |
Author |
Message |
Guest
|
A numeric expression must appear here |
Posted: Sat Sep 27, 2008 5:12 pm |
|
|
Hi
I have went through the new project wizard, and i've adjusted the project for an 2X16 LCD. When i compile the generated code, an error shows "Undefined identifier k", So i try to declare k as an integer, and i get a new error "A numeric expression must appear here". why i can't declare like the regular C++. Here's the code.
Code: |
#include "D:\My Documents\PIC Projects\LCD Test by CCS\LCD1.h"
#define LCD_ENABLE_PIN PIN_D7
#define LCD_RS_PIN PIN_D5
#define LCD_RW_PIN PIN_D6
#define LCD_DATA_PORT PORTB
#define LCD_TYPE 2
#define LCD_TRIS_LOCATION TRISB
#include <lcd.c>
void main()
{
lcd_init();
lcd_putc("\fReady...\n");
int k; // the "A numeric expression must appear here" appears here
while (TRUE)
{
k=kbd_getc(); //The Undefined error appears here.
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
}
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
// TODO: USER CODE!!
while(true)
{
lcd_putc("\Test Program\n");
delay_ms(1000);
}
}
|
Any Help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 27, 2008 5:28 pm |
|
|
Quote: | void main()
{
lcd_init();
lcd_putc("\fReady...\n");
int k; |
Declare local variables at the beginning of a function. Don't put them
after a few lines of code. |
|
|
Ttelmah Guest
|
|
Posted: Sun Sep 28, 2008 2:29 am |
|
|
As for why you can't declare like C++, this is C, not C++....
Best Wishes |
|
|
abo_shreek11
Joined: 27 Sep 2008 Posts: 10
|
|
Posted: Mon Sep 29, 2008 9:02 am |
|
|
Thanks alot PCM programmer, it worked but I am getting a new error message "Undefined identifier --kbd_getc", can you tell me what would probably be the problem. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Sep 29, 2008 9:41 am |
|
|
Quote: | k=kbd_getc(); //The Undefined error appears here. |
You are trying to call a function that has not been defined. Since the function does not exist the compiler has no idea what you want to do. It, therefore, errors out and wants you to correct the situation.
kbd_getc() is not a function that is part of the compiler. You need to create the function before you can use it.
Ronald |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 29, 2008 12:17 pm |
|
|
Look at this CCS example program. It shows how to do it.
Quote: | c:\program files\picc\examples\ex_lcdkb.c |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Sep 30, 2008 12:56 am |
|
|
Quote: | Declare local variables at the beginning of a function. Don't put them
after a few lines of code. |
As a supplement. Standard C does not allow a variable definition anywhere in the code, but nevertheless within a function, if it's at the begin of a block. Although you may doubt, if it has a particular purpose, this construct is used with some CCS examples.
Regards,
Frank |
|
|
abo_shreek11
Joined: 27 Sep 2008 Posts: 10
|
|
Posted: Tue Sep 30, 2008 10:09 pm |
|
|
Thanks a lot FvM, PCM programmer, rnielsen and Ttelmah.
Here is my final code:
Code: |
#include "D:\My Documents\PIC Projects\LCD Test 4 by CCS\main.h"
#include <LCD.C>
#define LCD_ENABLE_PIN PIN_D7
#define LCD_RS_PIN PIN_D5
#define LCD_RW_PIN PIN_D6
#define LCD_DATA_PORT PORTB
#define LCD_TYPE 2
#define LCD_TRIS_LOCATION TRISB
#include <lcd.c>
void main()
{
lcd_init();
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
lcd_init();
// TODO: USER CODE!!
lcd_putc("\fReady...\n");
}
|
When I compiled, it gives zero errors (finally). But when I power up my circuit, nothing but black squares on the LCD. Here's my connection:
(8-bit interface)
Data Port PORTB
Enable D7
R/W D6
RS D5
I setup this configuration during the project wizard, and I configured the pin direction (Input/Output) during the project wizard also, but no luck. I've tried the Mikroelektronika compiler Mikroc, and everything was fine, the lcd displayed the text, but I don't know why it's not working by CCS compiler.
Any suggestion!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 30, 2008 10:48 pm |
|
|
What LCD driver are you using ? The CCS driver and the Flex driver
are 4-bit drivers, not 8-bit. |
|
|
abo_shreek11
Joined: 27 Sep 2008 Posts: 10
|
|
Posted: Thu Oct 02, 2008 3:10 am |
|
|
Hi
I'm not using any driver, i just connected the 8 pins of portb to the 8 data pins of the lcd. I think the PIC will neglect the upper 4 bit, isn't it. |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 02, 2008 6:25 am |
|
|
The port bit values need to be defined _before_ you include the driver. Otherwise it'll use it's internal defaults.
Best Wishes |
|
|
abo_shreek11
Joined: 27 Sep 2008 Posts: 10
|
|
Posted: Thu Oct 02, 2008 6:40 am |
|
|
Hi Ttelmah
Thanks for your reply, i've commented the first #include<lcd.c>, but i still get the same squares on the lcd. any suggestion? |
|
|
peaps
Joined: 15 Sep 2008 Posts: 11 Location: Hemel Hempstead, Hertfordshire, UK
|
|
Posted: Fri Oct 10, 2008 2:43 pm |
|
|
It might be '\n' characters that get printed to the LCD. I had this same problem. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 10, 2008 3:03 pm |
|
|
He says he's getting blank squares on the LCD. He probably means
the "black squares" problem. This usually means the LCD is not
initialized correctly, either because of the driver or the hardware
connections. There are many threads on this forum about this problem.
Just set the search page to "Search for all terms" and search for this:
Here is one of them:
http://www.ccsinfo.com/forum/viewtopic.php?p=82383 |
|
|
drdelphi
Joined: 22 Apr 2007 Posts: 22 Location: Romania
|
|
Posted: Fri Oct 10, 2008 8:48 pm |
|
|
how do you control the lcd contrast ? did you put some resistors, potentiometer, anything ? |
|
|
|