Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
result
movlw low(0x015B) ; load W with value of low 0x15
subwf Word,W ; subtract value in file Word, with value in W
movlw high(0x015B) ; load W with value of 0x15
btfss STATUS,C ; check to see if bit "C", in Status is set.
movlw high(0x015B)+1 ; load W with value high 0x15 and add 1
subwf Word+1,W ; subtract value in file Word, with value in W
btfss STATUS,C ; carry clear if word is less than 0x15B
goto LEDon ; <-----changed
movlw low(0x0266)
subwf Word,W
movlw high(0x0266)
btfss STATUS,C
movlw high(0x0266)+1
subwf Word+1,W
btfsc STATUS,C ; carry set if word is greater or equal to 0x266
goto LEDon ; <------changed
; goto start <------removed
; turn LED off here
LEDoff ; <-------moved
bcf GPIO,5 ; set bit 5 of GPIO register to 0 (low)
goto start ; <-------changed
LEDon
bsf GPIO,5 ; set bit 5 of GPIO register to 1 (high)
goto start ; <-------changed
Init_ADC0 ;set for AN0
; Set ADCON0
movlw b'10000001'
movwf ADCON0 ; bit 7 is set meaning results will be right justified, and bit 0 is also set, meaning A/D module is operating. no other bit are set so Channel 00 for AN0 will be read.
return
Init_ADC1 ; set for AN1
; Set ADCON0
movlw b'10000101'
movwf ADCON0 ; bit 7 is set meaning results will be right justified, and bit 0 is also set, meaning A/D module is operating. bit 2 is set, meaning Channel 01 for AN1 is ready for reading.
return
Read_ADC1
call delay1 ; small delay for A/D aquisition time.
; read CHS0 ( channel 0)
bsf ADCON0, GO_DONE ; initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ; wait for ADC to finish
movf ADRESH,W ; move results from ADRESH file to W
movwf Word ; move value from W to file named Word
BANKSEL ADRESL ; switch to bank 1
movf ADRESL,W ; move results from ADRESL file to W
movwf Word+1 ; move value from W to file named Word and add 1
nop
nop
nop
return
Read_ADC2
call delay1 ; small delay for A/D aquisition time.
; read CHS1 (channel 1)
bsf ADCON0, GO_DONE ; initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ; wait for ADC to finish
movf ADRESH,W ; move results from ADRESH file to W
movwf Word ; move value from W to file named Word
BANKSEL ADRESL ; switch to bank 1
movf ADRESL,W ; move results from ADRESL file to W
movwf Word+1 ; move value from W to file named Word and add 1
nop
nop
nop
return
result
movlw low(0x015B) ; load W with value of low 0x15
subwf Word,W ; subtract value in file Word, with value in W
movlw high(0x015B) ; load W with value of 0x15
btfss STATUS,C ; check to see if bit "C", in Status is set.
movlw high(0x015B)+1 ; load W with value high 0x15 and add 1
subwf Word+1,W ; subtract value in file Word, with value in W
btfss STATUS,C ; carry clear if word is less than 0x15B
call LEDon
movlw low(0x0266)
subwf Word,W
movlw high(0x0266)
btfss STATUS,C
movlw high(0x0266)+1
subwf Word+1,W
btfsc STATUS,C ; carry set if word is greater or equal to 0x266
goto LEDon
; turn LED off here
LEDoff
bcf GPIO,5 ; set bit 5 of GPIO register to 0 (low)
goto start
LEDon
bsf GPIO,5 ; set bit 5 of GPIO register to 1 (high)
goto start
delay1 ; will delay W*8 cycles including the call/return
addlw 0xff ; add -1 to W 1
btfsc STATUS,Z ; =zero? 1/2
goto DoneDelay ; yes, better get out of here 2
nop ; delay a bit 1
goto $+1 ; delay a bit more 2
goto delay1 ; go around again 2
DoneDelay return ; 2
;***** VARIABLE DEFINITIONS
Word equ 0x30
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
; isr code can go here or be located as a call subroutine elsewhere
; these first 4 instructions are not required if the internal oscillator is not used
main
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
;*******************************************************************************************************
;************************************** Begining of application code *********************************
;*******************************************************************************************************
portsetup
bcf STATUS, RP0 ; ensure Bank "0" is previously selected
; The default chip configuration upon start up, or reset of 12f675, is analogue input on GP0, GP1, GP2 and GP4
; to alter this configuration, next 2 instructions are necessary, customize per your application.
movlw 07h ; move literal to working register
movwf CMCON ; turn comparators off as they are not used here
bsf STATUS, RP0 ; switch to Bank "1" to set up analogue ports
movlw 03h ; move literal 03h working register
movwf ANSEL ; move working register to file ANSEL, setting GP1 and GP0 as analogue input.
movlw 0Bh ; move literal to working register, 0Bh (001011b) (1 = input, 0 = output)
movwf TRISIO ; move working register value to TRISIO setting GP3, GP1 and GP0, as inputs, and GP2, GP4 and GP5, as digital outputs.
bcf STATUS, RP0 ; return to Bank "0"
start
nop ; small delay to settle micro
nop
nop
nop
nop
btfss GPIO,3 ; check to see if PTO is engaged.(high) if set then skip next instruction
goto start ; if not set, loop back to start
call Init_ADC0
call Read_ADC0
nop
nop
BANKSEL GPIO ; this is necessary only if control of pins,(such as outputs) on GPIO5 is needed after reading A/D.
call result
nop
nop
nop ; small delay to settle micro
btfss GPIO,3 ; check to see if PTO is engaged.(high) if set then skip next instruction
goto start ; if not set, loop back to start
call Init_ADC1
call Read_ADC1
nop
nop
BANKSEL GPIO ; this is necessary only if control of pins,(such as outputs) on GPIO5 is needed after reading A/D.
call result
goto start
Init_ADC0
movlw b'10000001'
movwf ADCON0 ; bit 7 is set meaning results will be right justified, and bit 0 is also set, meaning A/D module is operating. no other bits are set so Channel 00 for AN0 will be set for read.
return
Init_ADC1
movlw b'10000101'
movwf ADCON0 ; bit 7 is set meaning results will be right justified, and bit 0 is also set, meaning A/D module is operating. bit 2 is set, meaning Channel 01 for AN1 is set for reading.
return
Read_ADC0
call delay1 ; small delay for A/D aquisition time.
; read CHS0 ( channel 0)
bsf ADCON0, GO_DONE ; initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ; wait for ADC to finish, after which GO/DONE bit is cleared automaticaly after conversion.
movf ADRESH,W ; move results from ADRESH file to W
movwf Word ; move value from W to file named Word
BANKSEL ADRESL ; switch to bank 1
movf ADRESL,W ; move results from ADRESL file to W
movwf Word+1 ; move value from W to file named Word and add 1
nop
nop
nop
return
Read_ADC1
call delay1 ; small delay for A/D aquisition time.
; read CHS1 (channel 1)
bsf ADCON0, GO_DONE ; initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ; wait for ADC to finish, after which GO/DONE bit is cleared automaticaly after conversion
movf ADRESH,W ; move results from ADRESH file to W
movwf Word ; move value from W to file named Word
BANKSEL ADRESL ; switch to bank 1
movf ADRESL,W ; move results from ADRESL file to W
movwf Word+1 ; move value from W to file named Word and add 1
nop
nop
nop
return
result
movlw low(0x015B) ; load W with value of low 0x15
subwf Word,W ; subtract value in file Word, with value in W
movlw high(0x015B) ; load W with value of 0x15
btfss STATUS,C ; check to see if bit "C", in Status is set.
movlw high(0x015B)+1 ; load W with value high 0x15 and add 1
subwf Word+1,W ; subtract value in file Word, with value in W
btfss STATUS,C ; carry clear if word is less than 0x15B
call LEDon
movlw low(0x0266)
subwf Word,W
movlw high(0x0266)
btfss STATUS,C
movlw high(0x0266)+1
subwf Word+1,W
btfsc STATUS,C ; carry set if word is greater or equal to 0x266
goto LEDon
LEDoff
bcf GPIO,5 ; set bit 5 of GPIO register to 0 (low)
goto start
LEDon
bsf GPIO,5 ; set bit 5 of GPIO register to 1 (high)
goto start
delay1
movlw 05h ; will delay W*8 cycles including the call/return
addlw 0xff ; add -1 to W 1
btfsc STATUS,Z ; =zero? 1/2
goto DoneDelay ; yes, better get out of here 2
nop ; delay a bit 1
goto $+1 ; delay a bit more 2
goto delay1 ; go around again 2
DoneDelay
return
END ; directive 'end of program'
movlw 07h
movwf CMCON
Read_ADC0
call delay1 ; small delay for A/D aquisition time.
; read CHS0 ( channel 0)
bsf ADCON0, GO_DONE ; initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ; wait for ADC to finish, after which GO/DONE bit is cleared automaticaly after conversion.
movf ADRESH,W ; move results from ADRESH file to W
movwf Word ; move value from W to file named Word
BANKSEL ADRESL ; switch to bank 1
movf ADRESL,W ; move results from ADRESL file to W
movwf Word+1 ; move value from W to file named Word and add 1
nop
nop
nop
return
delay1
movlw 05h ; will delay W*8 cycles including the call/return
[COLOR="Red"]DelayW[/COLOR] addlw 0xff ; add -1 to W 1
btfsc STATUS,Z ; =zero? 1/2
goto DoneDelay ; yes, better get out of here 2
nop ; delay a bit 1
goto $+1 ; delay a bit more 2
goto [COLOR="red"]DelayW[/COLOR] ; go around again 2
DoneDelay
return
burg said:I hate endian, it can get really confusing. Is there any requirement by PIC's in general? To my understanding they only (ones I've dealt with) use 1 byte at a time (i.e. no word size, long, etc.), so Endian wouldn't be specified by the PIC itself, just the programmer.
mov al,Var -8 bit
mov ax,Var -16 bit
mov eax,Var -32 bit
burg said:I hate endian, it can get really confusing. Is there any requirement by PIC's in general? To my understanding they only (ones I've dealt with) use 1 byte at a time (i.e. no word size, long, etc.), so Endian wouldn't be specified by the PIC itself, just the programmer.