Simple Reset code needed for pic12f675 Please Help!


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default Simple Reset code needed for pic12f675 Please Help!

    I have a code I found on the internet that is a simple hot/cold detector with 2 led's. Well the problem is if a new ambient temperature is introduced it will just stay on the color of the ambient temperature unless I turn the unit off and back on again to reset the unit. Well I have found an electrical work-around using a 555 timer to reset the circuit every 30 seconds which is what I desire. However I am getting tired of building the 555's every time I build them so I know someone out there can write a simple code to do this for me automatically through the pic chip12... I have contacted the original owner of the code and he said he doesn't have the time to even look at it, so Im hoping someone here can help me. It would be greatly appreciated! Basically I need the chip to turn off then back on every 30 seconds as if I would do it with the on/off switch manually.
    Here is a sample of the code im using.
    Code:
    @ Device PIC12F675,PROTECT_OFF,INTRC_OSC_NOCLKOUT,MCLR_OFF
    DEFINE ADC_BITS 10 
    DEFINE ADC_CLOCK 3 
    DEFINE ADC_SAMPLEUS 50 
    
    
    ' Requires Pic Basic Pro to compile for the Microchip 12F675.
    
    
    
    
    CMCON=7
    GPIO=%00000000
    TRISIO=%010110
    ANSEL=%00111110
    ADCON0=%11001100
    
    
    t VAR WORD
    c VAR WORD
    cl VAR WORD
    m VAR BYTE
    hh VAR BYTE
    ch VAR BYTE
    u VAR BYTE
    d VAR BYTE
    
    
    u=0
    d=0
    hh=2
    ch=1
    cl=0
    
    
    pause 250
    ADCIN 3, t
    ADCIN 2, c
    if(t>c) then
     cl=t-c
     m=1
    endif
    if(t<c) then
     cl=c-t
     m=0
    endif
    
    
    loop:
    
    
    ADCIN 3, t
    ADCIN 2, c
    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 loop
    else
     if t<(c-hh) then
      d=d+1
      u=0
      goto loop
     endif
    endif
    
    
    u=0
    d=0
    GPIO.0=0
    GPIO.5=0
    nap 2
    GoTo loop
    Last edited by Archangel; - 28th November 2013 at 08:02.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Post 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 09: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.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Simple Reset code needed for pic12f675 Please Help!

    Thank you, I really appreciate the help!

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Simple Reset code needed for pic12f675 Please Help!

    You are welcome, I hope it is helpful.
    I changed the word loop to mainloop as loop is a reserved word in PBP 3.xx
    notice ADCON0
    bits 2 & 3 select the channel, bit 0 turns the AD on off and bit 1 is the GO/Done bit set to go, 0 means done which means you can check it to see if done.
    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.

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Simple Reset code needed for pic12f675 Please Help!

    If you really wanted to go the long way round like that,
    you could use a variable to count the number of times your main loop is run,
    then when it reaches a certain value, simply use a spare pin to pull the MCLR.
    But it's better to fix it.

Similar Threads

  1. Replies: 14
    Last Post: - 22nd January 2012, 04:06
  2. Help needed with source code
    By orangekitty in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th October 2010, 10:06
  3. Simple TMR1 application example needed
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th February 2010, 09:52
  4. help with code needed
    By ccronin4 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th December 2005, 22:48
  5. PIC18 USB simple example needed
    By harryweb in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 29th September 2005, 22:20

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts