Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

LCD Keypad Shield (ADC Keypad)

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

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Thu Apr 26, 2018 4:31 pm    Post subject: LCD Keypad Shield (ADC Keypad) Reply with quote

Cause I got this module so I wrote basic code for it (LCD connections and kepad with autorepaeat).
Code is like framework "ready to use" Very Happy
This keypad is connected to the only one pin A0

You can watch how this code works -> LINK TO VIDEO

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 32
$framesize = 128

'***********************************************
'*                                             *
'*         LCD KEYPAD SHIELD DEMO              *
'*                                             *
'*    RobotDyn Shield with resistive keypad    *
'*                                             *
'*  Demo shows hardware configuration, and     *
'*      function for reading switches          *
'*                                             *
'*                                   by BARTek *
'***********************************************

Config Submode = New

'***********************************************
'*           ALPHANUMERIC LCD                  *
'***********************************************

 Config Lcdpin = Pin , Rs = Portb.0 , E = Portb.1 , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7
 Config Lcd = 16x2
 Cursor Off , Noblink : Cls

'***********************************************
'*         CONFIG ADC FOR SWITCHES             *
'***********************************************

 Config Adc = Single , Prescaler = Auto , Reference = Avcc

'***********************************************
'*            TIMER2 FOR TIME BASE             *
'***********************************************

 Config Timer2 = Timer , Prescale = 1024 , Compare_a = Disconnect , Clear_timer = 1
 Compare2a = 155                                            '10ms @16MHz

'***********************************************
'*                VARIABLES                    *
'***********************************************

 Const Sw_r = 1
 Const Sw_u = 2
 Const Sw_d = 3
 Const Sw_l = 4
 Const Sw_s = 5
'switches
  Dim Old_key As Byte , Key_cnt As Byte , Key As Byte
'demo
  Dim Lr As Integer , Up_dn As Integer , Flipb As Byte

Function Read_keypad() As Byte

 'function with autorepeat

 Local Adc_read As Word , Read_key As Byte , Key_val As Byte

   Adc_read = Getadc(0)

   Select Case Adc_read
    Case 0 To 100 : Read_key = Sw_r                         'right = 0
    Case 101 To 250 : Read_key = Sw_u                       'up = 145
    Case 251 To 400 : Read_key = Sw_d                       'dwn = 330
    Case 401 To 600 : Read_key = Sw_l                       'left = 506
    Case 601 To 850 : Read_key = Sw_s                       'select = 743
    Case Is > 851 : Read_key = 0                            'no key = 1023
   End Select

   If Read_key <> 0 Then
    If Old_key = Read_key Then

     If Key_cnt < 20 Then
      Incr Key_cnt
       Key_val = 0
     Else
      Key_cnt = 0
       Key_val = Read_key
     End If

    End If

   Else
    Key_cnt = 15
     Key_val = 0
   End If

   Old_key = Read_key
    Read_keypad = Key_val

End Function

'for demo
Locate 1 , 1 : Lcd "UpDn=0"
Locate 2 , 6 : Lcd "< 0 >"
Locate 1 , 14 : Lcd "*"

Do

 If Tifr2.ocf2a = 1 Then                                    '10ms
   Tifr2.ocf2a = 1

   Key = Read_keypad()

 End If

   If Key <> 0 Then

    Select Case Key
     Case Sw_u
      If Up_dn < 9 Then Incr Up_dn
       Locate 1 , 6 : Lcd Up_dn ; " "
     Case Sw_d
      If Up_dn > -9 Then Decr Up_dn
       Locate 1 , 6 : Lcd Up_dn ; " "
     Case Sw_r
      If Lr < 9 Then Incr Lr
       Locate 2 , 7 : If Lr >= 0 Then Lcd " " : Lcd Lr
     Case Sw_l
      If Lr > -9 Then Decr Lr
       Locate 2 , 7 : If Lr >= 0 Then Lcd " " : Lcd Lr
     Case Sw_s
       Locate 1 , 14
       If Flipb = 0 Then
        Lcd " *" : Flipb = 1
       Else
        Lcd "* " : Flipb = 0
       End If

    End Select

    Key = 0
   End If

Loop
End
 
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Thu Apr 26, 2018 6:27 pm    Post subject: Reply with quote

Hi EDC,

I used this keyboard too, it is an excellent tools to learn the ADC to people

I like the way you use the timer

If Tifr2.ocf2a = 1 Then '10ms 'from doc : The compare match event will also set the
' Compare Flag (OCF2A or OCF2B) which can be used to generate an Output Compare interrupt request.

Tifr2.ocf2a = 1

Key = Read_keypad()

End If

Nice Work Mister Expert Wink
JP
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Apr 27, 2018 8:30 pm    Post subject: Reply with quote

Thank you for sharing. And for the nice video demo. Nice clear demo. Well done !
_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO 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