Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTERFACING KEYBOARD WITH ATMEGA32 ELECTRONICS & COMMUNICATION TITLE.

Similar presentations


Presentation on theme: "INTERFACING KEYBOARD WITH ATMEGA32 ELECTRONICS & COMMUNICATION TITLE."— Presentation transcript:

1 INTERFACING KEYBOARD WITH ATMEGA32 ELECTRONICS & COMMUNICATION TITLE

2 SUBJECT MICROCONTROLLER & ITS INTERFACING POWERPOINT PRESENTATION AS A PART OF ALA SUBMISSION BY : NAME : SHUBHAM A. KANORIA ENROLL : 131080111004 DEPT : E.C. SEMESTER : 5 TH ELECTRONICS & COMMUNICATION TOPIC : I NTERFACING KEYBOARD WITH ATMEGA32

3 A PC keyboard is an old and trusted human machine interface. Most peoples are familiar with it. When a text entry is required it is the best method. If we can interface the PC keyboard with an AVR MCU. We can create a whole lot of interesting applications! This presentation will focus on our easy to use PS2 keyboard library for AVR MCU. ELECTRONICS & COMMUNICATION

4 The PS2 Keyboard library for AVR has only two functions one for initializing the library and one for reading a ASCII character from the queue. The keyboard library automatically translates the scan codes to ASCII characters and buffers them in a FIFO queue. That means even if the CPU is busy doing something else and a character arrives from the keyboard, it will be automatically buffered in a queue. After that the CPU can read the characters anytime when it is free. ELECTRONICS & COMMUNICATION

5 Only two I/O lines used. One line is also connected to external interrupt pin of AVR. No external components is needed for interface; Included C source reads from keyboard interface and converts to serial In many situations you need some kind of human interface to your microcontroller project. In this example is interfacing AVR microcontroller to standard PC AT keyboard described. ELECTRONICS & COMMUNICATION

6

7 In a keyboard interface signal lines are open collector with pull-up resistors. Keyboard cable connectors can be DIN or Mini DIN (We are not talking about USB interface): ELECTRONICS & COMMUNICATION

8 According to keyboard timing diagram in bellow picture the keyboard transfers data to host AVR microcontroller. The protocol is: one start bit (always 0), eight data bits, one odd parity bit and one stop bit (always 1). The data is validated during the low period of clock pulse. Clock signal is generated by keyboard and pulses are about 30- 50us low and high. ELECTRONICS & COMMUNICATION

9 The keyboard has a scan code associated with each key. When key is press – the code is transmitted. If key is is hold down for a while the code is transmitted repeatedly (about 10 times per s). After key is released the brake code is transmitted ($F0). Usually all keys have 8 bit length codes except some keys like Home, Insert and Delay have an extended codes from two to five bytes. The first bytes is always $E0. This is also true for the “break” sequence e.g. E0 F0 xx… The keyboard can handle three sets of scan codes. Default is set Two which is used in this example. The code in example is a simple keyboard to RS232 interface. Scanned codes are translated to ASCII characters and transmitted by USART. The code included in example can be adapted to any AVR microcontroller with SRAM. ELECTRONICS & COMMUNICATION

10

11

12 #include //Keypad Information #define R0 0 #define R1 1 #define R2 2 #define R3 3 #define C0 4 #define C1 5 #define C2 6 #define C3 7 Program for Interfacing

13 ELECTRONICS & COMMUNICATION #define keypadPORT PORTA #define keypadPIN PINA #define keypadDDR DDRA //Keypad functions and global variables char getkey(); int keypadRow[] = {R0, R1, R2, R3}; //rows of the keypad int keypadCol[] = {C0, C1, C2, C3};//columnd int main() { char key_pressed; keypadDDR |= (1<<R0)|(1<<R1)|(1<<R2)|(1<<R3);//set upper part of keypad port as output //this will be required for scanning the rows keypadDDR &= ~((1<<C0)|(1<<C1)|(1<<C2)|(1<<C3));//set lower part of keypad port as input. // This is the part of the keypad port where the rows are connected.

14 ELECTRONICS & COMMUNICATION LCD_init(); //initialize LCD while(1) { key_pressed = getkey(); switch(key_pressed) { case('A'): break;//do nothing if no key is pressed default: send_char(key_pressed);//send the key pressed to LCD } return 0; } char getkey() { int i, j; for(i = 0; i < 4; i++) { keypadPORT = 0x00;

15 ELECTRONICS & COMMUNICATION keypadPORT |= (1 << keypadRow[i]);//send a high to a particular row of the keypad for(j = 0; j < 4; j++) { if(bit_is_set(keypadPIN,keypadCol[j]))//check if key is pressed { while(bit_is_set(keypadPIN,keypadCol[j])); //wait for key to be released switch(i) { case(0): { if (j == 0) return '7'; else if (j == 1) return '8'; else if (j == 2) return '9'; else if (j == 3) return '/'; break; } case(1): { if (j == 0) return '4'; else if (j == 1) return '5'; else if (j == 2) return '6'; else if (j == 3) return '*';

16 ELECTRONICS & COMMUNICATION break; } case(2): { if (j == 0) return '1'; else if (j == 1) return '2'; else if (j == 2) return '3'; else if (j == 3) return '-'; break; } case(3): { if (j == 0) return '?'; else if (j == 1) return '0'; else if (j == 2) return '='; else if (j == 3) return '+'; break; } return 'A';//Return 'A' if no key is pressed. }

17 THANK YOU ELECTRONICS & COMMUNICATION


Download ppt "INTERFACING KEYBOARD WITH ATMEGA32 ELECTRONICS & COMMUNICATION TITLE."

Similar presentations


Ads by Google