list p=12c672 #include count equ H'0025' ;defines count variable and gives a memory address resss equ H'0030' ;defines resss variable and gives a memory address org 0x00 ; defines the start of memory as 00h reset goto start ; initialize the settings of the A/D converter, and picks input/output pins start org 0x05 ; defines where to start the code bsf STATUS, RPO ;selects bank 1 movlw 0x04 ; moves 04 hex into working register movwf ADCON1 ; moves working register into functional register ADCON1 movlw 0x03 ; moves 03h into working register movwf TRISIO ; moves working register into TRISIO bcf STATUS, RPO ;selects bank 0 movlw 0x89 ; moves 089h into working register movwf ADCON0 ; moves w into f ;subroutine that starts A/D converter, and checks results loop movlw 0x10 ;put 10h into the working register movwf count ;move contents of working register into f register good decfsz count,1 ;decrements count by one, skips next if zero goto good ;if not zero go to good bsf ADCON0,GO ;starts A/D by setting GO bit of ADCON0 one btfsc ADCON0,GO ;tests to see if A/D is done, skips next code if 0 goto one ;if not zero go to “one” movf ADRES,0 ; movwf resss ;moves results into ress btfss resss,7 ;tests to see if results bit 7 set, skips next if set goto Toff ;calls Toff subroutine goto Ton ;calls Ton subroutine Toff bsf GPIO,4 ;sets GP4 to high output bcf GPIO,2 ;sets GPIO2 to low output goto loop ;jump to loop subroutine Ton bsf GPIO,2 ;sets GPIO2 to high output bcf GPIO,4 ;sets GPIO4 to low output goto loop ; starts A/D conversion over again end