processor 16f877 include __config _HS_OSC & _CP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_OFF adaz equ h'2e' adel equ h'2f' i equ h'31' j equ h'32' k equ h'33' u1 equ h'3a' u2 equ h'3b' u3 equ h'3c' ms equ h'3d' az equ h'21' el equ h'22' azeq equ h'23' eleq equ h'24' ae40 equ h'40' ae41 equ h'41' ae42 equ h'42' ae43 equ h'43' ae44 equ h'44' ae45 equ h'45' ae46 equ h'46' ae47 equ h'47' ae48 equ h'48' ae49 equ h'49' ae50 equ h'50' ae51 equ h'51' ae52 equ h'52' ae53 equ h'53' ae54 equ h'54' ae55 equ h'55' ae56 equ h'56' ae57 equ h'57' ae58 equ h'58' ae59 equ h'59' ae60 equ h'60' ae61 equ h'61' ae62 equ h'62' ae63 equ h'63' ae64 equ h'64' ae65 equ h'65' ae66 equ h'66' ae67 equ h'67' ae68 equ h'68' ae69 equ h'69' ae70 equ h'70' ae71 equ h'71' ae72 equ h'72' ae73 equ h'73' ae74 equ h'74' ae75 equ h'75' ae76 equ h'76' hc0 equ h'a0' hc1 equ h'a1' hc2 equ h'a2' hc3 equ h'a3' hc4 equ h'a4' hc5 equ h'a5' hc6 equ h'a6' hc7 equ h'a7' hc8 equ h'a8' hc9 equ h'a9' hca equ h'aa' hcb equ h'ab' hcc equ h'ac' hcd equ h'ad' hce equ h'ae' hcf equ h'af' pr0 equ h'b0' pr1 equ h'b1' pr2 equ h'b2' pr3 equ h'b3' pr4 equ h'b4' pr5 equ h'b5' pr6 equ h'b6' pr7 equ h'b7' pr8 equ h'b8' pr9 equ h'b9' pra equ h'c1' prb equ h'c2' prc equ h'c3' prd equ h'c4' pre equ h'c5' prf equ h'c6' org 0 clrf STATUS clrf INTCON bsf RCSTA,SPEN bsf RCSTA,CREN movlw b'00010000' movwf PORTA clrf PORTB clrf PORTC clrf PORTD clrf PORTE bsf STATUS,RP0 bcf STATUS,RP1 clrf PIE1 clrf PIE2 movlw b'00000100' movwf ADCON1 bsf TXSTA,TXEN movlw d'129' movwf SPBRG movlw b'00000011' movwf TRISA clrf TRISB movlw b'11000000' movwf TRISC clrf TRISD clrf TRISE movlw h'00' movwf pr0 movlw h'01' movwf pr1 movlw h'02' movwf pr2 movlw h'03' movwf pr3 movlw h'04' movwf pr4 movlw h'05' movwf pr5 movlw h'06' movwf pr6 movlw h'07' movwf pr7 movlw h'08' movwf pr8 movlw h'09' movwf pr9 movlw h'0a' movwf pra movlw h'0b' movwf prb movlw h'0c' movwf prc movlw h'0d' movwf prd movlw h'0e' movwf pre movlw h'0f' movwf prf movlw h'30' movwf hc0 movlw h'31' movwf hc1 movlw h'32' movwf hc2 movlw h'33' movwf hc3 movlw h'34' movwf hc4 movlw h'35' movwf hc5 movlw h'36' movwf hc6 movlw h'37' movwf hc7 movlw h'38' movwf hc8 movlw h'39' movwf hc9 movlw h'41' movwf hca movlw h'42' movwf hcb movlw h'43' movwf hcc movlw h'44' movwf hcd movlw h'45' movwf hce movlw h'46' movwf hcf bcf STATUS,RP0 bsf RCSTA,SPEN bsf RCSTA,CREN movlw h'01' movwf azeq movwf eleq movlw h'80' movwf az movlw h'20' movwf el movlw h'00' movwf ae40 movlw h'07' movwf ae41 movlw h'0e' movwf ae42 movlw h'15' movwf ae43 movlw h'1c' movwf ae44 movlw h'23' movwf ae45 movlw h'2a' movwf ae46 movlw h'32' movwf ae47 movlw h'38' movwf ae48 movlw h'40' movwf ae49 movlw h'47' movwf ae50 movlw h'4e' movwf ae51 movlw h'55' movwf ae52 movlw h'5c' movwf ae53 movlw h'63' movwf ae54 movlw h'6a' movwf ae55 movlw h'71' movwf ae56 movlw h'78' movwf ae57 movlw h'80' movwf ae58 movlw h'87' movwf ae59 movlw h'8e' movwf ae60 movlw h'95' movwf ae61 movlw h'9c' movwf ae62 movlw h'a3' movwf ae63 movlw h'aa' movwf ae64 movlw h'b1' movwf ae65 movlw h'b8' movwf ae66 movlw h'c0' movwf ae67 movlw h'c7' movwf ae68 movlw h'ce' movwf ae69 movlw h'd5' movwf ae70 movlw h'dc' movwf ae71 movlw h'e3' movwf ae72 movlw h'ea' movwf ae73 movlw h'f1' movwf ae74 movlw h'f6' movwf ae75 movlw h'ff' movwf ae76 movlw b'11000001' movwf ADCON0 main call uart call azmot call elmot goto main eprom clrf ADCON0 movlw b'00010000' movwf PORTA bsf STATUS,RP0 movlw h'ff' movwf TRISD clrf TRISA clrf TRISB clrf TRISE bcf STATUS,RP0 btfss PIR1,RCIF return movf RCREG,0 movwf k sublw h'77' btfss STATUS,Z goto ckrd call prone movf i,0 movwf u1 call prone movf i,0 movwf u2 call prone movf i,0 movwf u3 prsp btfss PIR1,RCIF goto prsp movf RCREG,0 sublw h'20' btfss STATUS,Z goto outw call wprom call rprom return outw call uartx call uartx return ckrd movf k,0 sublw h'72' btfss STATUS,Z return call prone movf i,0 movwf u1 call prone movf i,0 movwf u2 call rprom return wprom movf u1,0 movwf PORTE movf u2,0 movwf PORTB bsf STATUS,RP0 clrf TRISD bcf STATUS,RP0 movf u3,0 movwf PORTD movlw b'00110000' movwf PORTA call acqt movlw b'00111000' movwf PORTA call pulse movlw b'00110000' movwf PORTA movlw b'00010000' movwf PORTA call acqt bsf STATUS,RP0 movlw h'ff' movwf TRISD bcf STATUS,RP0 return rprom movf u1,0 movwf PORTE movf u2,0 movwf PORTB movlw b'00010100' movwf PORTA call acqt movlw b'00011100' movwf PORTA call acqt movf PORTD,0 movwf i movlw b'00010100' movwf PORTA movlw b'00010000' movwf PORTA swapf i,1 movf i,0 andlw h'0f' addlw h'a0' movwf FSR call txpd swapf i,1 movf i,0 andlw h'0f' addlw h'a0' movwf FSR call txpd return txpd bsf STATUS,RP0 btfss TXSTA,TRMT goto txpd bcf STATUS,RP0 movf INDF,0 movwf TXREG return uartx bsf STATUS,RP0 btfss TXSTA,TRMT goto uartx bcf STATUS,RP0 movlw h'57' movwf TXREG return uart btfss PIR1,RCIF return movf RCREG,0 sublw h'57' btfss STATUS,Z return call urone ursp btfss PIR1,RCIF goto ursp movf RCREG,0 sublw h'20' btfss STATUS,Z return movf INDF,0 addwf u3,0 movwf az movlw h'01' movwf azeq call urone movf INDF,0 addwf u3,0 movwf el movlw h'01' movwf eleq crlf btfss PIR1,RCIF goto crlf movf RCREG,0 return prone btfss PIR1,RCIF goto prone movf RCREG,0 addlw h'80' movwf FSR movf INDF,0 movwf i swapf i,1 prtwo btfss PIR1,RCIF goto prtwo movf RCREG,0 addlw h'80' movwf FSR movf INDF,0 addwf i,1 return urone btfss PIR1,RCIF goto urone movf RCREG,0 andlw h'0f' addlw h'04' movwf u1 swapf u1,1 urtwo btfss PIR1,RCIF goto urtwo movf RCREG,0 andlw h'0f' addwf u1,0 movwf FSR urthr btfss PIR1,RCIF goto urthr movf RCREG,0 andlw h'0f' movwf u3 return azmot btfss azeq,0 return movlw b'11000001' movwf ADCON0 call acqt bsf ADCON0,GO call atod movf ADRESH,0 movwf adaz subwf az,0 btfss STATUS,Z goto azbor bcf PORTB,1 bcf PORTB,2 clrf azeq return azbor movf adaz,0 subwf az,0 btfss STATUS,C goto azrev bcf PORTB,1 bsf PORTB,2 movlw h'01' movwf azeq return azrev bcf PORTB,2 bsf PORTB,1 movlw h'01' movwf azeq return elmot btfss eleq,0 return movlw b'11001001' movwf ADCON0 call acqt bsf ADCON0,GO call atod movf ADRESH,0 movwf adel subwf el,0 btfss STATUS,Z goto elbor bcf PORTB,4 bcf PORTB,5 clrf eleq return elbor movf adel,0 subwf el,0 btfss STATUS,C goto elrev bcf PORTB,4 bsf PORTB,5 movlw h'01' movwf eleq return elrev bcf PORTB,5 bsf PORTB,4 movlw h'01' movwf eleq return atod btfss ADCON0,GO return goto atod pulse movlw h'ff' movwf ms iloop call acqt decfsz ms,1 goto iloop return acqt movlw h'88' movwf j jloop decfsz j,1 goto jloop return end