Driver for using keypad in AVR - ARM Cortex M
uint8_t Keypad_GetKey(void); /* Function for get pushed key */
void Keypad_Read(CommandFunction_T your_function); /* Function for read keypad and run user command */
#define _KEYPAD_PORT
#define _KEYPAD_PIN
#define _KEYPAD_FIRST_ROW
#define _KEYPAD_SCAN_SPEED
-
In AVR:
DDRB = 0xF0; // 1111 0000
-
Options in AVR:
/* Set your connected port */ #define _KEYPAD_PORT &PORTB #define _KEYPAD_PIN &PINB #define _KEYPAD_FIRST_ROW 0 #define _KEYPAD_SCAN_SPEED 1
-
Options in STM32:
/* Set your connected port */ #define _KEYPAD_PORT GPIOB #define _KEYPAD_PIN GPIOB #define _KEYPAD_FIRST_ROW 14 #define _KEYPAD_SCAN_SPEED 1
void MyFunction(int8_t x)
{
/* ---- x is the pushed key ---- */
if(x == 6)
{
LED_ON();
}
else
{
LED_OFF();
}
}
int main(void)
{
while (1)
{
Keypad_Read(MyFunction);
}
}
void MyFunction(int8_t x)
{
/* ---- x is the pushed key ---- */
sprintf(str, "%u", x); /* cast pushed key number to string */
Lcd_PutString(str); /* show pushed key in the LCD */
}
int main(void)
{
while (1)
{
Keypad_Read(MyFunction);
}
}
uint8_t key_character[16] = {'1' , '2' , '3' , 'A' , '4' , '5' , '6', 'B' , '7' , '8' , '9' , 'C' , '*' , '0' , '#' , 'D'};
void ShowKey(int8_t x)
{
/* ---- x is the pushed key ---- */
Lcd_PutChar(key_character[ch]); /* Show character */
}
int main(void)
{
while (1)
{
Keypad_Read(ShowKey);
}
}
- Run on AVR
- Run on STM32 Fx cores