View previous topic :: View next topic |
Author |
Message |
Vilko
Joined: 25 May 2004 Posts: 190 Location: Ljubljana, Slovenia
|
Posted: Wed Mar 02, 2005 8:57 pm Post subject: Alphabet on 3X4 Keyboard |
|
|
Alphabet on 3x4 Keyboard
You have probable sent a SMS from handyphone. You must press several times the same key of keyboard to put one letter of the message into it.
Something similar I tried to achieve with my micro and Keyboard. I use the same principles as described already in post ‘MultipleClick on Key’ on this forum.
Only extended to keyboard 3x4. So I shall not explain again what has already been mentioned, but only the new staff.
Keyboard:
Code: | 'OUTPUTS All Active High
Statusled Alias P1.0 ' Operational Status (rele 1)
Col1 Alias P2.4 ' Keyboard Column Drivers
Col2 Alias P2.5
Col3 Alias P2.6 ' Add Another Col for 4X4 Kpad
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'INPUTS All Active Low
Row1 Alias P2.0 ' Keyboard Rows (Read)
Row2 Alias P2.1
Row3 Alias P2.2
Row4 Alias P2.3
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
I shall compose text in
Code: | Dim X(16) As Byte
Dim I As Byte
For I = 1 To 16
X(i) = &H20 'clear to spaces
Next
I = 1 |
Somewhere in mainprogrammloop i scan keyboard:
Code: | Keyscan:
Statusled = 0 ' Status Led OFF
Col1 = 0 : Col2 = 1 : Col3 = 1 ' Turns Columns On (Low) 1 by 1
' 012 6 10 14 18 22 27 31
' 012 3 4 5 6 7 8 9
' "012ABC3DEF4GHI5JKL6MNO7PQRS8TUV9WXYZ" lookup table
' hitcnt + keypressed gives argument for lookup table to fetch the character
Keyread = Hitcnt + 1 : Debounce Row1 , 0 , Gotkey , Sub
Keyread = Hitcnt + 10 : Debounce Row2 , 0 , Gotkey , Sub
Keyread = Hitcnt + 22 : Debounce Row3 , 0 , Gotkey , Sub
Keyread = 54 : Debounce Row4 , 0 , Gotkey , Sub ' CALL Button *
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Col1 = 1 : Col2 = 0 : Col3 = 1
Keyread = Hitcnt + 2 : Debounce Row1 , 0 , Gotkey , Sub
Keyread = Hitcnt + 14 : Debounce Row2 , 0 , Gotkey , Sub
Keyread = Hitcnt + 27 : Debounce Row3 , 0 , Gotkey , Sub
Keyread = Hitcnt + 0 : Debounce Row4 , 0 , Gotkey , Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Col1 = 1 : Col2 = 1 : Col3 = 0
Keyread = Hitcnt + 6 : Debounce Row1 , 0 , Gotkey , Sub
Keyread = Hitcnt + 18 : Debounce Row2 , 0 , Gotkey , Sub
Keyread = Hitcnt + 31 : Debounce Row3 , 0 , Gotkey , Sub
Keyread = 55 : Debounce Row4 , 0 , Gotkey , Sub ' CANCEL Button # | Notice, that variable Keyread is modified with the variable Hitcnt. For every hit on key inside timeinterval, clickcnt is incremented by one
In the Gotkey subroutine I wait for key to be released
Code: | ' Gotkey subroutine:
Gotkey:
Checkagain: ' wait for key to be released
Check = P2 And 15 ' Appropriate Port
If Check <> 15 Then : Goto Checkagain : End If ' |
Then reset timer and set flags if text is to be processed or canceled:
Code: | Ticnt = 0 ' reset the timer
If Keyread = 55 Then : Set Cancelflag : End If ' CANCEL Button
If Keyread = 44 Then : Set Processflag : End If ' CALL Button |
Keyread has value of key, which was pressed plus the number, howmanytime was pressed in the timeinterval. So I can fetch the character according it from the lookup table:
Code: | X(i) = Lookup(keyread , Table) |
Then I reset timemeasurment and increment hits counter:
Code: | Incr Clickcnt
Ticnt = 0 ' reset the timer
Return |
Timer Interrupt routine measures time elapsed from last click, which has set Ticnt to zero. If Ticnt reaches 50, it means the time of 50/125 second has passed from last click, the chosen character is valid and we set Clickflag and reset Clickcnt to zero:
Code: | Titi:
Load Timer0 , 250
If Ticnt < 255 Then
Incr Ticnt
End If
If Ticnt = 50 Then
Set Clickflag 'set flag time interval elapsed
Incr Ticnt 'to be sure, that clicflag set
Clickcnt = 0 'only ones for the time
End If
Return |
In the main program, if Clickflag was set by timerinterrupt routine then i
Set index to next byte in array and refresh lcd:
Code: | If Clickflag = 1 Then
Reset Clickflag
'set index to next position in array x(16)
Incr I
If I > 16 Then
I = 1
End If
'display the read contents:
push {i}
For I = 1 To 16
Locate 1 , I
push {i}
I = X(i)
Lcd Chr(i)
pop {i}
Next
pop {i}
End If |
If cancelflag or process flag was set by gotkey soubroutine, because key # or * was pressed, then I overwrite the last character read (also keys * and # read characters into array, but these characters do not belong to message) and the I erase or process the value in X(i) from i=1 to 16:
Code: | If Cancelflag = 1 Then
Reset Cancelflag
'erase all and reset index
For I = 1 To 16 : X(i) = &H20 : Next
I = 0
Locate 1 , 1
Lcd " "
End If
If Processflag = 1 Then
Reset Processflag
X(i) = &H20
If I > 1 Then : Decr I : End If
'move
Locate 2 , 1
For I = 1 To 16
push {i}
I = X(i)
Lcd Chr(i)
pop {i}
X(i) = &H20
Next
Locate 1 , 1
Lcd " "
I = 0
End If |
And that is it. The complete code is attached.
Nota bene: When you use this code, you will certainly change aliases for rows and columns. Do not forget to change the mask (15) in the statement
where we wait for key to be released.
Vilko |
|
Back to top |
|
|
joe_mayer
Joined: 13 Mar 2007 Posts: 2 Location: Kuala Lumpur
|
Posted: Thu Mar 29, 2007 1:49 am Post subject: my keypad problem.. |
|
|
hi...can you help me...the problem is i cannot interface my keypad to my AT89S8252...how to program the IC? what source code should i put...
please help... |
|
Back to top |
|
|
Vilko
Joined: 25 May 2004 Posts: 190 Location: Ljubljana, Slovenia
|
Posted: Thu Mar 29, 2007 5:56 am Post subject: What have you done? |
|
|
Hi, Joe,
You are asking for help, but you did not mention what you intend to do and what have you already done. How did you connecet Keypad to 8252?
What else have you connected to 8252 ..
I am willing to help you, but, i do not know, what you need. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|