Advertisement  

Saturday, 28 March 2020
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #202 - Programmable keypad with two modes Print
Created by Thomas Jensen 

This module uses an AVR microcontroller to interface a cheap numeric keypad. The PIN code is set by the user and stored in EEPROM.

Link to original project can be found here


Information

This module uses an AVR microcontroller to interface a cheap numeric keypad. The PIN code is set by the user and stored in EEPROM. If entered correctly; a one second pulse is sent on either output 1 or 2, depending on the selected mode. A tamper pin will be shorted to 0V when the module is connected. This keypad module is not itself meant to control anything, but it provides trigger signals for other control modules to act upon. It has three LEDs (green, red and alarm) which can be used to convey messages from that other control module.

Modes


Mode 1


To activate mode 1 enter PIN + * (star), a one second green light indicates correct PIN and confirms command.

Mode 2

To activate mode 2 enter PIN + # (number sign), a two seconds green light indicates correct PIN and confirms command.

PIN code


Change PIN


To change PIN enter current PIN + 0 (zero), a yellow light indicates that a new PIN can be entered. The new PIN is entered and confirmed with #, a green light indicates a successful change. Any button other than # will reject the new code and keep the old one, a red light indicates this.

Wrong PIN


When the wrong PIN is entered you get a red light. If the wrong PIN is entered three times the panel will not be usable for one minute. The red light will flash during this period.

I/O
Inputs

    PD2 Keypad R1
    PD3 Keypad R2
    PD4 Keypad R3
    PD5 Keypad R4

Outputs

    PB0 Keypad K1
    PB1 Keypad K2
    PB2 Keypad K3
    PB3 Mode 1 signal
    PB4 Mode 2 signal
    PB5 Green LED indicator
    PB6 Red LED indicator
    PB7 Lifesignal

D-Sub 9-pin

1.  5V
2.  0V
3.  Mode 1 signal
4.  Mode 2 signal
5.  Tamper N.C (short to 0V)
6.  Lifesignal
7.  Alarm LED from other controller
8.  Green LED from other controller
9.  Red LED from other controller

Keypad



1.  n/a
2.  K3
3.  K2
4.  K1
5.  R1
6.  R2
7.  R3
8.  R4

Schematic drawing


Images


 



Source code


'--------------------------------------------------------------
'                   Thomas Jensen | uCtrl.net
'--------------------------------------------------------------
'  file: KEYPAD_v.1.0
'  date: 17/11/2007
'--------------------------------------------------------------
$regfile = "attiny2313.dat"
$crystal = 8000000
Config Portd = Input
Config Portb = Output
Config Watchdog = 1024
 
Dim Lifesignal As Byte , Number As Byte , Row As Byte , Button As Byte
Dim Code1 As Integer , Code2 As Integer , Code3 As Byte , Code4 As Byte , Nr As Byte
Dim Redled As Byte , Greenled As Byte , Amberled As Byte , Code As Integer
Dim Code_p As Integer , Kanal1 As Byte , Kanal2 As Byte , Timeout As Byte , Feil As Integer
Dim Eeprom As Eram Integer , Program As Byte , Feil_a As Byte
 
'Inputs
'PD2 Keypad R1
'PD3 Keypad R2
'PD4 Keypad R3
'PD5 Keypad R4
 
'Outputs
'PB0 Keypad K1
'PB1 Keypad K2
'PB2 Keypad K3
'PB3 Mode 1 signal
'PB4 Mode 2 signal
'PB5 Green LED indicator
'PB6 Red LED indicator
'PB7 Lifesignal
 
Code_p = Eeprom                                             'Get stored code
If Code_p < 0 Then Code_p = 1234                            'If no code use default
Number = 255
 
'Boot
Portb = 0
 
Start Watchdog
 
Main:
'Read keypad
If Button = 0 And Feil = 0 And Number = 255 Then
 
If Row = 0 Then                                             'Keyboard row 1
   Portb.0 = 1
   If Pind.5 = 1 Then Number = 10
   If Pind.4 = 1 Then Number = 7
   If Pind.3 = 1 Then Number = 4
   If Pind.2 = 1 Then Number = 1
   Portb.0 = 0
   End If
 
If Row = 1 Then                                             'Keyboard row 2
   Portb.1 = 1
   If Pind.5 = 1 Then Number = 0
   If Pind.4 = 1 Then Number = 8
   If Pind.3 = 1 Then Number = 5
   If Pind.2 = 1 Then Number = 2
   Portb.1 = 0
   End If
 
