0% found this document useful (0 votes)
14 views5 pages

Mcu Projectpbcb

Uploaded by

Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Mcu Projectpbcb

Uploaded by

Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

'--------------------------------------------------------------

' (c) 1995-2006 MCS Electronics


'--------------------------------------------------------------
' File: Password based circuit breaker.BAS
' Coded by : Ahmad Saeed
' ZAM ZAM MICRO TECH
'--------------------------------------------------------------
'$sim
Rem The $sim statement will remove long delays for the simulator
Rem It is important to remove this statement when compiling the final file
$regfile = "89c55wd.dat"

$crystal = 11059200 ' Baud rate accurate


Xtal
$large

'Lmp Alias P3.0


'Mtr Alias P3.1

Column1 Alias P2.0 'The columns on my


Keyboard
Column2 Alias P2.1 'have 10k ohm pullup
resistors.
Column3 Alias P2.2

Row1 Alias P2.7


Row2 Alias P2.6
Row3 Alias P2.5
Row4 Alias P2.4

Config Lcd = 16 * 2 'configure lcd screen

Config Lcdpin = Pin , Db4 = P1.4 , Db5 = P1.5 , Db6 = P1.6 , Db7 = P1.7 , E =
P3.5 , Rs = P3.7

Dim A As Byte , L As Byte 'Flag indicating a


key is pressed
Dim C As Byte

Dim S1 As String * 1
Dim S2 As String * 8 'Character of key
pressed
Dim S3 As String * 8

P3.0 = 0
P3.1 = 0

Reset P3.6
Lcdinit

Wait 1
C = 17
Cls
Lcd " Enter Password"
Locate 2 , 2
Wait 1

Do
Gosub Keyscan
If A = 1 Then
If C < 10 Then
If Len(s3) < 8 Then
S1 = Str(c)
S2 = S3
S3 = S2 + S1
Locate 2 , 2
Lcd S3
End If
Waitms 250
Waitms 250
C = 17 : A = 0
Elseif C = 14 Then
L = Len(s3)
If L > 1 Then
L = L - 1
S2 = Left(s3 , L)
S3 = S2
Elseif L = 1 Then
S3 = ""
End If
Locate 2 , 2
Lcd " "
Locate 2 , 2
Lcd S3
Waitms 250
Waitms 250
C = 17 : A = 0

Elseif C = 15 Then
If S3 = "12345" Then
If P3.1 = 1 Then
P3.1 = 0
Cls
Lcd " MOTOR OFF"
Elseif P3.1 = 0 Then
P3.1 = 1
Cls
Lcd " MOTOR ON "
End If

Wait 1
S3 = ""
Cls
Lcd " Enter Password"
Locate 2 , 2

Elseif S3 = "54321" Then


If P3.0 = 1 Then
P3.0 = 0
Cls
Lcd " LAMP OFF"

Elseif P3.0 = 0 Then


P3.0 = 1
Cls
Lcd " LAMP ON "
End If
Wait 1
S3 = ""

Lcd " Enter Password "


Locate 2 , 2
Else
Cls
Lcd " Wrong Password"
Wait 1
Cls
Lcd " Enter Password"
Locate 2 , 2

End If

End If
End If
Loop

End

Keyscan:

'This is an simple 4x4 keyboard decoder with A to D and the * and # commented out

'----------- 1st Row ----------


Row1 = 0 'These feed the
keyboard with a logic zero
Row2 = 1 'then a set of tests
to see which
Row3 = 1 'column follows the
row, this computes to
Row4 = 1 'the intersection
which is the key linking
'row to column.
Debounce Column3 , 0 , 1_but , Sub
Debounce Column2 , 0 , 2_but , Sub
Debounce Column1 , 0 , 3_but , Sub
'----------- 2nd Row ----------
Row1 = 1
Row2 = 0
Row3 = 1
Row4 = 1

Debounce Column3 , 0 , 4_but , Sub


Debounce Column2 , 0 , 5_but , Sub
Debounce Column1 , 0 , 6_but , Sub
'----------- 3rd Row ----------
Row1 = 1
Row2 = 1
Row3 = 0
Row4 = 1

Debounce Column3 , 0 , 7_but , Sub


Debounce Column2 , 0 , 8_but , Sub
Debounce Column1 , 0 , 9_but , Sub

'----------- 4th Row ----------


Row1 = 1
Row2 = 1
Row3 = 1
Row4 = 0

Debounce Column3 , 0 , Star_but , Sub


Debounce Column2 , 0 , 0_but , Sub
Debounce Column1 , 0 , Hash_but , Sub

'------------------------------

Return

'These subroutines provide the vars C and A


'with values from the rows debounce commands.

'---------- 1st Row -----------


1_but:
C = 1
A = 1
Return

2_but:
C = 2
A = 1
Return

3_but:
C = 3
A = 1
Return

'-------- 2nd Row -----------

4_but:
C = 4
A = 1
Return

5_but:
C = 5
A = 1
Return
6_but:
C = 6
A = 1
Return

'-------- 3rd Row -----------

7_but:
C = 7
A = 1
Return

8_but:
C = 8
A = 1
Return

9_but:
C = 9
A = 1
Return

'-------- 4th Row -----------

Star_but:
C = 14
A = 1
Return

0_but:
C = 0
A = 1
Return

Hash_but:
C = 15
A = 1
Return

You might also like