SilentScreamer
Senior Member
I am trying to program an alarm using 28X1 chip for my GCSE Electronics coursework. I am going to try and use a reprogrammable 4 digit code and a keypad. I've already made the code below but haven't made a prototype yet (I'm still awaiting delivery of the chip ect.), so I'm uncertain if the code works (it seems to when I simulate it). Assuming it does, is there anyway I can reduce the size of the code? Else if anyone knows anything that will not work could I have suggestions on alternative methods of doing it?
EDIT: I have my Keypad connected so that the columns are connected to Inputs 0-2 and the rows connected to Outputs 0-3
Code:
NewPassChar1:
'Check column 1
let pins=%00000001
if pin0=1 then
let b0=1
goto NewPassChar2
endif
if pin1=1 then
let b0=4
goto NewPassChar2
endif
if pin2=1 then
let b0=7
goto NewPassChar2
endif
'Check column 2
let pins=%00000010
if pin0=1 then
let b0=2
goto NewPassChar2
endif
if pin1=1 then
let b0=5
goto NewPassChar2
endif
if pin2=1 then
let b0=8
goto NewPassChar2
endif
if pin3=1 then
let b0=0
goto NewPassChar2
endif
'Check column 3
let pins=%00000100
if pin0=1 then
let b0=3
goto NewPassChar2
endif
if pin1=1 then
let b0=6
goto NewPassChar2
endif
if pin2=1 then
let b0=9
goto NewPassChar2
endif
'Loop
goto NewPassChar1
' Charactor Two
NewPassChar2:
'Check column 1
let pins=%00000001
if pin0=1 then
let b1=1
goto NewPassChar3
endif
if pin1=1 then
let b1=4
goto NewPassChar3
endif
if pin2=1 then
let b1=7
goto NewPassChar3
endif
'Check column 2
let pins=%00000010
if pin0=1 then
let b1=2
goto NewPassChar3
endif
if pin1=1 then
let b1=5
goto NewPassChar3
endif
if pin2=1 then
let b1=8
goto NewPassChar3
endif
if pin3=1 then
let b1=0
goto NewPassChar3
endif
'Check column 3
let pins=%00000100
if pin0=1 then
let b1=3
goto NewPassChar3
endif
if pin1=1 then
let b1=6
goto NewPassChar3
endif
if pin2=1 then
let b1=9
goto NewPassChar3
endif
'Loop
goto NewPassChar2
' Charactor Three
NewPassChar3:
'Check column 1
let pins=%00000001
if pin0=1 then
let b2=1
goto NewPassChar4
endif
if pin1=1 then
let b2=4
goto NewPassChar4
endif
if pin2=1 then
let b2=7
goto NewPassChar4
endif
'Check column 2
let pins=%00000010
if pin0=1 then
let b2=2
goto NewPassChar4
endif
if pin1=1 then
let b2=5
goto NewPassChar4
endif
if pin2=1 then
let b2=8
goto NewPassChar4
endif
if pin3=1 then
let b2=0
goto NewPassChar4
endif
'Check column 3
let pins=%00000100
if pin0=1 then
let b2=3
goto NewPassChar4
endif
if pin1=1 then
let b2=6
goto NewPassChar4
endif
if pin2=1 then
let b2=9
goto NewPassChar4
endif
'Loop
goto NewPassChar3
' Charactor Four
NewPassChar4:
'Check column 1
let pins=%00000001
if pin0=1 then
let b3=1
goto Main
endif
if pin1=1 then
let b3=4
goto Main
endif
if pin2=1 then
let b3=7
goto Main
endif
'Check column 2
let pins=%00000010
if pin0=1 then
let b3=2
goto Main
endif
if pin1=1 then
let b3=5
goto Main
endif
if pin2=1 then
let b3=8
goto Main
endif
if pin3=1 then
let b3=0
goto Main
endif
'Check column 3
let pins=%00000100
if pin0=1 then
let b3=3
goto Main
endif
if pin1=1 then
let b3=6
goto Main
endif
if pin2=1 then
let b3=9
goto Main
endif
'Check column 3
let pins = %00000000
'Loop
goto NewPassChar4