Board: STM NUCLEO-F411RE
Libraries used:
mbed.h
Keypad.h (keypad | Mbed)
TextLCD (TextLCD - TextLCD library for controlling various LCD panel… | Mbed)
Warning: ‘wait_ms’ is deprecated: ‘wait_ms’ is deprecated in favor of explicit sleep functions. To sleep, ‘wait_ms’ should be replaced by ‘ThisThread::sleep_for’ (C++) or ‘thread_sleep_for’ (C). If you wish to wait (without sleeping), call ‘wait_us’. ‘wait_us’ is safe to call from ISR context. [since mbed-os-5.14] [-Wdeprecated-declarations] in “main.cpp”, Line: 44, Col: 5
When I compile there are no errors, only warnings for the deprecated functions. After I upload the program to the board, the LCD is blank and even when I press on the keypad, it is still blank. Please help to troubleshoot this.
The program:
// AES_C - LCD display with keypad calc
#include "mbed.h"
#include "TextLCD.h"
#include "Keypad.h"
volatile int flag;
unsigned int Index;
TextLCD lcd(PC_0, PC_1, PC_2, PC_3, PC_4, PC_5); // rs, e, d4-d7
// keypad interface
// r0 r1 r2 r3 c0 c1 c2 c3
Keypad keypad(PC_9, PC_8, PC_7, PC_6, PC_13, PC_12, PC_11, PC_10);
// The character table
char KeyTable[ ] =
{
'1', '2', '3', '+', // r3
'4', '5', '6', '-', // r2
'7', '8', '9', '*', // r1
'C', '0', 'E', '/', // r0
};
// c3 c2 c1 c0
unsigned int KeyPadISR(unsigned int index)
{
Index = index; //check the index is another variable
flag = 1;
return 0;
}
void LCDClear()
{
lcd.cls();
wait_ms(500); // millisecond
}
void LCDCursor(int column, int row)
{
lcd.locate(column, row);
wait_ms(500); // millisecond
}
int Calculate(int n)
{
int total = 0;
lcd.printf("No %d: ", n);
while(1)
{
if (flag == 1)
{
if(KeyTable[Index] != 'E')
{
total = total*10+KeyTable[Index] - '0';
lcd.printf("%c", KeyTable[Index]);
flag = 0;
}
else
{
flag = 0;
break;
}
}
// if (flag == 0)
//break;
}
return total;
}
// Main Program
int main()
{
int no1, no2, res;
char Op;
//lcd.printf("Hello World!\n");
//wait_ms(5000); // millisecond
keypad.attach(&KeyPadISR); // replaced it with attach
keypad.start();
wait_ms(1000); // millisecond
while(1)
{
LCDClear();
lcd.printf("CALCULATOR");
wait_ms(5000); // millisecond
LCDClear();
LCDCursor(0, 0);
no1 = Calculate(1);
LCDCursor(0, 1);
no2 = Calculate(2);
LCDClear();
LCDCursor(0, 0);
lcd.printf("Op: ");
while(1)
{
if(flag == 1)
{
Op = KeyTable[Index];
flag = 0;
break;
}
}
switch(Op)
{
case '+':
res = no1 + no2;
break;
case '-':
res = no1 - no2;
break;
case '*':
res = no1 * no2;
break;
case '/':
res = no1 / no2;
break;
}
LCDCursor(0, 0);
lcd.printf("%c ", Op);
LCDCursor(0, 1);
lcd.printf("Res = %d", res);
wait_ms(5000); // millisecond
}
}