Set 3
Set 3
Set 3
h"
int main(void) {
#include "stm32g071xx.h"
#include "math.h"
int main(void)
{
uint8_t rows, cols, j, k;
// Enable clock for Port A and C
RCC->IOPENR |=RCC_IOPENR_GPIOAEN;
RCC->IOPENR |=RCC_IOPENR_GPIOCEN;
// Set pin 4 to 7 of port C as columns (output:pull-push)
GPIOC->MODER &= 0xFFFF00FF; // clear required field
GPIOC->MODER |= 0X00005500; // set required bits
GPIOC->OTYPER &= 0xFFFFFF0F; // use pull-push type
GPIOC->PUPDR &= 0xFFFF00FF; // no pull up, no pull down
while(1){
GPIOC->ODR |= 0x00F0; // all columns HIGH
keyval = keypad_scan();
keyval1 = keyval;
cols = keyval & 0x0F;
cols = cols/2;
if (cols==4) cols-=1;
keyval = keyval >>4;
rows = keyval & 0x0F;
rows = rows/2;
if(rows==4) rows -=1;
for (j=0; j<=rows; ++j) {
GPIOA->BSRR = (1<<5); msdelay (250);
GPIOA->BSRR = (1<<21); msdelay (250);
}
msdelay(2000);
for (k=0; k<=cols; ++k) {
GPIOA->BSRR = (1<<5); msdelay (250);
GPIOA->BSRR = (1<<21); msdelay (250);
}
}
} // end of main
while(1){
rowval = GPIOA->IDR;
if (rowval!=0){
msdelay(10); // debounce delay
rowval = GPIOA->IDR & 0x00000F00;
if (rowval !=0)
break; // key press detected, go to scan loop
else continue;
}
else
continue;
}