Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:04 04 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Keyboard for Micromite Plus

     Page 7 of 14    
Author Message
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 01:18am 27 Aug 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said  
needs to be ... = 511 - (2 ^ value) otherwise you have too many 0's!!
[/quote]
Oh boy. :) :) Yes it should be all ones and only one zero.

  WhiteWizzard said  
ALSO

SetRow(RowNumber) in ScanMatrix (under the first DO) you will need to change to SetRow(RowNumber + 1)

No,this should be OK. Bit numbers 0 - 8.

  Kiiid said  
Here is a little idea: command buffer built into the keyboard. If the keyboard knows when the mite is in command mode, it could replace up and down arrows with previously entered command lines

Is there a single character available to delete the current line. Maybe ESC?
This would not be to difficult to add, same as macros that can contain little code snippets or other often used sequences. :)

Edited by TZAdvantage 2015-08-28
Microblocks. Build with logic.
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 01:29am 27 Aug 2015
Copy link to clipboard 
Print this post

  TZAdvantage said  
  Kiiid said  
Here is a little idea: command buffer built into the keyboard. If the keyboard knows when the mite is in command mode, it could replace up and down arrows with previously entered command lines

Is there a single character available to delete the current line. Maybe ESC?
This would not be to difficult to add, same as macros that can contain little code snippets or other often used sequences. :)



With compromise to the visual clarity the same function can be performed by sending Ctrl-C to the mite

http://rittle.org

--------------
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 01:49am 27 Aug 2015
Copy link to clipboard 
Print this post

This is what I have of TZA's code thus far:


Dim Lookup(8) as string * 8
Lookup(0) = "abcdefgh"
Lookup(1) = "ijklmnop"
Lookup(2) = "qrstuvwx"
Lookup(3) = "yz123456"
Lookup(4) = "7890-=[]"
Lookup(5) = "\;',./~!"
Lookup(6) = "@#$%^&*("
Lookup(7) = ")_+{}|:" + CHR$(34)
Lookup(8) = "<>?ABCDE"

C0=15:C1=16:C2=17:C3=21:C4=22:C5=23:C6=24:C7=26 'Setup columns
R0=02:R1=03:R2=04:R3=05:R4=06:R5=07:R6=09:R7=10:R8=25 'Setup rows
SetPin C0,din,pullup:SetPin C1,din,pullup:SetPin C2,din,pullup
SetPin C3,din,pullup:SetPin C4,din,pullup:SetPin C5,din,pullup
SetPin C6,din,pullup:Setpin C7,din,pullup

Setpin R0,dout:SetPin R1,dout:SetPin R2,dout:SetPin R3,dout
SetPin R4,dout:SetPin R5,dout:SetPin R6,dout:Setpin R7,dout
Setpin R8,dout

Delay = 50
DebounceDelay = 10

DEBUG = 1

'MAIN
Do
SetRow(-1)
PAUSE Delay
If ReadColumns() <> 255 then
print ScanMatrix$()
endif
Loop


SUB SetRow(value)
'Row pins 2,3,4,5,6,7,9,10,25
if value = -1 then
'Set all bits to 0. This will allow detecting any keypress
PORT(2,6,9,2,25,1) = 0
else
'Set a bit to 0
PORT(2,6,9,2,25,1) = 512 - (2 ^ value)
endif
END SUB

FUNCTION ReadColumns()
LOCAL FirstScan, ScanCode

'Read the column port and do a simplistic debounce
'Column pins 15,16,17,21,22,23,24,26
FirstScan = PORT(15,3,21,4,26,1)
PAUSE DebounceDelay
ScanCode = PORT(15,3,21,4,26,1)
If FirstScan <> ScanCode then ScanCode = 255
ReadColumns = ScanCode
END FUNCTION

FUNCTION ScanMatrix$()
LOCAL K$,Keys$, RowNumber, ScanCode

