; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; QUALIFY table, string ; Reads a one-character Serin string and looks up the character in ; a table of "qualifiers." If the character matches the next qualifier, ; the routine increments a counter and checks to determine whether all ; qualifiers have been matched. If so, it returns a 1 in w. If not, ; it returns a 0 in w after resetting the counter to the first item in ; the qualifier list. ; Device data and reset vector P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 qual Res d'1' ; Pointer to qualifiers. buffer equ d'31' ; Serin string address. org 0 P_word ADDWF pcl RETLW d'6' ; No. of elements in password. RETLW 'S' ; The password. RETLW 'e' RETLW 's' RETLW 'a' RETLW 'm' RETLW 'e' ; Below is a dummy Serin routine intended for use on the PSIM simulator. ; Wait until PSIM reaches the "ret" below, then change the data at buffer-1 ; (hex address 1E). You can step through Qualify to see how it works. ; The password "Sesame" is 53h, 65h, 73h, 61h, 6Dh, 65h. Serin MOVLW 'A' ; Dummy Serin for demo. MOVWF buffer-1 RETLW 0h ; Enter character data here. start MOVLW d'4' ; Input for serial data. TRIS 5h MOVLW d'0' ; All outputs for LEDs TRIS 6h CLRF 6h ; LEDs off to begin. CLRF qual ; Clear qual to start. start_loop CALL Serin ; Receive one byte. CALL Qualify ; Check it against password. IORLW 0h ; IF w=1 THEN LEDs_on BTFSC status,z ; ELSE :loop GOTO start_loop MOVLW d'255' ; Password match: toggle LEDs. XORWF 6h GOTO start ; Do it again. ; Upon entry, a one-byte Serin string should be stored at buffer-1. ; Qualify will check it against the next entry in the P_word table, and ; if there's a match, will increment the qualifier counter qual. If there's ; no match, it will clear qual, and check the character against the first ; entry in P_word. This second step prevents Qualify from failing to ; recognize passwords after a false start, like "SeSesame." Qualify INCF qual,w ; Look up next item in P_word. CALL P_word subwf buffer-1,0 ; Compare it to received byte by BTFSS status,z ; subtraction. If result <> 0, no match. GOTO Qualify_no_match INCF qual ; Match: increment qual pointer and CLRW ; get the 0th item in the table (number CALL P_word ; of chars in the password). subwf qual,0 ; IF qual = no._of_P_word_chars THEN BTFSC status,z ; return with 1 in w. RETLW d'1' ; ELSE return with 0 in w. RETLW 0h Qualify_no_match MOVF qual ; IF qual = 0, return with 0 in w. BTFSC status,z RETLW 0h CLRF qual ; ELSE qual = 0: GOTO Qualify (check GOTO Qualify ; char against 0th password entry). end