Altera_Forum
Honored Contributor
13 years agoHelp with basic C code
I want to be able to set the char variable (to be displayed on the LCD) from within the functions (named fx1 and fx2 here).
I'm getting a 'expected expression before ']' token' error. I hope someone can help, i know its probably quite a basic thing to do...#include <stdio.h>
# include "system.h"
# include "altera_up_avalon_character_lcd.h"
# define switches (volatile char*) 0x00101060
char first_row;
void fx1(void)
{
first_row = "fx1";
}
void fx2(void)
{
//first_row = "fx2";
}
int main()
{
int i;
int switch_state = 0;
while(1)
{
lcd();
int switch_state = 0;
for(i = 0; i < 8; i++)
{
if (*switches & (1 << i))
{
switch_state = i;
break;
}
}
switch (switch_state)
{
case 0: fx1(); break;
case 1: fx2(); break;
}
}
return 0;
}
int lcd()
{
alt_up_character_lcd_dev * char_lcd_dev;
// open the Character LCD port
char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0"); /*open device port*/
if ( char_lcd_dev == NULL)/*port opened?*/
printf ("Error: could not open character LCD device\n");
else
printf ("Opened character LCD device\n");
/* Initialize the character display */
alt_up_character_lcd_init (char_lcd_dev);
/* Write in the first row */
alt_up_character_lcd_string(char_lcd_dev, first_row);
}