Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <p16f690.inc>
- __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)
- ; Setup ADC subroutine
- ORG 0x00
- pause EQU 0x10
- pause1 EQU 0x20
- val1 EQU 0x21
- val2 EQU 0x22
- val3 EQU 0x23
- val4 EQU 0x24
- checkVal EQU 0x25
- goto main
- checkError
- ; return
- checkCorrect
- ; return
- readVal1
- ; call readADC
- ; movlw W, val1
- ; call LED1
- ; goto loop1
- readVal2
- ; call readADC
- ; movlw W, val2
- ; call LED1
- ; goto loop1
- readVal3
- ; call readADC
- ; movlw W, val3
- ; call LED1
- ; goto loop1
- readVal4
- ; call readADC
- ; movlw W, val4
- ; call LED1
- ; goto loop1
- ; check btfsc subwf val1,1
- ; call checkError
- ; btfsc subwf val2,2
- ; call checkError
- ; btfsc subwf val3,3
- ; call checkError
- ; btfsc subwf val4,4
- ; call checkError
- ; call checkCorrect
- ; Subroutine setSwitch
- LED1
- movwf PORTC
- ; bsf PORTC, W
- call delay
- bcf PORTC, W
- return
- delay
- decfsz pause,f
- goto delay
- decfsz pause1,f
- goto delay
- return
- setSwitch
- BANKSEL TRISA ;Select BankA
- bsf TRISA,3 ;Set bit3 PORTA as input
- BANKSEL PORTA ;select bank 0
- return
- setLEDs
- BANKSEL TRISC
- CLRF TRISC
- BANKSEL PORTC
- RETURN
- initTimer0
- BANKSEL OPTION_REG
- movlw B'10000111' ; Configure Timer0
- movwf OPTION_REG ; Maximum prescalar
- BANKSEL TMR0
- clrf TMR0 ; Initialise Timer0
- movlw B'10100000' ; Timer0 interrupt active
- movwf INTCON
- return
- setADC
- BANKSEL TRISA
- bsf TRISA,0
- movlw 0x10
- movwf ADCON1
- BANKSEL ANSEL
- bsf ANSEL,0
- BANKSEL ADCON0
- movlw B'00000001'
- movwf ADCON0
- goto $+1
- goto $+1
- goto $+1
- return
- readADC
- BANKSEL ADCON0 ; Select bank 0
- bsf ADCON0,GO ; Start ADC conversion
- loop btfsc ADCON0,GO ; Check if converted
- goto loop ; Poll (loop) until done
- movf ADRESH,W ; Put 8-bit result in W
- return
- main
- call setADC ; Setup Channel 0 of ADC
- call readADC ; Read the ADC value
- call setSwitch
- call setLEDs
- loop1 btfsc PORTA,3
- call pressed
- call LED1
- goto loop1
- pressed call readADC
- sublw val1
- btfsc zflg
- goto $+2
- call readVal1
- btfsc val2
- goto $+2
- call readVal2
- btfsc val3
- goto $+2
- call readVal3
- btfsc val4
- goto $+2
- call readVal4
- return
- goto $ ; Wait here
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement