di2822l1.txt ;************************************************************************************************ ; LISTING 1 - ZERO-POWER PHOTOGATE-ASSEMBLY PROGRAM ; ; "Extend the timing capabilities of a PC," EDN, Jan 10, 2002, pg 74 ; ;**************************************************************************************************** ; hardware connections needed are as follows ; PC parallel port connections (see below for software aspect) ; DAT0 pin11, VALID pin 10, SEND pin 2, SIGNAL* is not used but reserve pin 3 ; TRANS_ON/LED_ON pin 4 are power output from parallel port ; MCLR* is output from parallel port pin 5 causing reset if low ; Vdd is output from parallel port pin 6 for power include "D:\pic\mplab\P16f84.inc" __CONFIG (_XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF) ; Equates Bank0RAM equ 20H DATO equ 0 VALID equ 1 SEND equ 2 SIGNAL equ 3 ; Variables cblock Bank0RAM BYTE1 BYTE2 BYTE3 BYTE4 BYTEO COUNT8 endc ; org 0000H goto MAINP org 0004H ; should never get here goto OVERFLO ; error exit if INT MAINP bsf STATUS,RP0 ; select Bank 1 ; PORT A detects signal on Bit 3, communicates with PC on 0-2 ; Bit 0 is serial data out (DATA) ; Bit 1 is valid data indicator (VALID) ; Bit 2 is input from PC saying it is ready (SEND) bcf TRISA, DATO ; PORT A Bit 0 output (DATO) bcf TRISA, VALID ; PORT A Bit 1 output (VALID) bsf TRISA, SEND ; PORT A Bit 2 input (SEND) bsf TRISA, SIGNAL ; PORT A Bit 3 input (signal) bcf STATUS,RP0 ; select Bank 0 clrf BYTE1 clrf BYTE2 clrf BYTE3 clrf BYTE4 ; all counter bytes to 0 bcf PORTA,VALID ; no valid data for PC btfsc PORTA,SIGNAL ; signal must NOT be on now goto OVERFLO ; error exit if it is WAITI btfss PORTA,SIGNAL ; wait for signal on PORTA goto WAITI goto INC1 INC4 incfsz BYTE4,F ; incr BYTE4 if BYTE3 over goto INC1 goto OVERFLO ; if BYTE4 over, error exit INC3 incfsz BYTE3,F ; incr BYTE3 if BYTE2 over goto INC1 goto INC4 INC2 incfsz BYTE2,F ; incr BYTE2 if BYTE1 over GTI1 goto INC1 goto INC3 INC1 btfss PORTA,SIGNAL ; signal still on PORTA? goto SERIAL ; if gone, transmit results incfsz BYTE1,F ; incr&test goto INC1 ; if nonzero goto INC2 ; if zero overflow to BYTE2 ; three-wire handshake with PC ; byte data is shifted out on PORTA DATO lowest->highest SERIAL movf BYTE1,W movwf BYTEO call BYTOUT movf BYTE2,W movwf BYTEO call BYTOUT movf BYTE3,W movwf BYTEO call BYTOUT movf BYTE4,W movwf BYTEO call BYTOUT goto MAINP BYTOUT movlw 8 movwf COUNT8 WAITS btfss PORTA,SEND ; wait for PC to allow send goto WAITS ; if clear check again SHIFC bcf STATUS,C ; clear carry flag rrf BYTEO,F ; BYTEO into carry btfss STATUS,C ; check carry bit goto OUT0 ; if 0 output 0 goto OUT1 ; if 1 output 1 OUT0 bcf PORTA,DATO goto DEC8 OUT1 bsf PORTA,DATO DEC8 bsf PORTA,VALID ; valid data is now there WAITL btfsc PORTA,SEND ; wait for send to be lowered goto WAITL bcf PORTA,VALID ; lower valid decfsz COUNT8 goto WAITS return OVERFLO comf BYTE1,F ; all bytes must be zero comf BYTE2,F ; set to FF for all comf BYTE3,F ; which means error comf BYTE4,F goto SERIAL ; and output error END