Keys$ = ""
RowNumber = 0
Do
SetRow(RowNumber)
ScanCode = ReadColumns()

'Decode the ScanCode
if ScanCode <> 255 then
'One or more keys were pressed
if DEBUG = 1 then PRINT ScanCode
for ColumnNumber = 0 to 7
'Check every bit in the column
if (Scancode and (255 - (2 ^ ColumnNumber))) = 0 then
if CAP = 0 AND SFT = 0 then
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
else
'For now use the same lookup table, use RowNumber + 9 when debugged
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
endif
if DEBUG = 1 then
PRINT RowNumber + "," + ColumnNumber + "=>" + K$
endif
Keys$ = Keys$ + K$
endif
next
endif

RowNumber = RowNumber + 1
Loop until RowNumber > 8

ScanMatrix$ = Keys$

END FUNCTION



Smoke makes things work. When the smoke gets out, it stops!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 01:53am 27 Aug 2015
Copy link to clipboard 
Print this post

  TZAdvantage said  
  WhiteWizzard said  
ALSO

SetRow(RowNumber) in ScanMatrix (under the first DO) you will need to change to SetRow(RowNumber + 1)

No,this should be OK. Bit numbers 0 - 8.


Yes - I was thinking 2 ^ 0 = 0 - my mistake!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 01:55am 27 Aug 2015
Copy link to clipboard 
Print this post

Grogs - Change 512 - (2 ^ value) in the SetRows(value) sub and re-try!

To 511 - (2 ^ value) Edited by WhiteWizzard 2015-08-28
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 01:58am 27 Aug 2015
Copy link to clipboard 
Print this post

Grogs - could you add line numbers to the listing to make it easier to refer to points in the code - cheers!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 02:02am 27 Aug 2015
Copy link to clipboard 
Print this post

Changed to 511. Result:





As to line numbers, just copy and paste the code into MMEdit for line numbers.
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:05am 27 Aug 2015
Copy link to clipboard 
Print this post

G,

You still need to change this: (not only change OR to AND. :)
What do you get when you change
[code]
if (Scancode OR (255 - (2 ^ ColumnNumber))) = 0 then
[/code]
into this:
[code]
if (Scancode AND (2 ^ ColumnNumber)) = 0 then
[/code]


Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:06am 27 Aug 2015
Copy link to clipboard 
Print this post

Thanks - which line is printing these numbers???

Sorry - don't have MMEdit on this device



 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:08am 27 Aug 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said   Thanks - which line is printing these numbers???
Sorry - don't have MMEdit on this device

That should be this line in ScanMatrix$ function:
[code]
if DEBUG = 1 then PRINT ScanCode
[/code]
The empty lines are printed in Main
[code]
print ScanMatrix$()
[/code]

Edited by TZAdvantage 2015-08-28
Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 02:17am 27 Aug 2015
Copy link to clipboard 
Print this post

Result:





Current code:


Dim Lookup(8) as string * 8
Lookup(0) = "abcdefgh"
Lookup(1) = "ijklmnop"
Lookup(2) = "qrstuvwx"
Lookup(3) = "yz123456"
Lookup(4) = "7890-=[]"
Lookup(5) = "\;',./~!"
Lookup(6) = "@#$%^&*("
Lookup(7) = ")_+{}|:" + CHR$(34)
Lookup(8) = "<>?ABCDE"

C0=15:C1=16:C2=17:C3=21:C4=22:C5=23:C6=24:C7=26 'Setup columns
R0=02:R1=03:R2=04:R3=05:R4=06:R5=07:R6=09:R7=10:R8=25 'Setup rows
SetPin C0,din,pullup:SetPin C1,din,pullup:SetPin C2,din,pullup
SetPin C3,din,pullup:SetPin C4,din,pullup:SetPin C5,din,pullup
SetPin C6,din,pullup:Setpin C7,din,pullup

