From ecd33bd78e0caef597d3bad272ac239ffda74d24 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 31 Dec 1999 19:51:10 -0500 Subject: first LCD support --- lcd.c | 304 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 304 insertions(+) create mode 100644 lcd.c (limited to 'lcd.c') diff --git a/lcd.c b/lcd.c new file mode 100644 index 0000000..79b39a9 --- /dev/null +++ b/lcd.c @@ -0,0 +1,304 @@ +#include "i2c.h" +#include "lcd.h" +#include +#include +#include + +#define LCD_ENABLE 0x03 /* the 4x40 LCDs have two enable lines - 0x03 enables both at the same time */ +#define LCD_DATA_RAM 128 /* display RAM, in the LCD ICs */ +#define LCD_CG_RAM 64 /* custom character RAM, in the LCD ICs */ + +#define LCD_chars_total 160 +#define LCD_cols 40 +#define LCD_rows 4 /* 4x40 LCD */ + +char LCD_Data[LCD_rows][LCD_cols]; /* shadow copy of LCD display in local RAM, to minimize slow I2C writes */ + +/*** EndHeader */ + + +static void break_up_string (char *in_string, int N, char *str1, char *str2, char *str3) +{ + +#define SUBSTRING_CNT 3 + + int input_length; + int j, k, copypos; + int n; + + char *copy_input; + char *p; + + j=k=copypos=0; + input_length=strlen(in_string); + copy_input = g_strdup(in_string); + + for (j=0; jinput_length) { + break; + } + if ((*(copy_input+k)==' ')&&(copypos=N) { + break; + } + } else { + // No more spaces. Does the last chunk of text fit? + if (strlen(copy_input+k+1)>N-k) { + break; + } + } + } + // valid character, copy to output string + *(interm_str+k)=*(copy_input+k); + + } + // remove processed part from the input + if (copypos<=input_length) { + strcpy(copy_input, in_string+copypos); + } + n = strlen(interm_str); + for (k=n-1; k=0; k--) { //trim space + if (*(interm_str+k)==' ') { + *(interm_str+k)=0; + } else { + break; + } + } + switch (j) { + case 0: + strcpy(str1,interm_str); + break; + case 1: + strcpy(str2,interm_str); + break; + case 2: + strcpy(str3,interm_str); + break; + } + free(interm_str); + + } + + g_free(copy_input); +} + + + + +void LCD_clear() +{ + char i; + char j; + + I2C_Write(PCF8574A+LCD_Port, 0x00 | LCD_ENABLE); + I2C_Write(PCF8574A+LCD_Port, 0x00); + I2C_Write(PCF8574A+LCD_Port, 0x10 | LCD_ENABLE); + I2C_Write(PCF8574A+LCD_Port, 0x10); + + /* wait 1.64ms */ + g_usleep(1640); + + for (i=0; i<4; ++i) + for (j=0; j<40; ++j) { + LCD_Data[i][j]=0; + } + + return; +} + + +static void LCD_RAM_write(int RAM_start,int row, int col, char *LCD_string) +{ + /* rows: 0-3, cols: 0-39 */ + +#define data_level 0x04 + + int i; + int cur_row, cur_col; + int String_length; + char char_out, enable_one_lcd; + int ram_location; + char last_op_a_write; + + String_length=strlen(LCD_string); + enable_one_lcd=0x02; + + last_op_a_write=0; + cur_row=row; + cur_col=col; + + if (cur_row<2) { + enable_one_lcd=0x02; + } else { + enable_one_lcd=0x01; + } + + /* write out the string */ + for (i=0; i