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 CCS Technical Support

A numeric expression must appear here

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








A numeric expression must appear here
PostPosted: Sat Sep 27, 2008 5:12 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 27, 2008 5:28 pm     Reply with quote

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







PostPosted: Sun Sep 28, 2008 2:29 am     Reply with quote

As for why you can't declare like C++, this is C, not C++.... Smile

Best Wishes
abo_shreek11



Joined: 27 Sep 2008
Posts: 10

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 29, 2008 9:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 9:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 12:17 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 12:56 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Sep 30, 2008 10:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 10:48 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 02, 2008 3:10 am     Reply with quote

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







PostPosted: Thu Oct 02, 2008 6:25 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 02, 2008 6:40 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 10, 2008 2:43 pm     Reply with quote

It might be '\n' characters that get printed to the LCD. I had this same problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 10, 2008 3:03 pm     Reply with quote

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:
Quote:
LCD black squares

Here is one of them:
http://www.ccsinfo.com/forum/viewtopic.php?p=82383
drdelphi



Joined: 22 Apr 2007
Posts: 22
Location: Romania

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Oct 10, 2008 8:48 pm     Reply with quote

how do you control the lcd contrast ? did you put some resistors, potentiometer, anything ?
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