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 support@ccsinfo.com

working with functions

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







working with functions
PostPosted: Mon Mar 30, 2009 5:54 pm     Reply with quote

I am using a function to read a keypad. Then I want to send the value read in my main function. If make the function return a char to main. In main I can then send this char.

But I keep getting

"a numeric expression must appear here! at the this instruction in the main

char z;

pls find the attached code below thanks
Code:

#include<16f873.h>
#use delay(clock = 4000000)
#fuses xt, nolvp, nowdt
#include<lcd_driver_code.c>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=E, BITS=8, stream=PIC)

#define B1 Pin_B1
#define B2 pin_B2
#define B3 pin_B3

char keypad_read_display(void){ //function definition/declaration
   char k;
   int value;

   output_low(B1); output_high(B2); output_high(B3);
   value=input(pin_b4)+(input(pin_b5)*2)+(input(pin_b6)*4)+(input(pin_b7)*8);
   switch(value){
      case 0XF: break;
      case 0XE: k = '1'; break;
      case 0XD: k = '4'; break;
      case 0XB: k = '7'; break;
      case 0X7: k = '*'; break;
      default: }

   output_high(B1); output_low(B2); output_high(B3);
   value=input(pin_b4)+(input(pin_b5)*2)+(input(pin_b6)*4)+(input(pin_b7)*8);
   switch(value){
      case 0XF: break;
      case 0XE: k = '2'; break;
      case 0XD: k = '5'; break;
      case 0XB: k = '8'; break;
      case 0X7: k = '0'; break;
      default: }

   output_high(B1); output_high(B2); output_low(B3);
   value=input(pin_b4)+(input(pin_b5)*2)+(input(pin_b6)*4)+(input(pin_b7)*8);
   switch(value){
      case 0XF: break;
      case 0XE: k = '3'; break;
      case 0XD: k = '6'; break;
      case 0XB: k = '9'; break;
      case 0X7: k = '\#'; break;
      default: }

   //printf(lcd_putc,"\f %c", key);
   }

      main(char){
      lcd_init();
      set_tris_b(0XFF);
      port_b_pullups(TRUE);
       char z;//i get error at this line, numeric constant must appear
     
      char k;
      while(1){
         keypad_read_display();
         putchar(z);
         delay_ms(100);}}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 30, 2009 6:14 pm     Reply with quote

Quote:
main(char){

main() doesn't take any parameters in this compiler. There is no argc
and argv. Don't assume that everything in MSVC is transportable to CCS.


Quote:
main(char){
lcd_init();
set_tris_b(0XFF);
port_b_pullups(TRUE);
char z;//i get error at this line, numeric constant must appear

char k; while(1){
keypad_read_display();
putchar(z);
delay_ms(100);}}

Don't put variable declarations within code, with this compiler. Put them
at the start of a function. In this case, they go above the lcd_init() line.


Quote:
If make the function return a char to main

You need to buy a book on C and study how a function returns a value
to the caller. It's not really our job to teach this. This forum is about
teaching the oddities of the CCS compiler (amongst other things).
It's assumed that you know basic C.
Guest








PostPosted: Mon Mar 30, 2009 6:22 pm     Reply with quote

Thank you.

I moved the putchar into function and it works now.

Points noted
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