home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
788.seq
next >
Wrap
Text File
|
1991-01-22
|
11KB
|
310 lines
\ Thorn Model 788 Keypad Reader by Andrew McKewan
comment:
The Model 780 reader accepts ABA or EMPI cards, selected by an option
switch. The output format is Thorn 31-bit Wiegand. Keypad digits are
reported individually via a 1200 baud RS-232 output line.
comment;
\ Port Pin Assignments
PORTA 0 2CONSTANT AUX-OUT \ Auxilliary input
PORTA 1 2CONSTANT AUX-IN \ Auxilliary output
\ PORTA 2 2CONSTANT OUT0 \ Wiegand data "0" output
\ PORTA 3 2CONSTANT OUT1 \ Wiegand data "1" output
PORTA 4 2CONSTANT G-XLED \ Green external led
PORTA 5 2CONSTANT R-XLED \ Red external led
PORTA 6 2CONSTANT LED-CTL \ LED control line
PORTA 7 2CONSTANT TAMPER \ Tamper switch
PORTB 0 2CONSTANT PROMCS \ EEPROM chip select
PORTB 1 2CONSTANT PROMSK \ EEPROM serial clock
PORTB 2 2CONSTANT PROMDI \ EEPROM data in
PORTB 3 2CONSTANT PROMDO \ EEPROM data out
PORTB 4 2CONSTANT BUZZER \ Buzzer control
PORTB 5 2CONSTANT G-LED \ Green led control
PORTB 6 2CONSTANT Y-LED \ Yellow led control
PORTB 7 2CONSTANT R-LED \ Red led control
PORTD 2 2CONSTANT OPTION-A \ Option switch A
PORTD 3 2CONSTANT OPTION-B \ Option switch B
PORTD 4 2CONSTANT OPTION-C \ Option switch C
PORTD 5 2CONSTANT OPTION-D \ Option switch D
$50 CONSTANT RAM \ start of ram
TEMP DROP ( allocate it now )
\ ***************************************************************************
\ LED Control
CODE DARK R-LED BSET, Y-LED BSET, G-LED BSET, RTS, END-CODE
CODE RED R-LED BCLR, Y-LED BSET, G-LED BSET, RTS, END-CODE
CODE YELLOW R-LED BSET, Y-LED BCLR, G-LED BSET, RTS, END-CODE
CODE GREEN R-LED BSET, Y-LED BSET, G-LED BCLR, RTS, END-CODE
: FLASH ( -- ) \ flash led green then dark.
GREEN 500MS DARK 500MS ;
\ ***************************************************************************
\ Buzzer
MACRO BUZZER-ON BUZZER BCLR, END-MACRO
MACRO BUZZER-OFF BUZZER BSET, END-MACRO
: (BEEP) ( duration -- )
BUZZER-ON MS BUZZER-OFF ;
: BEEP 30 (BEEP) ;
\ **************************************************************************
\ Scan keypad
\ *** NOT READY FOR LIBRARY ***
40 CONSTANT DEBOUNCE ( units of 512 uS )
VARIABLE FLAGS
FLAGS 0 2CONSTANT KEYFLG \ set when key detected
LABEL SCANCODE
( 0-5 ) $09 C, $06 C, $03 C, $12 C, $44 C, $41 C,
( 6-9, *, # ) $50 C, $24 C, $21 C, $30 C, $0C C, $18 C, END-CODE
LABEL KEYDN ( set Z flag if no key is down )
PORTC LDA, A COM, $7F # AND, RTS, END-CODE
LABEL SCAN ( carry set if key down, key in X )
KEYDN JSR, 0= NOT
IF, 11 # LDX, ( 9 if numeric only )
BEGIN, SCANCODE ,X CMP, 0= IF, SEC, RTS, THEN,
X DEC, 0<
UNTIL,
THEN, CLC, RTS, END-CODE
LABEL KEYUP \ Clear KEYFLG if key is released and debounced. Otherwise
\ just return.
KEYDN JSR, 0=
IF, CARH LDA, CARL TST, TEMP 1+ STA,
BEGIN, KEYDN JSR, 0=
WHILE, CARH LDA, CARL TST, TEMP 1+ SUB,
DEBOUNCE # CMP, < NOT
UNTIL, KEYFLG BCLR, THEN,
THEN, RTS, END-CODE
CODE ?KEY ( -- key true | false )
\ Check keypad. If a key is down, return the key value
\ and a true flag. If no key is down, return a false flag.
\ If KEYFLG is set, then we just returned a key and we
\ must wait for it to be released.
TEMP STX,
KEYFLG SET IF, KEYUP JSR, 2 $ BRA, THEN,
SCAN JSR, 2 $ BCC,
1 $: TEMP 1+ STX, ( key )
CARH LDA, CARL TST, TEMP 2+ STA, ( timer )
BEGIN, SCAN JSR, 2 $ BCC,
TEMP 1+ CPX, 1 $ BNE,
CARH LDA, CARL TST, TEMP 2+ SUB,
DEBOUNCE # CMP, < NOT
UNTIL,
KEYFLG BSET, ( got a key )
TXA, TEMP LDX, PUSH,
TRUE # LDA, PUSH,
RTS,
2 $: TEMP LDX, A CLR, PUSH, RTS, ( no key )
END-CODE
\ ***************************************************************************
\ SCI transmit for keypad data
: SCI-INIT ( -- )
$00 SCCR1 ! \ 8 data bits, 1 stop bit
$08 SCCR2 ! \ enable transmitter, no SCI interrputs
$33 BAUD ! ; \ 1200 baud
CODE EMIT ( char -- ) \ send byte to sci port
BEGIN, TDRE SET UNTIL,
POP, SCDAT STA,
RTS, END-CODE
CODE KEY ( -- char ) \ get byte from sci port (not used here)
BEGIN, RDRF SET UNTIL,
SCDAT LDA, PUSH,
RTS, END-CODE
\ ***************************************************************************
\ Keypad
LABEL KEYCODES
$F7 C, $F0 C, $F4 C, $F8 C, $F1 C, $F5 C,
$F9 C, $F2 C, $F6 C, $FA C, $F3 C, $FB C,
END-CODE
CODE KEYCODE ( key# -- code )
TEMP STX,
0 ,X LDX, KEYCODES ,X LDA,
TEMP LDX, 0 ,X STA,
RTS, END-CODE
: DO-KEY ( key -- )
BEEP
\ SEND-KEY ( wiegand key output for testing )
KEYCODE EMIT \ send to SCI port
;
\ ***************************************************************************
\ LED Control
comment:
LED-CTL AUX-IN LED
1 1 RED
0 1 GREEN
1 0 YELLOW
0 0 YELLOW
LED-CTL = PORTA 6
AUX-IN = PORTA 1
comment;
: DO-LED ( -- )
PORTA @ $02 AND 0= IF YELLOW EXIT THEN
PORTA @ $40 AND IF RED EXIT THEN
GREEN ;
\ ***************************************************************************
\ ABA Card Processing
\
\ The reader accepts 12-digit ABA cards. The first six digits are converted
\ to binary and stored as the site code. The next six digits are the ID
\ number. If the site code overflows 8 bits or the ID overflows 16 bits then
\ they are set to the maximum value (255 and 65535).
2 array buf \ buffer for binary conversion
variable overflow \ set if result overflows 16 bits
code *10 ( -- ) \ multiply buf * 10
temp stx,
buf 1 + lda, 10 # ldx, mul,
buf 1 + sta, temp 1+ stx,
buf lda, 10 # ldx, mul, x tst, 1 $ bne,
temp 1 + add, buf sta, 2 $ bcc,
1 $: overflow 0 bset,
2 $: temp ldx, rts, end-code
code add ( n -- ) \ add n to buf
pop,
buf 1 + add, buf 1 + sta,
buf lda, 0 # adc, buf sta, 1 $ bcc,
overflow 0 bset,
1 $: rts, end-code
: conv ( n -- ) \ convert n digits to binary in buf
overflow off
buf 2 erase
( n ) for *10 digit add next ;
: conv-site ( -- ) \ convert 6 digits of card to site
6 conv
overflow @ buf @ or
if 255 ( overflow ) else buf 1 + @ then
data 1 + ! ;
: conv-id ( -- ) \ convert 6 digits of card to id
6 conv
overflow @
if 255 dup ( overflow ) else buf 2@ then
data 2 + 2! ;
: convert ( -- ) \ convert 12-digit ABA to binary
rewind margin
digit drop ( soc )
conv-site
conv-id ;
: do-ABA ( -- ) \ check card data. If valid send in
\ Thorn 31-bit Wiegand format.
valid-aba
#digits @ 15 = and ( 12 data digits on card )
if convert
send-thorn-31bits
then ;
\ ***************************************************************************
\ EMPI Card Processing
\
\ Valid Thorn job codes are from 2000 to 2255. We add $30 to the job code
\ to bring it into the range $0800 to $08FF. Then we check the high byte
\ and make sure it is 8. The site code to transmit is in the low byte.
\ An invalid job code is reported as site code 255.
code bias ( -- ) \ ad $30 to job code
data 1+ lda, $30 # add, data 1+ sta,
data lda, 0 # adc, data sta, rts, end-code
: job-ok ( -- f ) \ return true if thorn job code
data @ 8 = ;
: test \ not in production code
portd @ 8 and 0= ( option b on )
if #bits @ 10 >
if send-all
then
then ;
: do-EMPI ( -- ) \ check for valid EMPI data with correct
\ job code. If valid send card in Thorn
\ 31-bit Wiegand format.
valid-empi
if bias
job-ok not if 255 data 1 + ! then
send-thorn-31bits
then ;
: do-card ( -- )
portd @ 4 and ( option-a off )
if do-EMPI
else do-ABA
then ;
: READER ( -- )
CLEAR-CARD ENABLE
BEGIN DO-LED
?KEY IF DISABLE DO-KEY EXIT THEN
CARD-EVENT
UNTIL
CARD-DONE
DO-CARD ;
: MAIN
$01 PORTA ! $0D DDRA !
$F0 PORTB ! $F7 DDRB !
$00 PORTC ! $00 DDRC !
STACK 4 $EE FILL \ for stack trace
5 SKIP0 ! \ card lead-in
10 OUTPUT ! \ Wiegand 1 ms bit time
SCI-INIT ( init serial port )
4 FOR FLASH NEXT \ I'm ok
BEGIN READER AGAIN ;
\ ***************************************************************************
\ Interrupt Vector Initialization
$100 $1FF4 !-T \ SPI transfer complete
$100 $1FF6 !-T \ SCI serial
EDGE $1FF8 !-T \ Timer
$100 $1FFA !-T \ External IRQ
$100 $1FFC !-T \ SWI
$100 $1FFE !-T \ Reset