• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Function Pointers

Status
Not open for further replies.

TucsonDon

Member
I have a function to write a location to a LCD
the prototype:
C:
void LCDMove(unsigned char row,unsigned char column);
and have defined location in the header as follows:
C:
#define POS1 LCDMove(1,1)
#define POS2 LCDMove(2,1)
#dfine POS3 LCDMove(3,1) ect….
I issue that I have is that I have a function to display text on the lcd:
C:
void TextDisplay(void)
{
sprint(buff, "%s", Text);
while(busyXLCD());
-postion-
putsXLCD(buff);
repeat several times
}
I need to make "-postion-" a variable that changes with the text that I am displaying.
 

dknguyen

Well-Known Member
Most Helpful Member
It is unclear what you want. Do you want to pass a pointer to a function as an argument? Or do you actually want to call a function through a pointer?
 

Pommie

Well-Known Member
Most Helpful Member
I'm guessing at what you're trying to do. If I'm right, you can just use LCDmove (position,1) where you have -position-.

Mike.
 

TucsonDon

Member
I have called the function and argument in the header definition. This is for a sub menu so the layout is changed based on the parent menu, so I want to be able to point to the definition and then "plug them into" the function in place of "-postion-"
 

Pommie

Well-Known Member
Most Helpful Member
I was going to point you towards a previous discussion on this but when I checked that was your thread too! Did that not help?

Mike.
 

TucsonDon

Member
I was going to point you towards a previous discussion on this but when I checked that was your thread too! Did that not help?

Mike.
it worked perfectly, I am using in this function but I need to set the address on the LCD
 

Pommie

Well-Known Member
Most Helpful Member
Add the position at the start of your menu entries and in the function get the row and column with something like,
Code:
    row=*point++;
    column=*point++;
    LCDmove(row,column);
    while(*point)
        LCDchar(*point++);
You add the position to the string by adding hex values, menu[]="\x01\x02This is at position 1,2" etc.

Mike.
 
Last edited:

TucsonDon

Member
C:
void LCDMove(unsigned char row,unsigned char column);
void (*PLCDMove) (char);
        PLCDMove = &LCDMove;
C:
#define POS1 (1,1)
#define POS2 (2,1)
#dfine POS3 (3,1)

char Mode, ModeOn, ModeOff;

C:
Mode = POS1
void TextDisplay(void)
{
sprint(buff, "%s", Text);
while(busyXLCD());
(PLEDMove) (Mode)
putsXLCD(buff);
repeat several times
}
This will point to the function but it is not passing the whole argument.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top