Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

TM1628 Keypad problem

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
pratik

Bascom Member



Joined: 13 Oct 2005
Posts: 55

india.gif
PostPosted: Sun Dec 04, 2016 8:03 pm    Post subject: TM1628 Keypad problem Reply with quote

I am working on TM1628 LED Display & keypad driver IC
I am able to display the digits but facing problem to read the keypad data
Can anyone help me to solve the problem

The program is just to display 0 to 6 than read the keypad & display the read data

My code

Code:

$regfile = "m16def.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
$baud = 9600


Config Portc.0 = Output                                     'Strobe                                   '
Config Portc.1 = Output                                     'Clock
Config Portc.2 = Output                                     'Data   input / output
Config Portb.0 = Output                                     ' Extra Test LED

Strobe Alias Portc.0
Clk Alias Portc.1
Dio Alias Portc.2
Led Alias Portb.0

Config strobe = Output
Config Dio = Output
Dim command_1 As Byte
Dim command_2 As Byte
Dim command_3 As Byte
Dim command_4 As Byte


Dim D0 As Byte
Dim D1 As Byte
Dim D2 As Byte
Dim D3 As Byte
Dim D4 As Byte
Dim D5 As Byte
Dim D6 As Byte
Dim D7 As Byte
Dim D8 As Byte
Dim D9 As Byte
Dim Dm As Byte
Dim Readkey As Byte
Dim Rd As Byte
Dim Scankey As Byte
Dim I As Byte

Command_1 = &B00000011                                      'Display Mode setting  7 digit 10 Segment
Command_2 = &B01000000                                      'data setting in  write data & Inr display address
Readkey = &B01000010                                        'Data setting in read key
Command_3 = &B11000000                                      'Address setting  00H
Command_4 = &B10001000                                      'display control pulse 1/16 & Display On
Scankey = &B10000000                                        ' Display Controler Display off & key scan
Dm = &B00000000                                             ' dummy data to blank the display

' Display code for 7 segment
D0 = &B00111111                                             ' =0
D1 = &B00000110                                             ' =1
D2 = &B01011011                                             ' =2
D3 = &B01001111                                             ' =3
D4 = &B01100110                                             ' =4 **
D5 = &B01101101                                             ' =5
D6 = &B01111101                                             ' =6
D7 = &B00000111                                             ' =7
D8 = &B01111111                                             ' =8
D9 = &B01101111                                             ' =9

' init TM 1628
Gosub Tm1628_init
Waitms 5

' Blank TM 1628
Gosub Tm1628_blank
Waitms 5


Do

 Set Strobe
 Reset Strobe
Shiftout Dio , Clk , command_3 , 2
 Set strobe
 Reset strobe
Shiftout Dio , Clk , command_2 , 2


'send 0 to 6 for display
'need to send dummy blank data after every valid data for using 7 segment
Shiftout Dio , Clk , D0 , 2
Shiftout Dio , Clk , Dm , 2
Shiftout Dio , Clk , D1 , 2
Shiftout Dio , Clk , Dm , 2
Shiftout Dio , Clk , D2 , 2
Shiftout Dio , Clk , Dm , 2
Shiftout Dio , Clk , D3 , 2
Shiftout Dio , Clk , Dm , 2
Shiftout Dio , Clk , D4 , 2
Shiftout Dio , Clk , Dm , 2
Shiftout Dio , Clk , D5 , 2
Shiftout Dio , Clk , Dm , 2
Shiftout Dio , Clk , D6 , 2
Shiftout Dio , Clk , Dm , 2
Set Strobe

Wait 2

' Read key & display on first segment

Gosub Tm1628_blank
Waitms 5

Gosub Tm1628_key

Gosub Tm1628_display

Wait 2

Loop

Tm1628_init:
  Set Strobe
  Reset Strobe
Shiftout Dio , Clk , Command_2 , 2
  Set Strobe
    Waitms 3
  Reset Strobe
Shiftout Dio , Clk , Command_3 , 2
  Set Strobe
    Waitms 3
  Reset Strobe
Shiftout Dio , Clk , Command_1 , 2
  Set Strobe
    Waitms 3
  Reset Strobe
Shiftout Dio , Clk , command_4 , 2
  Set Strobe
Return


Tm1628_blank:

 Set Strobe
 Reset Strobe
Shiftout Dio , Clk , command_2 , 2
'send Blank data to TM 1828
  For I = 1 To 14

Shiftout Dio , Clk , Dm , 2

  Next I

Set strobe

Return


Tm1628_key:

' enable scan key  & disable display
 Set Strobe
 Reset Strobe
Shiftout Dio , Clk , Scankey , 2
 Set Strobe

 ' start read key
Waitms 3
  Reset Strobe
 Shiftout Dio , Clk , Readkey , 2

Waitms 200
' read key
Shiftin Dio , Clk , Rd , 2

 Set Strobe
' disable key scan & enable display
 Reset strobe
Shiftout Dio , Clk , Command_4 , 2
 Set strobe

Return

Tm1628_display:

  Set strobe
  Reset strobe
Shiftout Dio , Clk , Command_2 , 2
  Reset Strobe
Shiftout Dio , Clk , Command_3 , 2
  Set Strobe

Shiftout Dio , Clk , Rd , 2

  Set Strobe

Return

End
 


(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.7.8 )
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Dec 05, 2016 10:37 am    Post subject: TM1638... Reply with quote

It looks a lot like the TM1638 code. PaulVK did a great job to get that working. Perhaps a search in this forum.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
pratik

Bascom Member



Joined: 13 Oct 2005
Posts: 55

india.gif
PostPosted: Mon Dec 05, 2016 4:00 pm    Post subject: Reply with quote

Thanks Ben
Back to top
View user's profile
pratik

Bascom Member



Joined: 13 Oct 2005
Posts: 55

india.gif
PostPosted: Mon Dec 05, 2016 8:25 pm    Post subject: Reply with quote

finally I can read the key code
but most of the times even after pressing the keys it give me 0 value.

Code:


Dim Keys As Long                                          

'break the longs into four bytes
Dim Key(4) As Byte At Keys Overlay


Tm1628_key:

 ' start read key
   Set Strobe
  Reset Strobe
 Shiftout Dio , Clk , Readkey , 2
'Config Portc.2 = Input
Waitms 1
' read 32 bit key code
Shiftin Datain , Clk , Keys , 2

'Config Portc.2 = Output
Waitms 3
 Set Strobe

 ' disable key scan & enable display
 Reset Strobe
Shiftout Dio , Clk , Command_4 , 2
 Set Strobe

 Reset Strobe
Shiftout Dio , Clk , Command_2 , 2
  Set Strobe
Return

Tm1628_display:

Gosub Tm1628_init
Waitms 5

 Set Strobe
 Reset Strobe
Shiftout Dio , Clk , Command_3 , 2
 Set Strobe
 Reset Strobe
Shiftout Dio , Clk , Command_2 , 2

 For I = 1 To 4
Shiftout Dio , Clk , Key(i) , 2
Print Key(i) ; " ";

 Next I
   Print

  Set Strobe

Return

End
[/code]
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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