Hi, I have revisited a simple ADC project using 12f675. I've set GPIO,0 as analogue in, & GPIO,1 & 2 as outputs connected to two led's used to indicate input level < or> depending on value set in ADC reading (e.g. 2volts) I set a DC value between 0v (Vss & 5v = Vdd) using a 10k pott. ADC set up for ext ref 5v vdd. The circuit works_accept as I advance the pott in either direction the led's alternatively switch on and off as the voltage increases or decreases at several intervals. The adc voltage value = 102 (2 volts) for 8 bit convertion. One led should be lit only when > 2v & the other lit < 2v. I'm using the pott only to prove my circuit, and eventually use either a temp sensor (resistive) or an LDR device with one of the GPIO's to switch a relay.
This is the first time I've used this PIC and come accross this problem.
I have included the asm listing. Note very new to programming_most gratefull again for any assistance.
[
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; *
; *
; *
;**********************************************************************
; *
; Files required: *
; 12F675.lkr *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************
list p=12f675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
;***** VARIABLE DEFINITIONS (examples)
; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program
INT_VECTOR CODE 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
; these first 4 instructions are not required if the internal oscillator is not used
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
; set file register bank to 0
; ======================= DELAY =================================
DELAY1
CLRF TMR0 ; START TMR0
LOOPBB MOVF TMR0,W ; READ TMR0 INTO W
SUBLW .200 ; TIME -W
BTFSS STATUS,Z ; CHECK TIME W = 0
GOTO LOOPBB
RETLW 0 ; RETURN AFTER TMR0 = 100
main
bsf STATUS,RP0 ; select bank 0
movlw .9 ;B'00001001' ; SET BIT 0 as input ;
movwf TRISIO
movlw B'00000111'
movwf OPTION_REG
movlw B'00010001' ;set bit 0 as analogue input
movwf ANSEL
bcf STATUS,RP0
movlw B'00000111'
movwf CMCON
bcf STATUS,RP0
movlw B'00000001' ; left justified (bit7=0) /255
movwf ADCON0
clrf GPIO
;======================== START OF PROGRAM ============================
BEGIN
bsf ADCON0,GO
WAIT btfsc ADCON0,GO
goto WAIT
bsf STATUS,RP0
movf ADRESL,W
sublw .102 ; 8 bit ADC convertion = 255/5 x 2v = 102
; == 10 BIT ADC CONVERTION _ 2volts
btfsc STATUS,C ; 1,023 / 5volt vdd = 204.6 x voltage in
goto LED1 ; e.g_ 2volts x 204.6 = 409
goto LED2
LED1 bcf STATUS,RP0
bsf GPIO,1
bcf GPIO,2
goto BEGIN
LED2 bcf STATUS,RP0
bsf GPIO,2
bcf GPIO,1
goto BEGIN
END ]
This is the first time I've used this PIC and come accross this problem.
I have included the asm listing. Note very new to programming_most gratefull again for any assistance.
[
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; *
; *
; *
;**********************************************************************
; *
; Files required: *
; 12F675.lkr *
; *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
; *
; *
;**********************************************************************
list p=12f675 ; list directive to define processor
#include <p12f675.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
;***** VARIABLE DEFINITIONS (examples)
; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program
INT_VECTOR CODE 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
; these first 4 instructions are not required if the internal oscillator is not used
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
; set file register bank to 0
; ======================= DELAY =================================
DELAY1
CLRF TMR0 ; START TMR0
LOOPBB MOVF TMR0,W ; READ TMR0 INTO W
SUBLW .200 ; TIME -W
BTFSS STATUS,Z ; CHECK TIME W = 0
GOTO LOOPBB
RETLW 0 ; RETURN AFTER TMR0 = 100
main
bsf STATUS,RP0 ; select bank 0
movlw .9 ;B'00001001' ; SET BIT 0 as input ;
movwf TRISIO
movlw B'00000111'
movwf OPTION_REG
movlw B'00010001' ;set bit 0 as analogue input
movwf ANSEL
bcf STATUS,RP0
movlw B'00000111'
movwf CMCON
bcf STATUS,RP0
movlw B'00000001' ; left justified (bit7=0) /255
movwf ADCON0
clrf GPIO
;======================== START OF PROGRAM ============================
BEGIN
bsf ADCON0,GO
WAIT btfsc ADCON0,GO
goto WAIT
bsf STATUS,RP0
movf ADRESL,W
sublw .102 ; 8 bit ADC convertion = 255/5 x 2v = 102
; == 10 BIT ADC CONVERTION _ 2volts
btfsc STATUS,C ; 1,023 / 5volt vdd = 204.6 x voltage in
goto LED1 ; e.g_ 2volts x 204.6 = 409
goto LED2
LED1 bcf STATUS,RP0
bsf GPIO,1
bcf GPIO,2
goto BEGIN
LED2 bcf STATUS,RP0
bsf GPIO,2
bcf GPIO,1
goto BEGIN
END ]