markocrni
Newbie level 4
I receive an Illegal pointer conversion error, with this lines Glcd_Write_Text(menu[from].text, 10, line_cnt, 1);. Any sugestions? THX.
Code:
void start();
unsigned char selected = 0;
// glcd pinout settings
char GLCD_DataPort at PORTD;
sbit GLCD_CS1 at RB0_bit;
sbit GLCD_CS2 at RB1_bit;
sbit GLCD_RS at RB2_bit;
sbit GLCD_RW at RB3_bit;
sbit GLCD_EN at RB4_bit;
sbit GLCD_RST at RB5_bit;
sbit GLCD_CS1_Direction at TRISB0_bit;
sbit GLCD_CS2_Direction at TRISB1_bit;
sbit GLCD_RS_Direction at TRISB2_bit;
sbit GLCD_RW_Direction at TRISB3_bit;
sbit GLCD_EN_Direction at TRISB4_bit;
sbit GLCD_RST_Direction at TRISB5_bit;
typedef const struct MenuStructure{
const char *text;
unsigned char num_menupoints;
unsigned char up;
unsigned char down;
unsigned char enter;
void (*fp)(void);
}MenuEntry;
const char menu_000[] = "[Osnovni meni]"; //0
const char menu_001[] = "Opcija 1"; //1
const char menu_002[] = "Opcija 2"; //2
const char menu_003[] = "Opcija 3"; //3
const char menu_004[] = "Opcija 4"; //4
const char menu_005[] = "Opcija 5"; //5
const char menu_006[] = "Opcija 6"; //6
const char menu_007[] = "Opcija 7"; //7
const char menu_008[] = "Opcija 8"; //8
const char menu_009[] = "START"; //9
const char menu_100[] = "[Opcija 1]"; //10
const char menu_101[] = "Sub opcija1"; //11
const char menu_102[] = "Sub opcija2"; //12
const char menu_103[] = "Sub opcija3"; //13
const char menu_104[] = "Sub opcija4"; //14
const char menu_105[] = "Sub opcija5"; //15
const char menu_106[] = "nazad"; //16
MenuEntry menu[] = {
{menu_000, 10, 0, 0, 0, 0},
{menu_001, 10, 1, 2, 11, 0},
{menu_002, 10, 1, 3, 2, 0},
{menu_003, 10, 2, 4, 3, 0},
{menu_004, 10, 3, 5, 4, 0},
{menu_005, 10, 4, 6, 5, 0},
{menu_006, 10, 5, 7, 6, 0},
{menu_007, 10, 6, 8, 7, 0},
{menu_008, 10, 7, 9, 8, 0},
{menu_009, 10, 8, 9, 9, start},
{menu_100, 7, 0, 0, 0, 0},
{menu_101, 7, 11, 12, 11, 0},
{menu_102, 7, 11, 13, 12, 0},
{menu_103, 7, 12, 14, 13, 0},
{menu_104, 7, 13, 15, 14, 0},
{menu_105, 7, 14, 16, 15, 0},
{menu_106, 7, 15, 16, 1, 0},
};
void show_menu(void){
unsigned char line_cnt = 0;
unsigned char from = 0;
unsigned char till = 0;
unsigned char tmp = 0;
while(till <= selected){
till += menu[till].num_menupoints;
}
from = till - menu[selected].num_menupoints;
till--;
tmp = from;
if(selected>=(from+2) && selected<=(till-1)){
from = selected - 2;
till = from + 3;
for(from;from<=till;from++){
Glcd_Write_Text(menu[from].text, 10, line_cnt, 1);
line_cnt++;
}
Glcd_Write_Text(">", 0, 2, 1);
}
else{
if(selected<(from+2)){
till = from +3;
for(from;from<=till;from++){
Glcd_Write_Text(menu[from].text, 10, line_cnt, 1);
line_cnt++;
}
Glcd_Write_Text(">", 0, 2, 1);
}
if(selected==till){
from = till - 3;
for(from;from<=till;from++){
Glcd_Write_Text(menu[from].text, 10, line_cnt, 1);
line_cnt++;
}
Glcd_Write_Text(">", 0, 3, 1);
}
}
}
void browse_menu(void){
do{
show_menu();
if(Button(&PORTA, 0, 5, 1)){
selected = menu[selected].up;
}while(RA0_bit);
if(Button(&PORTA, 3, 5, 1)){
selected = menu[selected].down;
}while(RA0_bit);
if(Button(&PORTA, 2, 5, 1)){
if(menu[selected].fp != 0){
menu[selected].fp();
}
selected = menu[selected].enter;
}while(RA0_bit);
}while(1);
}
void start(void){
Glcd_Write_Text("Start working", 0, 0, 1);
}
void main(){
ADCON1 = 0x0F;
Glcd_Init(); // Initialize GLCD
browse_menu();
}