If Row = 2 Then                                             'Keyboard row 3
   Portb.2 = 1
   If Pind.5 = 1 Then Number = 11
   If Pind.4 = 1 Then Number = 9
   If Pind.3 = 1 Then Number = 6
   If Pind.2 = 1 Then Number = 3
   Portb.2 = 0
   End If
 
Row = Row + 1                                               'Next row
If Row > 2 Then Row = 0
End If
 
'Reset button status
Portb.0 = 1
Portb.1 = 1
Portb.2 = 1
If Pind.2 = 0 And Pind.3 = 0 And Pind.4 = 0 And Pind.5 = 0 Then Button = 0
Portb.0 = 0
Portb.1 = 0
Portb.2 = 0
 
'Get code
If Number <> 255 Then
Button = 1
Select Case Nr
   Case 0                                                   'Digit 1
   Code1 = Number
   Code1 = Code1 * 1000
   Code = Code1 + Code
   Amberled = 4
   Case 1                                                   'Digit 2
   Code2 = Number
   Code2 = Code2 * 100
   Code = Code2 + Code
   Amberled = 4
   Case 2                                                   'Digit 3
   Code3 = Number
   Code3 = Code3 * 10
   Code = Code3 + Code
   Amberled = 4
   Case 3                                                   'Digit 4
   Code4 = Number
   Code = Code4 + Code
   Amberled = 4
 
   Case 4
   If Program = 1 Then                                      'Program new code
      Select Case Number
         Case 11                                            'Accept
         Code_p = Code
         Eeprom = Code_p
         Greenled = 60
         Case Else                                          'Reject
         Redled = 30
         End Select
      Number = 255
      Program = 0
      Gosub Reset_code_read
      Goto Main
      End If
   If Code = Code_p Then                                    'Code correct
   Feil_a = 0
      Select Case Number
         Case 0                                             'New code
         Program = 1
         Amberled = 40
         Case 10                                            'Channel 1
         Kanal1 = 20
         Greenled = 20
         Case 11                                            'Channel 2
         Kanal2 = 20
         Greenled = 40
         Case Else                                          'Reject
         Redled = 30
         End Select
   Else                                                     'Code failed
      Redled = 30
      Feil_a = Feil_a + 1
   End If
   Timeout = 0
   Number = 255
   Gosub Reset_code_read
   Goto Main
End Select
Nr = Nr + 1
Number = 255
End If
 
'Timeout when entering code
If Nr > 0 And Timeout = 0 Then Timeout = 201
If Timeout > 0 Then Timeout = Timeout - 1
If Timeout = 1 And Nr <> 0 Then
   Gosub Reset_code_read
   Number = 255
   Redled = 30
   End If
 
'Error handling, 3 wrong codes
If Feil_a > 3 And Feil = 0 Then
   Feil = 1200
   Feil_a = 0
   End If
If Feil > 0 And Redled = 0 Then Redled = 4
If Feil > 0 Then Feil = Feil - 1
 
'AmberLED
If Amberled > 0 Then
   Greenled = Amberled
   Redled = Amberled
   Amberled = 0
   End If
 
'GreenLED
If Greenled > 2 Then Portb.5 = 1
If Greenled = 2 Then Portb.5 = 0
If Greenled > 0 Then Greenled = Greenled - 1
 
'RedLED
If Redled > 2 Then Portb.6 = 1
If Redled = 2 Then Portb.6 = 0
If Redled > 0 Then Redled = Redled - 1
 
'Channel1
If Kanal1 = 20 Then Portb.3 = 1
If Kanal1 = 1 Then Portb.3 = 0
If Kanal1 > 0 Then Kanal1 = Kanal1 - 1
 
'Channel2
If Kanal2 = 20 Then Portb.4 = 1
If Kanal2 = 1 Then Portb.4 = 0
If Kanal2 > 0 Then Kanal2 = Kanal2 - 1
 
'Lifesignal
If Lifesignal > 0 Then Lifesignal = Lifesignal - 1
If Lifesignal = 12 Then Portb.7 = 1
If Lifesignal = 1 Then Portb.7 = 0
If Lifesignal = 0 Then Lifesignal = 41
 
Reset Watchdog
Waitms 50
Goto Main                                                   'Loop cycle
End
 
Reset_code_read:                                            'Reset code param.
   Nr = 0
   Code = 0
   Code1 = 0
   Code2 = 0
   Code3 = 0
   Code4 = 0
Return
End