Setpin R0,dout:SetPin R1,dout:SetPin R2,dout:SetPin R3,dout
SetPin R4,dout:SetPin R5,dout:SetPin R6,dout:Setpin R7,dout
Setpin R8,dout

Delay = 50
DebounceDelay = 10

DEBUG = 1

'MAIN
Do
SetRow(-1)
PAUSE Delay
If ReadColumns() <> 255 then
print ScanMatrix$()
endif
Loop


SUB SetRow(value)
'Row pins 2,3,4,5,6,7,9,10,25
if value = -1 then
'Set all bits to 0. This will allow detecting any keypress
PORT(2,6,9,2,25,1) = 0
else
'Set a bit to 0
PORT(2,6,9,2,25,1) = 511 - (2 ^ value)
endif
END SUB

FUNCTION ReadColumns()
LOCAL FirstScan, ScanCode

'Read the column port and do a simplistic debounce
'Column pins 15,16,17,21,22,23,24,26
FirstScan = PORT(15,3,21,4,26,1)
PAUSE DebounceDelay
ScanCode = PORT(15,3,21,4,26,1)
If FirstScan <> ScanCode then ScanCode = 255
ReadColumns = ScanCode
END FUNCTION

FUNCTION ScanMatrix$()
LOCAL K$,Keys$, RowNumber, ScanCode

Keys$ = ""
RowNumber = 0
Do
SetRow(RowNumber)
ScanCode = ReadColumns()

'Decode the ScanCode
if ScanCode <> 255 then
'One or more keys were pressed
if DEBUG = 1 then PRINT ScanCode
for ColumnNumber = 0 to 7
'Check every bit in the column
if (Scancode and (2 ^ ColumnNumber)) = 0 then
if CAP = 0 AND SFT = 0 then
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
else
'For now use the same lookup table, use RowNumber + 9 when debugged
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
endif
if DEBUG = 1 then
PRINT RowNumber + "," + ColumnNumber + "=>" + K$
endif
Keys$ = Keys$ + K$
endif
next
endif

RowNumber = RowNumber + 1
Loop until RowNumber > 8

ScanMatrix$ = Keys$

END FUNCTION

Smoke makes things work. When the smoke gets out, it stops!
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:18am 27 Aug 2015
Copy link to clipboard 
Print this post

str$()
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:19am 27 Aug 2015
Copy link to clipboard 
Print this post

PRINT str$(RowNumber) + "," + str$(ColumnNumber) + "=>" + K$
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:20am 27 Aug 2015
Copy link to clipboard 
Print this post

Getting close. :)
I had this first:
[code]
PRINT RowNumber","ColumnNumber"=>"K$
[/code]
But found it a bit unclear. Claaning up code introduces error. Well that never happened before. :) :)

Edited by TZAdvantage 2015-08-28
Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:21am 27 Aug 2015
Copy link to clipboard 
Print this post

Better still:

PRINT "R:" + str$(RowNumber) + " C:" + str$(ColumnNumber) + " => " + K$
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9586
Posted: 02:24am 27 Aug 2015
Copy link to clipboard 
Print this post

RESULT:





This result is still incorrect - I was typing QWERT.

CURRENT CODE:


Dim Lookup(8) as string * 8
Lookup(0) = "abcdefgh"
Lookup(1) = "ijklmnop"
Lookup(2) = "qrstuvwx"
Lookup(3) = "yz123456"
Lookup(4) = "7890-=[]"
Lookup(5) = "\;',./~!"
Lookup(6) = "@#$%^&*("
Lookup(7) = ")_+{}|:" + CHR$(34)
Lookup(8) = "<>?ABCDE"

C0=15:C1=16:C2=17:C3=21:C4=22:C5=23:C6=24:C7=26 'Setup columns
R0=02:R1=03:R2=04:R3=05:R4=06:R5=07:R6=09:R7=10:R8=25 'Setup rows
SetPin C0,din,pullup:SetPin C1,din,pullup:SetPin C2,din,pullup
SetPin C3,din,pullup:SetPin C4,din,pullup:SetPin C5,din,pullup
SetPin C6,din,pullup:Setpin C7,din,pullup

