l istp=16f887 ; list directive to define processor
#include <p16f887.inc> ; processor specific variable definitions
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
; variable decleration
cblock 0x00
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
timer1
incf_count
Endc
org 0x0021 ; Start program at address
count equ 0x20 ; Counter variable
nop ; required for debugger
; Initialize PORT D to be all outputs and PORT A all inputs.
Start
BANKSEL PORTD
CLRF PORTD
BANKSEL TRISD
movwf TRISA ; Make PortA all input
clrf TRISD ; Set PORTD for output
clrf PORTD ; write 0s to PORTD
clrf count ; Initialize count to 0.
; Setup timer 1
bcf T1CON,TMR1ON ; Turn Timer 1 off.
bsf T1CON,T1CKPS1 ; Set prescaler for divide bsf T1CON,T1CKPS0 by 8.
bcf T1CON,T1OSCEN ; Disable the RC oscillator.
bcf T1CON,TMR1CS ; Use the Fosc/4 source.
clrf TMR1L ; Start timer at 0000h
clrf TMR1H ; clear the pre-scalar counter
bsf T1CON,TMR1ON ; Start the time
Time1 btfss PIR1,TMR1IF ; Did timer overflow?
; Timer overflowed, increment counter and display
bcf PIR1,0 ; Clear the flag
incf count,F ; Bump the counter
movf count,W ; Get the count
movwf PORTD ; Send to Port D.
bcf T1CON,0 ; Turn the timer off.
movlw 80h ; Start timer at 80h
movwf TMR1H
clrf TMR1L
bsf T1CON,0 ; Turn the timer on.
movlw 0xFF
movlw 0x00 ; Left Justified, Vdd-Vss referenced
movwf ADCON1
BANKSEL TRISA
movlw 0xFF ; we want all Port A pins Analog
movwf ANSEL
bcf STATUS,RP0 ; back to Register Bank 0
movlw 0x41
movwf ADCON0 ; configure A2D for Fosc/8, Channel 0 (RA0), and turn on the A2D module
nop ; wait 5uS for A2D amp to settle and capacitor to charge.
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
bsf ADCON0,GO_DONE ; start conversion
btfss ADCON0,GO_DONE ; this bit will change to zero when the conversion is complete
goto $-1
movf ADRESH, W ; Copy the display to the LEDs
movwf PORTD
goto timer1
End ; directive 'end of program'