1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
| .include "8515def.inc"
.equ col1 = PINA0
.equ col2 = PINA1
.equ col3 = PINA2
.equ col4 = PINA3
.def keyval = r16
.def temp = r17
.def flags = r18
.equ keyport = PORTA
.equ pressed = 0
key_init:
ldi keyval,$F0 ;Make Cols as i/p
out DDRA, keyval ;and Rows as o/p
ldi keyval,$0F ;Enable pullups
out keyport, keyval ;on columns
ret
get_key:
ldi keyval,$0 ;Scanning Row1
ldi temp,$7F ;Make Row1 low
out keyport,temp ;Send to keyport
rcall read_col ;Read Columns
sbrc flags,pressed ;If key pressed
rjmp done ;Exit the routine
ldi keyval,$4 ;Scanning Row2
ldi temp,$BF ;Make Row2 Low
out keyport,temp ;Send to keyport
rcall read_col ;Read Columns
sbrc flags,pressed ;If key pressed
rjmp done ;Exit from routine
ldi keyval,$8 ;Scanning Row3
ldi temp,$DF ;Make Row3 Low
out keyport,temp ;Send to keyport
rcall read_col ;Read columns
sbrc flags,pressed ;If key pressed
rjmp done ;Exit the routine
ldi keyval,$C ;Scanning Row4
ldi temp,$EF ;Make Row4 Low
out keyport,temp ;send to keyport
rcall read_col ;Read columns
done:
ret
read_col:
cbr flags, (1<<pressed) ;Clear status flag
sbic PINA, col1 ;Check COL1
rjmp nextcol ;Go to COL2 if not low
hold:
sbis PINA, col1 ;Wait for key release
rjmp hold
sbr flags, (1<<pressed) ;Set status flag
ret ;key 1 pressed
nextcol:
sbic PINA,col2 ;Check COL2
rjmp nextcol1 ;Goto COL3 if not low
hold1:
sbis PINA, col2 ;Wait for key release
rjmp hold1
inc keyval ;Key 2 pressed
sbr flags,(1<<pressed) ;Set status flag
ret
nextcol1:
sbic PINA,col3 ;Check COL3
rjmp nextcol2 ;Goto COL4 if no pressed
hold2:
sbis PINA, col3 ;Wait for key release
rjmp hold2
inc keyval ;Key 3 pressed
inc keyval
sbr flags, (1<<pressed) ;Set status flag
ret
nextcol2:
sbic PINA,col4 ;Check COL4
rjmp exit ;Exit if not low
hold3:
sbis PINA, col4 ;Wait for key release
rjmp hold3
inc keyval ;Key 4 Pressed
inc keyval
inc keyval
sbr flags, (1<<pressed) ;Set status flag
ret
exit:
clr keyval ;reset keyval
cbr flags, (1<<pressed) ;No Key Pressed
ret |