- Drive a LCD through a HD44780 controller connected to a PCF8574 TWI
This example shows how HWA deals with external hardware. Here, a HD44780-based LCD controller is driven through a PCF8574 I²C bus expander connected to a two-wire interface (TWI). The TWI can be embedded into the MCU or software-emulated.
- config.h
#include BOARD_H
#if HW_ADDRESS(twi0) != -1
# define TWI twi0
#else
# define TWI HW_SWTWIMASTER( scl, (portc,5), \
sda, (portc,4), \
bps, TWI_BPS )
#endif
#define TWI_BPS 100000
#define LCD HW_HD44780( lines, 2, \
cols, 16, \
e, (PCF, 1, 2), \
rs, (PCF, 1, 0), \
rw, (PCF, 1, 1), \
data, (PCF, 4, 4) )
#define PCF HW_PCF8574( interface, TWI, address, 0x27 )
#define LCD_LED (PCF, 1, 3)
- main.c
#include "config.h"
#include "xprintf.h"
int main(void)
{
hw( configure, TWI, bps, TWI_BPS );
init, yes,
display, on ,
cursor, off,
blink, off,
shift, cursor,
direction, right );
while(1) {
int i = 0;
int line = 0;
for(i=0; i<1000 ; i++) {
if ( line == 0 ) {
hw( gotoxy, LCD, 0, line );
xprintf(
HW(LCD,putchar),
" g=%3d", i);
}
else {
hw( gotoxy, LCD, 8, line );
xprintf(
HW(LCD,putchar),
" g=%03d", i);
}
line++;
line %= 2;
}
}
}