Home
1. .include "8515def.inc"
2.
3. .equ col1 = PINA0
4. .equ col2 = PINA1
5. .equ col3 = PINA2
6. .equ col4 = PINA3
7.
8. .def keyval = r16
9. .def temp = r17
10. .def flags = r18
11.
12. .equ keyport = PORTA
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
13. .equ pressed = 0
14.
15. key_init:
16. ldi keyval,$F0 ;Make Cols as i/p
17. out DDRA, keyval ;and Rows as o/p
18. ldi keyval,$0F ;Enable pullups
19. out keyport, keyval ;on columns
20. ret
21.
22. get_key:
23. ldi keyval,$0 ;Scanning Row1
24. ldi temp,$7F ;Make Row1 low
25. out keyport,temp ;Send to keyport
26. rcall read_col ;Read Columns
27.
28. sbrc flags,pressed ;If key pressed
29. rjmp done ;Exit the routine
30.
31. ldi keyval,$4 ;Scanning Row2
32. ldi temp,$BF ;Make Row2 Low
33. out keyport,temp ;Send to keyport
34. rcall read_col ;Read Columns
35.
36. sbrc flags,pressed ;If key pressed
37. rjmp done ;Exit from routine
38.
39. ldi keyval,$8 ;Scanning Row3
40. ldi temp,$DF ;Make Row3 Low
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
41. out keyport,temp ;Send to keyport
42. rcall read_col ;Read columns
43.
44. sbrc flags,pressed ;If key pressed
45. rjmp done ;Exit the routine
46.
47. ldi keyval,$C ;Scanning Row4
48. ldi temp,$EF ;Make Row4 Low
49. out keyport,temp ;send to keyport
50. rcall read_col ;Read columns
51.
52. done:
53. ret
54.
55. read_col:
56. cbr flags, (1<<pressed) ;Clear status flag
57.
58. sbic PINA, col1 ;Check COL1
59. rjmp nextcol ;Go to COL2 if not low
60.
61. hold:
62. sbis PINA, col1 ;Wait for key release
63. rjmp hold
64. sbr flags, (1<<pressed) ;Set status flag
65. ret ;key 1 pressed
66. nextcol:
67. sbic PINA,col2 ;Check COL2
68. rjmp nextcol1 ;Goto COL3 if not low
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
69.
70. hold1:
71. sbis PINA, col2 ;Wait for key release
72. rjmp hold1
73. inc keyval ;Key 2 pressed
74. sbr flags,(1<<pressed) ;Set status flag
75. ret
76. nextcol1:
77. sbic PINA,col3 ;Check COL3
78. rjmp nextcol2 ;Goto COL4 if no pressed
79.
80. hold2:
81. sbis PINA, col3 ;Wait for key release
82. rjmp hold2
83. inc keyval ;Key 3 pressed
84. inc keyval
85. sbr flags, (1<<pressed) ;Set status flag
86. ret
87. nextcol2:
88. sbic PINA,col4 ;Check COL4
89. rjmp exit ;Exit if not low
90.
91. hold3:
92. sbis PINA, col4 ;Wait for key release
93. rjmp hold3
94. inc keyval ;Key 4 Pressed
95. inc keyval
96. inc keyval
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
97. sbr flags, (1<<pressed) ;Set status flag
98. ret
99. exit:
100. clr keyval ;reset keyval
101. cbr flags, (1<<pressed) ;No Key Pressed
102. ret
103.
1. #include <avr/io.h>
2. // Include file for AVR
3. #define keyport PORTA //Keypad Port
4. #define keyportddr DDRA //Data Direction Register
5. #define keyportpin PINA //Keypad Port Pins
6.
7. #define col1 PA0 //Column1 PortA.0
8. #define col2 PA1 //Column2 PortA.1
9. #define col3 PA2 //Column3 PortA.2
10. #define col4 PA3 //Column4 PortA.3
11.
12. #define TRUE 1
13. #define FALSE 0
14.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
15. unsigned char keyval; //A variable
16.
17. /*
18. +---------------------------------------+
19. | Prototype: void key_init(void); |
20. | Return Type: void |
21. | Arguments: None |
22. | Description: Initialize ports and |
23. | Keypad. |
24. +---------------------------------------+
25. */
26. void key_init(){
27. keyportddr = 0xF0;
28. keyport = 0x0F;
29. }
30.
31. /*
32. +-----------------------------------------------+
33. | Prototype: unsigned char get_key(void); |
34. | Return Type: unsigned char |
35. | Arguments: None |
36. | Description: To read key from the keypad |
37. +-----------------------------------------------+
38. */
39. unsigned char get_key(){
40. unsigned char i,key=1;
41. for(i=0;i<4;i++){ //Loop for 4 rows
42. keyport &=~(0x80>
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
43. >
44. i); //Make rows low one by one
45. if(!(keyportpin & (1<<col1))){
46. //check COL1
47. while(!(keyportpin & (1<<col1)));
48. //wait for release
49. return key;
50. //return pressed key value
51. }
52. if(!(keyportpin & (1<<col2))){
53. //Check COL2
54. key += 1;
55. //Second key pressed
56. while(!(keyportpin & (1<<col2)));
57. //wait for release
58. return key;
59. //return key value
60. }
61. if(!(keyportpin & (1<<col3))){
62. //Check COL3
63. key += 2;
64. //Third key pressed
65. while(!(keyportpin & (1<<col3)));
66. //Wait for release
67. return key;
68. //Return value
69. }
70. if(!(keyportpin & (1<<col4))){
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
71. //check COL4
72. key += 3;
73. //Fourth key pressed
74. while(!(keyportpin & (1<<col4)));
75. //Wait for release
76. return key;
77. //Return key value
78. }
79. key +=4; //Next row
80. keyport |= 0x80>
81. >
82. i;
83. //make read row high again
84. }
85. return FALSE; //return false if no key pressed
86. }
Using these keypad routines is really simple.. here is a simple example that shows how to convert the key numbers to displayable
ascii characters.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
6. =10 && keyval < 16)
7. return keyval - 10 + 'A';
8. else
9. return '?';
10. }
11.
12. /* usage */
13. ascii_key = translate(get_key());
14. /*
15. * ascii_key will have the ascii equivalent of key pressed on the keypad
16. * i.e. 0, 1, 2, 3, 4,...., A, B, C, D, E, F
17. */
However the above function is just an example of how to use get_key function, you can define any translate function as per your
requirement.
The next section of the tutorial will cover the programming of 8051. The usage example will apply to 8051 too.
Post A Question Share A Project
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Forum Activity
Conversation
Type your message here ... sim300 not able to send and receive the
message
sim 300 gsm modem is not able to send the
message ...
ChollyMo 02/22/2017
Indeed, on the LCD tutorial, many missing Posted By XuZiling 02/22/2017
Tables and figures !!
Physics of Semiconductor Devices, 2nd
Edition - Simon M. Sze
ChollyMo 02/22/2017 hope to enjoy this book
I don't see any Table 3. I'm using Chrome.
most everEmin
online: 182184 01/03/2017 Receiving a gsm message and displaying it on
(Members:I'm already182184)
, Guests: a member since
on 06 Aug2012 and
2010: entered
05:37 AM lcd
repeatedly during period. But now it is HiThis is what we get on the lcd when we burn
Members:impossible
37801 and obtaining a new registration is the ...
Newest member:
also failed.
XuZiling
The same error message specifying
that two e-mails i entered are different!. In fact
thaey are the same. Now, what will be happen, Posted By ExperimenterUK 02/14/2017
Trending whatTopics
is your solution? Thanks..
Receiving a gsm message and displaying it on
parameters Atmel AVR microcontroller ebooks home lcd
automation using gsm mode mutiplexed 7-seg display Thank you when we send a message the
I2C simulation on Pinnacle 52 transistor message is no...
cellphone controlled
message is no...
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
robot sim300 footprint library debugging in keil
peace and happiness
more tags
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com