Re: Simple Reset code needed for pic12f675 Please Help!
Hi Jeromy,
I do not think this code as it is will do what you want because it appears you can only use 1 AD channel at a time. I am posting a revised code which is untested but will give you some idea how to implement 2 channels of AD converter.
Code:
#CONFIG
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _WDT_ON
#ENDCONFIG
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
' Requires Pic Basic Pro to compile for the Microchip 12F675.
CMCON=7 ; analog comparators off
GPIO=%00000000
TRISIO=%010110 ;PORTS 1,2 & 4 AS INPUTS
; _________________________________
; | ____________________________ A/D Conversion Clock Select bits UPPER NIB
; | | |
ANSEL=%00111110 ;ANALOG SELECT BITS LOWER NIB
ADCON0=%11001111 ; AN3 ENABLED
;==================================================================
;create variables *************************************************
t VAR WORD ; AD CONVERTER
c VAR WORD ; AD CONVERTER
cl VAR WORD
m VAR BYTE
hh VAR BYTE
ch VAR BYTE
u VAR BYTE
d VAR BYTE
;=================================================================
; initialize values into variables *******************************
u = 0
d = 0
hh = 2
ch = 1
cl = 0
;=================================================================
; start up *******************************************************
pause 250
ADCON0=%11001111 ; AN3 ENABLED
ADCIN 3, t ;CHANNEL 3 is GPIO.4 PIN 3 OF PART
PAUSE 250
ADCON0=%11001011 ; AN2 ENABLED
ADCIN 2, c ;channel 2 is GPIO.2 PIN 5 OF PART
PAUSE 250
if(t > c) then
cl = (t-c)
m = 1
endif
if(t < c) then
cl = (c-t)
m = 0
endif
;=================================================================
; loop ***********************************************************
mainloop:
ADCON0=%11001111 ; AN3 ENABLED
ADCIN 3, t ;CHANNEL 3 is GPIO.4 PIN 3 OF PART
PAUSE 250
ADCON0=%11001011 ; AN2 ENABLED
ADCIN 2, c ;channel 2 is GPIO.2 PIN 5 OF PART
PAUSE 250
if m = 1 then
t = (t - cl)
else
t = (t + cl)
endif
if u > 10 then
GPIO.0=0
GPIO.5=1
endif
if d > 10 then
GPIO.5 = 0
GPIO.0 = 1
endif
if t >(c + ch) then
u = (u + 1)
d = 0
goto mainloop
else
if t <(c - hh) then
d = (d + 1)
u = 0
goto mainloop
endif
endif
u=0
d=0
GPIO.0=0
GPIO.5=0
nap 2
GoTo mainloop
end
Notice the config statements are for PBP 3. and MPASM
Your configs were for an earlier version using PBP assembler. If you use PBP add a WDT ON statement to your config.
Oh and Jeromy, please confine your problems of a project within a single thread unless the problem is different, which is to say do not open multiple threads for a single problem.
Last edited by Archangel; - 28th November 2013 at 10:07.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Bookmarks