





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






1
#include <stdio.h> #include "system.h"
int main ( void ) { FILE* LCD;
LCD = fopen ("/dev/lcd", "w");
if (LCD == NULL ) { fprintf(stderr, "open failed\n"); return 0; }
fprintf(LCD, "This is LCD demo\n"); fprintf(LCD, "Altera HAL usage");
fclose (LCD);
return 0; }
Code 1: Example utilization of LCD with Altera’s HAL device interface
1 A hardware abstraction layer (HAL) is an abstraction layer, implemented in software, between the physical hardware of a computer and the software that runs on that computer. Its function is to hide differences in hardware from most of the operating system kernel, so that most of the kernel-mode code does not need to be changed to run on systems with different hardware [Ref: http://www.wikipedia.org]
void LCD_init() { usleep(15000); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT;
usleep(4100); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT;
usleep(100); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT;
while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_FUNC | LCD_OPT_FUNC_8BIT | LCD_OPT_FUNC_TWO_LINE | LCD_OPT_FUNC_BIGFONT;
while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_ENABLE;
while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_CLEAR;
while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_MODE | LCD_OPT_MODE_INC;
while ( LCD->read_data & LCD_BUSY ); usleep(100); LCD->write_cmd = LCD_CMD_ENABLE | LCD_OPT_ENABLE_DISP | LCD_OPT_ENABLE_CURSOR | LCD_OPT_ENABLE_BLINK; }
#define LCD_CMD_FUNC 0x20 // function set
main() { LCD_init();
while(1) { LCD_puts(“hello world”); } }
void LCD_puts(char s) { while (s) LCD_write_data(*s++); }
static void LCD_write_cmd (byte cmd) { LCD->write_cmd = cmd; }
static byte LCD_read_cmd (void) { return LCD->read_cmd ; }
static void LCD_write_data (byte data) { LCD->write_data = data; }
static byte LCD_write_cmd (void) { return LCD->read_data ; }
Command Register (write)
Status Register (read)
Data Register (write)
Data Register (read)
Low level Access
Functionality exposed to application via header file (LCD.h)