Lab 11
Lab 11
Reg No FA18-BEE-121-E
LAB #11
This Lab has been designed to familiarize with STM keypad interface
and manipulation.
Objectives
To explain the working of 4x3 keypad interfacing with the STM32F407 using trainer board and modify
the program and display its output on STM32F407 trainer board using C programming.
Methodology
This Lab consisted of interfacing of STM Keypad its operation and programming. The basic
objective was to manipulate the Keypad to display a desired number. The keypad is used widely in
different applications due to its ease and it is used where limited information needs to be fed. The basic
structure of the keypad is it has four rows and three columns . The keypad module is constructed in
the form of a matrix. Basically, the matrix act as switches that complete the circuit and allow the
flow of current. As the current flows through the circuit the corresponding digit appears on the
LCD that is interfaced with the keypad. The keypad module has 12 keys configured in a 4x3
matrix. In order to determine whether a key has been pressed, logic 0 is sent along each of the row
connections. The column connections are then monitored to see if any go low. By knowing which
combination of row and column has been connected, it is then possible to determine which switch
has been pressed. The pre lab consisted of displaying a digit after pressing a key and displaying
the corresponding digit on to the LCD. The in-lab task was to write a complete C program that
will interface a keypad with STM32F4 microcontroller and continuously scans it. Whenever a key
is pressed, the corresponding character will be displayed on the 7-Segment. The final task was to
interface the 8 x 3 matrix keypad with STM32F4 microcontroller in such a way, that the output of
the keypad is shown on two 7 segment display. The tasks were to be completed and the results
were to be verified. .
Conclusion
The lab helped further understand the use of STM Trainer Board and the interfacing of LCD, 7
segment and keypad. The Lab also helped in the understanding of selection procedure of the digits
when a button is pressed, and the science involved in the functioning and interfacing of the keypad
with the LCD and 7 segment the results after changing the codes were observed. All the Lab Tasks
were completed. Observations were made and the results were verified
Lab tasks
Task 1
/*----------------------------------------------------------------------------
Pre-LAB-11 Lab Task-1 (Keypad Interfacing)
*----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stm32f4xx.h>
void lcd_ini(void);
void lcd_data(char j);
void lcd_cmd(char i);
char keypad(void);
volatile uint32_t msTicks; /* counts 1ms timeTicks */
/*----------------------------------------------------------------------------
SysTick_Handler
*----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
msTicks++;
}
void Delay (uint32_t dlyTicks) {
uint32_t loop=0,dly=0,loope=0;
dly = dlyTicks ;
for(loop=0;loop<dly;loop++){
for(loope=0;loope<29000;loope++){
__nop();
}
}
}
unsigned long LCDDATA=0;
unsigned long op=0;
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main (void) {
SystemCoreClockUpdate(); // Get Core Clock Frequency
RCC->AHB1ENR |= (1 << 1) ; // Enable GPIOB clock
RCC->AHB1ENR |= (1 << 3) ; // Enable GPIOD clock
RCC->AHB1ENR |= (1 << 4) ; // Enable GPIOE clock
GPIOB->MODER = 0x00000005;
GPIOB->OTYPER = 0x00000003;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;
GPIOD->MODER = 0x00005110;
GPIOD->OTYPER = 0x00000000;
GPIOD->OSPEEDR = 0xAAAAAAAA;
GPIOD->PUPDR = 0x00000000;
GPIOE->MODER = 0x55555555;
GPIOE->OTYPER = 0x0000FF00;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->PUPDR = 0x00000000;
GPIOB->BSRRH = ((1 << 0) ); // LCD RW -> 0
lcd_ini();
lcd_cmd(0x80); // line 1
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data('K'); // K
lcd_data('E'); // E
lcd_data('Y'); // Y
lcd_data('P'); // P
lcd_data('A'); // A
lcd_data('D'); // D
lcd_data(' '); // SP
lcd_data('4'); // 4
lcd_data('x'); // X
lcd_data('3'); // 3
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data(' '); // SP
while(1){
keypad();
}
}
void lcd_ini(void)
{
Delay(10);
lcd_cmd(0x38);
lcd_cmd(0x0C);
lcd_cmd(0x01);
Delay(10);
}
void lcd_cmd(char i)
{
unsigned long r=0;
char loop=0;
r |= i;
for(loop=0;loop<=7;loop++)
{
r = r << 1;
}
GPIOB->BSRRH = ((1 << 1) );
LCDDATA = r;
GPIOE->ODR &= 0x000000FF;
GPIOE->ODR |= LCDDATA;
GPIOE->BSRRL = ((1 << 7) );
Delay(100);
GPIOE->BSRRH = ((1 << 7) );
}
void lcd_data(char j)
{
unsigned long r=0;
char loop=0;
r |= j;
for(loop=0;loop<=7;loop++)
{
r = r << 1;
}
GPIOB->BSRRL = ((1 << 1) );
LCDDATA = r;
GPIOE->ODR &= 0x000000FF;
GPIOE->ODR |= LCDDATA;
GPIOE->BSRRL = ((1 << 7) );
Delay(100);
GPIOE->BSRRH = ((1 << 7) );
}
char keypad(void){
char key_pressed=0;
/*Row 1 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRL = ((1 << 7) ); // Row 1 // Set
GPIOD->BSRRH = ((1 << 6) ); // Row 2 // Reset
GPIOD->BSRRH = ((1 << 4) ); // Row 3 // Reset
GPIOD->BSRRH = ((1 << 2) ); // Row 4 // Reset
if((GPIOD->IDR & 0x00000002) == 0x00000002) { //col 1
key_pressed = 1 ;
lcd_cmd(0xC7); // line 2
lcd_data('1');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) { //col 2
key_pressed = 2 ;
lcd_cmd(0xC7); // line 2
lcd_data('2');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) { //col 3
key_pressed = 3 ;
lcd_cmd(0xC7); // line 2
lcd_data('3');
Delay(100);
GPIOB->IDR = 0x00000000;
}
/*Row 2 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRL = ((1 << 6) );
GPIOD->BSRRH = ((1 << 4) );
GPIOD->BSRRH = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 4 ;
lcd_cmd(0xC7); // line 2
lcd_data('4');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 5 ;
lcd_cmd(0xC7); // line 2
lcd_data('5');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 6 ;
lcd_cmd(0xC7); // line 2
lcd_data('6');
Delay(100);
GPIOB->IDR = 0x00000000;
}
/*Row 3 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRH = ((1 << 6) );
GPIOD->BSRRL = ((1 << 4) );
GPIOD->BSRRH = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 7 ;
lcd_cmd(0xC7); // line 2
lcd_data('7');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 8 ;
lcd_cmd(0xC7); // line 2
lcd_data('8');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 9 ;
lcd_cmd(0xC7); // line 2
lcd_data('9');
Delay(100);
GPIOB->IDR = 0x00000000;
}
/*Row 4 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRH = ((1 << 6) );
GPIOD->BSRRH = ((1 << 4) );
GPIOD->BSRRL = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 10 ;
lcd_cmd(0xC7); // line 2
lcd_data('*');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 0 ;
lcd_cmd(0xC7); // line 2
lcd_data('0');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 11 ;
lcd_cmd(0xC7); // line 2
lcd_data('#');
Delay(100);
GPIOB->IDR = 0x00000000;
}
return key_pressed;
}
Task 2
/*----------------------------------------------------------------------------
LAB-11 Lab Task-1 (Keypad Interfacing)
*----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stm32f4xx.h>
void lcd_ini(void);
void lcd_data(char j);
void lcd_cmd(char i);
char keypad(void);
volatile uint32_t msTicks; /* counts 1ms timeTicks */
/*----------------------------------------------------------------------------
SysTick_Handler
*----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
msTicks++;
}
void Delay (uint32_t dlyTicks) {
uint32_t loop=0,dly=0,loope=0;
dly = dlyTicks ;
for(loop=0;loop<dly;loop++){
for(loope=0;loope<29000;loope++){
__nop();
}
}
}
unsigned long LCDDATA=0;
unsigned long op=0;
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main (void) {
SystemCoreClockUpdate(); // Get Core Clock Frequency
RCC->AHB1ENR |= (1 << 1) ; // Enable GPIOB clock
RCC->AHB1ENR |= (1 << 3) ; // Enable GPIOD clock
RCC->AHB1ENR |= (1 << 4) ; // Enable GPIOE clock
GPIOB->MODER = 0x00000005;
GPIOB->OTYPER = 0x00000003;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;
GPIOD->MODER = 0x00005110;
GPIOD->OTYPER = 0x00000000;
GPIOD->OSPEEDR = 0xAAAAAAAA;
GPIOD->PUPDR = 0x00000000;
GPIOE->MODER = 0x55555555;
GPIOE->OTYPER = 0x0000FF00;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->PUPDR = 0x00000000;
GPIOB->BSRRH = ((1 << 0) ); // LCD RW -> 0
lcd_ini();
lcd_cmd(0x80); // line 1
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data('K'); // K
lcd_data('E'); // E
lcd_data('Y'); // Y
lcd_data('P'); // P
lcd_data('A'); // A
lcd_data('D'); // D
lcd_data(' '); // SP
lcd_data('4'); // 4
lcd_data('x'); // X
lcd_data('3'); // 3
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data(' '); // SP
while(1){
keypad();
}
}
void lcd_ini(void)
{
Delay(10);
lcd_cmd(0x38);
lcd_cmd(0x0C);
lcd_cmd(0x01);
Delay(10);
}
void lcd_cmd(char i)
{
unsigned long r=0;
char loop=0;
r |= i;
for(loop=0;loop<=7;loop++)
{
r = r << 1;
}
GPIOB->BSRRH = ((1 << 1) );
LCDDATA = r;
GPIOE->ODR &= 0x000000FF;
GPIOE->ODR |= LCDDATA;
GPIOE->BSRRL = ((1 << 7) );
Delay(100);
GPIOE->BSRRH = ((1 << 7) );
}
void lcd_data(char j)
{
unsigned long r=0;
char loop=0;
r |= j;
for(loop=0;loop<=7;loop++)
{
r = r << 1;
}
GPIOB->BSRRL = ((1 << 1) );
LCDDATA = r;
GPIOE->ODR &= 0x000000FF;
GPIOE->ODR |= LCDDATA;
GPIOE->BSRRL = ((1 << 7) );
Delay(100);
GPIOE->BSRRH = ((1 << 7) );
}
char keypad(void){
char key_pressed=0;
/*Row 1 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRL = ((1 << 7) ); // Row 1 // Set
GPIOD->BSRRH = ((1 << 6) ); // Row 2 // Reset
GPIOD->BSRRH = ((1 << 4) ); // Row 3 // Reset
GPIOD->BSRRH = ((1 << 2) ); // Row 4 // Reset
if((GPIOD->IDR & 0x00000002) == 0x00000002) { //col 1
key_pressed = 1 ;
lcd_cmd(0xC7); // line 2
lcd_data('1');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) { //col 2
key_pressed = 2 ;
lcd_cmd(0xC7); // line 2
lcd_data('2');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) { //col 3
key_pressed = 3 ;
lcd_cmd(0xC7); // line 2
lcd_data('3');
Delay(100);
GPIOB->IDR = 0x00000000;
}
/*Row 2 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRL = ((1 << 6) );
GPIOD->BSRRH = ((1 << 4) );
GPIOD->BSRRH = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 4 ;
lcd_cmd(0xC7); // line 2
lcd_data('4');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 5 ;
lcd_cmd(0xC7); // line 2
lcd_data('5');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 6 ;
lcd_cmd(0xC7); // line 2
lcd_data('6');
Delay(100);
GPIOB->IDR = 0x00000000;
}
/*Row 3 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRH = ((1 << 6) );
GPIOD->BSRRL = ((1 << 4) );
GPIOD->BSRRH = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 7 ;
lcd_cmd(0xC7); // line 2
lcd_data('7');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 8 ;
lcd_cmd(0xC7); // line 2
lcd_data('8');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 9 ;
lcd_cmd(0xC7); // line 2
lcd_data('9');
Delay(100);
GPIOB->IDR = 0x00000000;
}
/*Row 4 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRH = ((1 << 6) );
GPIOD->BSRRH = ((1 << 4) );
GPIOD->BSRRL = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 10 ;
lcd_cmd(0xC7); // line 2
lcd_data('*');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 0 ;
lcd_cmd(0xC7); // line 2
lcd_data('0');
Delay(100);
GPIOD->IDR = 0x00000000;
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 11 ;
lcd_cmd(0xC7); // line 2
lcd_data('#');
Delay(100);
GPIOB->IDR = 0x00000000;
}
return key_pressed;
Task 3
#include <stdio.h>
#include <stm32f4xx.h>
#define seg_a_off GPIOE->BSRRL = ((1 << 2) )
#define seg_b_off GPIOE->BSRRL = ((1 << 5) )
#define seg_c_off GPIOC->BSRRL = ((1 << 8) )
#define seg_d_off GPIOE->BSRRL = ((1 << 6) )
#define seg_e_off GPIOD->BSRRL = ((1 << 0) )
#define seg_f_off GPIOC->BSRRL = ((1 << 9) )
#define seg_g_off GPIOE->BSRRL = ((1 << 4) )
#define seg_dot_off GPIOC->BSRRL = ((1 << 13) )
switch(sel_digit){
case 1:dig_1_on;dig_2_off;dig_3_off;break;
case 2:dig_1_off;dig_2_on;dig_3_off;break;
case 3:dig_1_off;dig_2_off;dig_3_on;break;
}// End switch(sel_digit)
switch(display_digit){
case 0:seg_a_on;seg_b_on;seg_c_on;seg_d_on;seg_e_on;seg_f_on;seg_g_off;seg_dot_off;break;
case 1:seg_a_off;seg_b_on;seg_c_on;seg_d_off;seg_e_off;seg_f_off;seg_g_off;seg_dot_off;break;
case 2:seg_a_on;seg_b_on;seg_c_off;seg_d_on;seg_e_on;seg_f_off;seg_g_on;seg_dot_off;break;
case 3:seg_a_on;seg_b_on;seg_c_on;seg_d_on;seg_e_off;seg_f_off;seg_g_on;seg_dot_off;break;
case 4:seg_a_off;seg_b_on;seg_c_on;seg_d_off;seg_e_off;seg_f_on;seg_g_on;seg_dot_off;break;
case 5:seg_a_on;seg_b_off;seg_c_on;seg_d_on;seg_e_off;seg_f_on;seg_g_on;seg_dot_off;break;
case 6:seg_a_on;seg_b_off;seg_c_on;seg_d_on;seg_e_on;seg_f_on;seg_g_on;seg_dot_off;break;
case 7:seg_a_on;seg_b_on;seg_c_on;seg_d_off;seg_e_off;seg_f_off;seg_g_off;seg_dot_off;break;
case 8:seg_a_on;seg_b_on;seg_c_on;seg_d_on;seg_e_on;seg_f_on;seg_g_on;seg_dot_off;break;
case 9:seg_a_on;seg_b_on;seg_c_on;seg_d_off;seg_e_off;seg_f_on;seg_g_on;seg_dot_off;break;
}// End switch(display_digit)
}// End void display_digit(unsigned int sel_digit,unsigned int display_digit)
void lcd_ini(void);
void lcd_data(char j);
void lcd_cmd(char i);
char keypad(void);
GPIOB->MODER = 0x00004505;
GPIOB->OTYPER = 0x00000003;
GPIOB->OSPEEDR = 0xAAAAAAAA;
GPIOB->PUPDR = 0x00000000;
GPIOD->MODER = 0x00005111;
GPIOD->OTYPER = 0x00000000;
GPIOD->OSPEEDR = 0xAAAAAAAA;
GPIOD->PUPDR = 0x00000000;
GPIOE->MODER = 0x55555555;
GPIOE->OTYPER = 0x0000FF00;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->PUPDR = 0x00000000;
GPIOB->BSRRH = ((1 << 0) ); // LCD RW -> 0
lcd_ini();
lcd_cmd(0x80); // line 1
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data('K'); // K
lcd_data('E'); // E
lcd_data('Y'); // Y
lcd_data('P'); // P
lcd_data('A'); // A
lcd_data('D'); // D
lcd_data(' '); // SP
lcd_data('4'); // 4
lcd_data('x'); // X
lcd_data('3'); // 3
lcd_data(' '); // SP
lcd_data(' '); // SP
lcd_data(' '); // SP
while(1){
keypad();
}
}
void lcd_ini(void)
{
Delay(10);
lcd_cmd(0x38);
lcd_cmd(0x0C);
lcd_cmd(0x01);
Delay(10);
}
void lcd_cmd(char i)
{
unsigned long r=0;
char loop=0;
r |= i;
for(loop=0;loop<=7;loop++)
{
r = r << 1;
}
GPIOB->BSRRH = ((1 << 1) );
LCDDATA = r;
GPIOE->ODR &= 0x000000FF;
GPIOE->ODR |= LCDDATA;
GPIOE->BSRRL = ((1 << 7) );
Delay(100);
GPIOE->BSRRH = ((1 << 7) );
}
void lcd_data(char j)
{
unsigned long r=0;
char loop=0;
r |= j;
for(loop=0;loop<=7;loop++)
{
r = r << 1;
}
GPIOB->BSRRL = ((1 << 1) );
LCDDATA = r;
GPIOE->ODR &= 0x000000FF;
GPIOE->ODR |= LCDDATA;
GPIOE->BSRRL = ((1 << 7) );
Delay(100);
GPIOE->BSRRH = ((1 << 7) );
}
char keypad(void){
char key_pressed=0;
/*Row 1 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRL = ((1 << 7) ); // Row 1 // Set
GPIOD->BSRRH = ((1 << 6) ); // Row 2 // Reset
GPIOD->BSRRH = ((1 << 4) ); // Row 3 // Reset
GPIOD->BSRRH = ((1 << 2) ); // Row 4 // Reset
if((GPIOD->IDR & 0x00000002) == 0x00000002) { //col 1
key_pressed = 1 ;
counter = 1;
lcd_cmd(0xC7); // line 2
lcd_data('1');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) { //col 2
key_pressed = 2 ;
counter = 2;
lcd_cmd(0xC7); // line 2
lcd_data('2');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) { //col 3
key_pressed = 3 ;
counter = 3;
lcd_cmd(0xC7); // line 2
lcd_data('3');
Delay(100);
GPIOB->IDR = 0x00000000;
display_value(counter);
}
/*Row 2 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRL = ((1 << 6) );
GPIOD->BSRRH = ((1 << 4) );
GPIOD->BSRRH = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 4 ;
counter = 4;
lcd_cmd(0xC7); // line 2
lcd_data('4');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 5 ;
counter = 5;
lcd_cmd(0xC7); // line 2
lcd_data('5');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 6 ;
counter = 6;
lcd_cmd(0xC7); // line 2
lcd_data('6');
Delay(100);
GPIOB->IDR = 0x00000000;
display_value(counter);
}
/*Row 3 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRH = ((1 << 6) );
GPIOD->BSRRL = ((1 << 4) );
GPIOD->BSRRH = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 7 ;
counter = 7;
lcd_cmd(0xC7); // line 2
lcd_data('7');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 8 ;
counter = 8;
lcd_cmd(0xC7); // line 2
lcd_data('8');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 9 ;
counter = 9;
lcd_cmd(0xC7); // line 2
lcd_data('9');
Delay(100);
GPIOB->IDR = 0x00000000;
display_value(counter);
}
/*Row 4 = 1 & scanning of Col 1 , Col 2 , Col 3*/
GPIOD->BSRRH = ((1 << 7) );
GPIOD->BSRRH = ((1 << 6) );
GPIOD->BSRRH = ((1 << 4) );
GPIOD->BSRRL = ((1 << 2) );
if((GPIOD->IDR & 0x00000002) == 0x00000002) {
key_pressed = 10 ;
counter = 10;
lcd_cmd(0xC7); // line 2
lcd_data('*');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOD->IDR & 0x00000008) == 0x00000008) {
key_pressed = 0 ;
counter = 0;
lcd_cmd(0xC7); // line 2
lcd_data('0');
Delay(100);
GPIOD->IDR = 0x00000000;
display_value(counter);
}
else if((GPIOB->IDR & 0x00000008) == 0x00000008) {
key_pressed = 11 ;
counter = 11;
lcd_cmd(0xC7); // line 2
lcd_data('#');
Delay(100);
GPIOB->IDR = 0x00000000;
}
return key_pressed;
}