Hello,
I’m trying to capture/intercept/read the characters being sent to a 4x20 LCD which is set to 4-bit mode.
I need to read every time the Enable line goes high. First nibble then the second nibble to build the 8bit character.
My testing code, needless to say it’s not giving correct results.
- if I correlate the codes to the ascii table its incorrect
- I’m not getting the number of binaries as the number of characters displayed every time the lcd is refreshed.
Im wondering if what I want to do is even possible?
according to this forum it is possible by reading the PORTS directly instead of individual IO.
Read data from LCD (4-bit mode) - Using Arduino / Displays - Arduino Forum
Any ideas would be welcomed.
void Read_LCD(void);
// setup() runs once, when the device is first turned on.
bool LCD_D7_STATE; //lcd is in 4 bit mode
bool LCD_D6_STATE; //lcd is in 4 bit mode
bool LCD_D5_STATE; //lcd is in 4 bit mode
bool LCD_D4_STATE; //lcd is in 4 bit mode
bool LCD_D3_STATE; //lcd is in 4 bit mode
bool LCD_D2_STATE; //lcd is in 4 bit mode
bool LCD_D1_STATE; //lcd is in 4 bit mode
bool LCD_D0_STATE; //lcd is in 4 bit mode
bool nibble = 0; //lcd is in 4 bit mode
char data_char [9];//holds the value D7,D6,D5,D4
#define LCD_D7 A3//data read
#define LCD_D6 A2//data read
#define LCD_D5 A1//data read
#define LCD_D4 A0//data read
#define LCD_E A5//20x4 enable line
void setup() {
// Put initialization like pinMode and begin functions here.
pinMode(LCD_D4, INPUT_PULLDOWN);//lcd 4 bit data mode
pinMode(LCD_D5, INPUT_PULLDOWN);
pinMode(LCD_D6, INPUT_PULLDOWN);
pinMode(LCD_D7, INPUT_PULLDOWN);
pinMode(LCD_E, INPUT_PULLUP);//lcd enable
attachInterrupt(LCD_E, Read_LCD, CHANGE);
}
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
}
void Read_LCD() {
if (nibble == 0){
LCD_D7_STATE = pinReadFast(LCD_D7);
LCD_D6_STATE = pinReadFast(LCD_D6);
LCD_D5_STATE = pinReadFast(LCD_D5);
LCD_D4_STATE = pinReadFast(LCD_D4);
}
if (nibble == 1) {
LCD_D3_STATE = pinReadFast(LCD_D7);
LCD_D2_STATE = pinReadFast(LCD_D6);
LCD_D1_STATE = pinReadFast(LCD_D5);
LCD_D0_STATE = pinReadFast(LCD_D4);
}
Serial.printf ("nibble %d\n" ,nibble);
nibble = !nibble;
sprintf(data_char, "%d%d%d%d%d%d%d%d",LCD_D0_STATE,LCD_D1_STATE,LCD_D2_STATE,LCD_D3_STATE,LCD_D4_STATE,LCD_D5_STATE,LCD_D6_STATE,LCD_D7_STATE);//convert bin data to string
Serial.printf("data_char %s\n",data_char);
}