• Home
  • Blog
  • C Programming USART and ASCII Characters Exercise

C Programming USART and ASCII Characters Exercise

0 comments

I’m working on a c programming exercise and need an explanation and answer to help me learn.

Your program is intended to output the letter or the number that is pushed on the sixteen-button keypad provided to you, based on which key is being pressed using USART and ASCII characters. Use C code and Atmel 328 board to develop.

The suggestion is that you set rows as output and columns as input. The code shall first set all rows high at each pass and then, go one row at a time (setting them low), checking each column in that row, to identify which button is pressed. And then interpret the pressed button based on the pins each key is associated with and output the key’s corresponding letter/number/symbol on the Data Visualizer console provided in the Atmel Studio. The code should run on an infinite loop, continually scanning for any button that is pushed. Don’t forget to compensate for button de-bouncing time of 50 milliseconds.

Steps or functions to build on:

UART Initialization function

UART Tx function

Keypad scan function

In main function:

– Declare rows as output and columns as input

SCANNING THROUGH THE KEYPAD:

Set all rows(output) high

PORTD |= (1<<4 |1<<5 |1<<6 |1<<7);

Set row(i) low – one at a time and check each

column

PORTD &= ~(1<< row#i)

Check each column(j) to see which is pulled Low

if (!(PINB & (1 << column#j)))

Output the corresponding character

UART_Tx (keychar[i][j])

E.g.: DDRD |= (1<<DDD4) sets row of PD4 as output

DDRB &= ~(1<<DDB0) sets column PB0 as input

Use the data visualizer built in to the atmel studio to show character output.

Note: If USART is initialized, DO NOT use PD0 and PD1 for keypad (GPIO pins disabled when Serial I/O enabled for these pins)

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}