Created
February 23, 2016 13:33
-
-
Save TGNThump/fe4d482779e82338d00d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_TRIS: | |
let trisc = %1010110 | |
_VARS: | |
symbol flgs = b0 | |
symbol atmpts = b1 | |
symbol digit = b2 | |
symbol currin = b3 | |
symbol lastin = b4 | |
symbol col1 = b5 | |
symbol col2 = b6 | |
symbol col3 = b7 | |
_CONSTS: | |
table 0, (%01100000, %10100000, %11100000) | |
symbol lockflg = 0x00 | |
symbol failflg = 0x01 | |
symbol alarmflg = 0x02 | |
symbol codelngth = 0x02 | |
symbol resetbtn = %01001000 | |
main: | |
gosub lock | |
do | |
if flgs bit lockflg set then | |
gosub locked | |
else | |
gosub unlocked | |
endif | |
debug | |
loop | |
end | |
locked: | |
gosub readin | |
select case currin | |
case lastin | |
return | |
case 0x00 | |
return | |
case resetbtn | |
if digit != 0 then | |
inc atmpts | |
gosub rset | |
endif | |
else | |
if flgs bit failflg clear then | |
readtable digit, b7 | |
if currin != b7 then | |
setbit flgs, failflg | |
elseif digit = codelngth then | |
gosub unlock | |
return | |
endif | |
endif | |
if flgs bit failflg set then | |
if atmpts >= 0x03 then | |
setbit flgs, alarmflg | |
endif | |
endif | |
inc digit | |
endselect | |
return | |
unlocked: | |
gosub readin | |
select case currin | |
case lastin | |
return | |
case 0x00 | |
return | |
case resetbtn | |
gosub lock | |
endselect | |
return | |
readin: | |
let lastin = currin | |
let currin = 0x00 | |
;col1 | |
if flgs bit alarmflg set then | |
let portc = 0x21 | |
else | |
let portc = 0x20 | |
endif | |
readportc col1 | |
let col1 = col1 & 0xDE | |
if col1 != 0x00 then | |
let col1 = col1 >> 0x01 | |
let currin = col1 + %01000000 | |
return | |
endif | |
;col2 | |
if flgs bit alarmflg set then | |
let portc = 0x81 | |
else | |
let portc = 0x80 | |
endif | |
readportc col2 | |
let col2 = col2 & %01111110 | |
if col2 != 0x00 then | |
let col2 = col2 >> 0x01 | |
let currin = col2 + %10000000 | |
return | |
endif | |
;col3 | |
if flgs bit alarmflg set then | |
let portc = %00001001 | |
else | |
let portc = %00001000 | |
endif | |
readportc col3 | |
let col3 = col3 & %11110110 | |
if col3 != 0x00 then | |
let col3 = col3 >> 0x01 | |
let currin = col3 + %11000000 | |
return | |
endif | |
if flgs bit alarmflg set then | |
let portc = 0x01 | |
else | |
let portc = 0x00 | |
endif | |
return | |
rset: | |
let digit = 0x00 | |
let portc = 0x01 | |
clearbit flgs, failflg | |
return | |
unlock: | |
gosub rset | |
clearbit flgs, lockflg | |
clearbit flgs, alarmflg | |
let atmpts = 0x00 | |
return | |
lock: | |
gosub rset | |
setbit flgs, lockflg | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment