Echelon Mini FX User Manual

Page 53

Advertising
background image

40

Mini FX Quick-Start Exercise

4. Add the following code that initializes the I/O devices and writes to the LCD when

the FT 5000 EVB is reset:

void InitializeIO()
{
io_change_init(ioSwitch1);
}

void LcdDisplayString(unsigned row, unsigned column, const char* data);

when(reset) {
InitializeIO();

LcdDisplayString(0,0, "Mini FX QuickStart ");
LcdDisplayString(1,0, "====================");
LcdDisplayString(2,0, "Press SW1 to toggle ");
LcdDisplayString(3,0, "LED1 ");
}

5. Add the following code that writes to the LCD on the FT 5000 EVB:

IO_0 i2c __slow ioIIC;
# define LCD_COMMAND_PREFIX 0xFEu
# define LCD_COMMAND_ON 0x41u
# define LCD_COMMAND_SETCURSOR 0x45u
# define LCD_COMMAND_CLEARSCREEN 0x51u
# define LCD_COMMAND_BRIGHTNESS 0x53u
// The datasheet states the address as 0x50, but the
// 7-bit right-justified address is really 0x28 (0x50 >> 1):
# define I2C_ADDRESS_LCD (0x50u >> 1)

// The SendLcdCommand() function is used within this driver kit.
// The function sends a one- or two-byte command to the display.

void SendLcdCommand(unsigned command, unsigned parameter, unsigned size)
{
unsigned data[3];

data[0] = LCD_COMMAND_PREFIX;
data[1] = command;
data[2] = parameter;

(void)io_out(ioIIC, data, I2C_ADDRESS_LCD, 1+size);
}


void LcdDisplayString(unsigned row, unsigned column, const char* data)
{
// Set the cursor position:
static const unsigned lcdRowAddress[4] = {0x00, 0x40, 0x14, 0x54};
SendLcdCommand(LCD_COMMAND_SETCURSOR, lcdRowAddress[row]+column, 2);
// Send the data:
(void)io_out(ioIIC, data, I2C_ADDRESS_LCD, (unsigned)strlen(data));
}

// The InitializeLCD function enables and clears the display. Call this
// function from InitializeIO() (which in turn is called from when(reset).

// InitializeIO() is called from the when(reset) task and initalizes
// the I/O system and related driver functions.

// display SW1 and LED1 state when on

void DisplayStatus(boolean led, boolean sw)
{
LcdDisplayString(2, 0, “SW1 = ”);

Advertising