Processor 16F84 Radix DEC EXPAND include "p16F84.inc" ;Crystal 4Mhz _ResetVector set 0x00 _IntVector set 0x04 TXByte EQU 0x10 Counter EQU 0x11 RXByte EQU 0x12 IRQC EQU 0x13 L1 EQU 0X14 L2 EQU 0X15 Temp EQU 0X16 Address EQU 0x17 RX1 EQU 0x18 RX2 EQU 0x19 Flag EQU 0x20 DO EQU 4 CLK EQU 2 CS EQU 1 DIN EQU 3 IRQ EQU 5 SETDELAY EQU 6 WCONFIGHI EQU b'11000010' WCONFIGLO EQU b'00101011' RCONFIGHI EQU b'01000000' RCONFIGLO EQU b'00000000' WDATAHI EQU b'10000000' RDATAHI EQU 0x00 RDATALO EQU 0x00 RTSL EQU b'10000110' RTSH EQU b'10000100' PARITY EQU 0 PM EQU 1 RM EQU 2 R EQU 7 TEST EQU 0 _IntVector set 0x04 ORG 0 goto Start ; ;ORG _IntVector ;goto Interrupt ; RESPOND BCF PORTA,TEST ; BSF PORTA,TEST ; Movwf Temp ; clrw RLOOP Movlw RDATAHI ; BSF PORTA,CS ; NOP ; BCF PORTA,CS ; Call Shiftout ; MovF RXByte,0 ; Movwf RX1 ; Movlw RDATALO ; Call Shiftout ; BSF PORTA,CS ; MovF RXByte,0 ; Movwf RX2 ; BTFSS RX1,PARITY ; GOTO RLOOP ; BCF RX2,0 ; MOVF RX2,0 ; BCF Address,0 ; BCF STATUS,Z ; SUBWF Address,0 ; BTFSC STATUS,Z ; Call Senddata ; Return Senddata Call DELAY ;ENABLE DRIVERS BSF PORTA,CS ; BCF PORTA,CS ; Movlw RTSH ; call Shiftout ; Clrw ; Call Shiftout ; BSF PORTA,CS ; BSF PORTA,CS ; BCF PORTA,CS ; Movlw WDATAHI ; Call Shiftout ; Movlw 'A' ; Call Shiftout ; BSF PORTA,CS ; Call DELAY ; Call DELAY ; Call DELAY ; Call DELAY ; Call DELAY BSF PORTA,CS ; BCF PORTA,CS ; Movlw WDATAHI ; Call Shiftout ; Movf Address,0 ; Call Shiftout ; BSF PORTA,CS ; Call DELAY ; Call DELAY ; BSF PORTA,CS ; BCF PORTA,CS ; Movlw RTSL ; call Shiftout ; Clrw ; Call Shiftout ; BSF PORTA,CS ; Return DELAY MOVLW 100 ; MOVWF L2 ; LOOP2 MOVLW 255 ; MOVWF L1 ; LOOP1 decfsz L1,F; GOTO LOOP1; decfsz L2,F; GOTO LOOP2 Return Shortwait Movlw 0x31 Movwf L1; Inner Decfsz L1,F goto Inner Return Shiftout MOVWF TXByte ; LOOP Movlw 8; Movwf Counter; SO_LOOP rlf TXByte,F; btfsc STATUS,C goto SO_Set bcf PORTA,DO goto SO_Toggle SO_Set bsf PORTA,DO SO_Toggle Bcf STATUS,C; bcf PORTA,CLK; bsf PORTA,CLK; bcf STATUS,C ; BTFSC PORTA,DIN; BSF STATUS,C; RLF RXByte,1; bcf PORTA,CLK decfsz Counter,F; goto SO_LOOP; return Readdata Movlw RDATAHI; Call Shiftout; Movlw RDATALO ; CALL Shiftout; Return ; Setup CLRW ; CLRF PORTA ; BSF STATUS, RP0 ; MOVLW b'00001000' ; ; MOVWF TRISA ; MOVLW b'11111111' MOVWF TRISB BCF STATUS,RP0 Return Configuart BSF PORTA,CS ; NOP ; NOP ; BCF PORTA,CS ; CLRW ; MOVLW WCONFIGHI ; Call Shiftout ;Send Configuaration Data MOVLW WCONFIGLO ;to UART Call Shiftout ; BSF PORTA,CS ; BCF PORTA,CS Movlw RCONFIGHI ; Call Shiftout ; BCF STATUS,Z ; Movlw RCONFIGLO ; Call Shiftout ; BSF PORTA,CS ; MOVLW WCONFIGLO ; SUBWF RXByte,0 ; BTFSS STATUS,Z ; GOTO Configuart ; RETURN ReadAddress BSF PORTA,TEST ; BCF PORTA,TEST ; MOVF PORTB,0 ; MOVWF Address ; Return Disint BSF STATUS, RP0 ; Select Bank 1 LOOP4 BCF INTCON,GIE ;Disable All ; Interrupts BTFSC INTCON,GIE ;All Interrupts ; Disabled? GOTO LOOP4 ;NO, try again ; Yes, continue ; with program ; flow BCF STATUS,RP0 Return ToggleRTS BSF PORTA,CS BCF PORTA,CS Movlw RTSL call Shiftout Clrw Call Shiftout BSF PORTA,CS Return Enint BSF PORTA,TEST ; NOP ; NOP ; NOP ; NOP ; BCF PORTA,TEST ; BSF STATUS, RP0 ; Select Bank 1 Clrw ; Movwf 0x81 ; movlw 0x90 ; Turn on the Receive Interrupts movwf INTCON BCF STATUS,RP0 Return Start Call Disint Call Setup ;Set up Ports Call Configuart ;Configure the UART to IRQ Enabled on recieved data ;Call Enint ;& parity mask Call ToggleRTS ; Loop Call ReadAddress ; btfss PORTB,0 ; Call RESPOND ; goto Loop ; End