Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Cannot pass char parameter to a function.

Status
Not open for further replies.

Francesco cembrola

Newbie level 6
Newbie level 6
Joined
Jul 22, 2006
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,362
The code below works OK.
It calles the function 'text_pos' an passes ascii caracters to it.
Then 'text_pos' convert them to ascii codes.
These are send to the I2C interface to controll an LCD display.
These characters represent the cursor coordinates on the LCD display

However I need to modify the code to pass parameters like : text_pos ('34',65'), (two digits).
otherwise I can only get the coordinates up to 9X,9Y.

If I call the function like: text_pos('10','12'), how do I read each of the digit indivually?

I need to assign something like: int X0= first digit of row. int X1= second digit of row.
int Y0=first digit of col. int Y1 = second digit of col.

Do i need to declare two arrayes in the function?
I have tried some experiments with out success.

Can you please help to modify the code?

Thank you.:-?




Code:
#include <p18F26k22.h>
#include <stdlib.h>
#include <delays.h>
#include <stdio.h>
#include <I2C.h>
#include <string.h>

void text_pos(char row, char col);

int xpos=0;
int ypos=0;

void main(void)
{ 

text_pos('5','9');  // call function to set cursor coordinates

}


void text_pos(char row,char col)

}  
xpos=col;// convert char to int
// xpos second digit

ypos=row; 
// ypos second digit
 
StartI2C2();  
putcI2C2(0x64);   //device address
putcI2C2(27);     //esc
putcI2C2(91);     // [ 
putcI2C2(ypos);   //row

// putcI2C2(ypos);// need here the second digit for y pos

putcI2C2(59);     // ;
putcI2C2(xpos);   // column
// putcI2C2(xpos2); //need here the second digit for X pos

putcI2C2(72);      // H 
Delay10KTCYx(100);   
StopI2C2();
     
 }
 

You can only pass an array pointer to the function (this is C right?)
Code:
char my_array[]="123456";

void my_function(char *array_p)
{
char a,b,c;

  a=array_p[0];    // this is the first char of the array
  b=array_p[1];    // this is the second char of the array
  c=array_p[2];    // this is the third char of the array
}

Call it using
Code:
my_function(my_array);

If you want you can use two or more pointer parameters
 

You can only pass an array pointer to the function (this is C right?)
Code:
char my_array[]="123456";

void my_function(char *array_p)
{
char a,b,c;

  a=array_p[0];    // this is the first char of the array
  b=array_p[1];    // this is the second char of the array
  c=array_p[2];    // this is the third char of the array
}

Call it using
Code:
my_function(my_array);

If you want you can use two or more pointer parameters



Hi thank you for the speedy replay.
I think you have over estimated my knoledge of C.

I do understand the first part of your code.

But I still don get it how to read those digits once they have been passed to the function.

Regards

Francesco
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
char my_array[]="123456";   // I declare an array
 
void my_function(char *array_p)  // declaring a function that takes a char pointer as a parameter
{
char a,b,c;  // declare local char variables a,b,c
 
  a=array_p[0];    // assign to a the first character of the array (in this example '1')
  b=array_p[1];    // assign to a the second character of the array  (in this example '2')
  c=array_p[2];    // assign to a the third character of the array  (in this example '3')
}
 
my_function(my_array);  // call the function using the address of the first character of the array, my_array is the same as &my_array[0]

 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
char my_array[]="123456";   // I declare an array
 
void my_function(char *array_p)  // declaring a function that takes a char pointer as a parameter
{
char a,b,c;  // declare local char variables a,b,c
 
  a=array_p[0];    // assign to a the first character of the array (in this example '1')
  b=array_p[1];    // assign to a the second character of the array  (in this example '2')
  c=array_p[2];    // assign to a the third character of the array  (in this example '3')
}
 
my_function(my_array);  // call the function using the address of the first character of the array, my_array is the same as &my_array[0]



Hi alex,

thanks agoin for the replay.
I will be modifying may code tomorrow following your example. I will post my outcome.

regards

francesco:)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top