Setpin R0,dout:SetPin R1,dout:SetPin R2,dout:SetPin R3,dout
SetPin R4,dout:SetPin R5,dout:SetPin R6,dout:Setpin R7,dout
Setpin R8,dout

Delay = 50
DebounceDelay = 10

DEBUG = 1

'MAIN
Do
SetRow(-1)
PAUSE Delay
If ReadColumns() <> 255 then
print ScanMatrix$()
endif
Loop


SUB SetRow(value)
'Row pins 2,3,4,5,6,7,9,10,25
if value = -1 then
'Set all bits to 0. This will allow detecting any keypress
PORT(2,6,9,2,25,1) = 0
else
'Set a bit to 0
PORT(2,6,9,2,25,1) = 511 - (2 ^ value)
endif
END SUB

FUNCTION ReadColumns()
LOCAL FirstScan, ScanCode
'Read the column port and do a simplistic debounce
'Column pins 15,16,17,21,22,23,24,26
FirstScan = PORT(15,3,21,4,26,1)
PAUSE DebounceDelay
ScanCode = PORT(15,3,21,4,26,1)
If FirstScan <> ScanCode then ScanCode = 255
ReadColumns = ScanCode
END FUNCTION

FUNCTION ScanMatrix$()
LOCAL K$,Keys$, RowNumber, ScanCode
Keys$ = ""
RowNumber = 0
Do
SetRow(RowNumber)
ScanCode = ReadColumns()
'Decode the ScanCode
if ScanCode <> 255 then
'One or more keys were pressed
if DEBUG = 1 then PRINT ScanCode
for ColumnNumber = 0 to 7
'Check every bit in the column
if (Scancode and (2 ^ ColumnNumber)) = 0 then
if CAP = 0 AND SFT = 0 then
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
else
'For now use the same lookup table, use RowNumber + 9 when debugged
K$ = MID$(Lookup(RowNumber), ColumnNumber + 1, 1)
endif
if DEBUG = 1 then
PRINT str$(RowNumber) + "," + str$(ColumnNumber) + "=>" + K$
endif
Keys$ = Keys$ + K$
endif
next
endif
RowNumber = RowNumber + 1
Loop until RowNumber > 8

ScanMatrix$ = Keys$
END FUNCTION
Edited by Grogster 2015-08-28
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:25am 27 Aug 2015
Copy link to clipboard 
Print this post

That looks better!
Now the tedious task of filling the lookup table with the right characters.


Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:26am 27 Aug 2015
Copy link to clipboard 
Print this post

Now try with Debug=0 (should be quicker!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:28am 27 Aug 2015
Copy link to clipboard 
Print this post

Also add a ; otherwise each character will be on a new line.
[code]
print ScanMatrix$();
[/code]
The lookup table has only placeholders for the right characters.
If you see a 'v' that should be a 'q' then find it in the lookup table and change the 'v' into a 'q'. Repeat for all characters.
This will allow many different kinds of keyboards to be used, just need to put in the right values in the lookup table.

If you wired the keyboard as in the latest matrix, then you can use it to fill the lookup table quickly.

Can you also test holding two keys down at the same time. (Only do this when you have diodes in your matrix otherwise you can short two row outputs)

Edited by TZAdvantage 2015-08-28
Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:32am 27 Aug 2015
Copy link to clipboard 
Print this post

If you were to type eight characters at a time (as per each Lookup string) then TZA's task of populating the matrix becomes easy.

So take the first Lookup characters 'abcdefgh' and press each in turn to show the eight resulting characters.

With all 9 Lookups reported back then TZA can simply put the resulting characters in the correct place in the lookup matrix.

Hope this makes sense . . . .
 
     Page 7 of 14    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025