12F675 code sample


Closed Thread
Results 1 to 10 of 10
  1. #1
    marad73's Avatar
    marad73 Guest

    Red face 12F675 code sample

    Can anyone help me find some sample front end code in PBP to set up a 12F675? What I need is something that I can modify to suit my application that includes defines, configs, etc. Need to use WDT, POR, BOD and two of the ADCs to compare 2 inputs. Also want to wake up from SLEEPUNCAL using WDT, use internal EEPROM, etc. Once I have something to start with, I can add stuff as necessary!
    This chip is new to me! Help will be greatly appreciated!
    Ron

    Not a lazy horse - just don't know where the start of the 12F675 race is!!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Quick and dirty!

    Here's something really basic and untested to start with

    Code:
        '
        '    PIC Configuration
        '    =================
        @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
             '    Internal Oscillator
             '    Enable watch dog timer
             '    Enable power up timer
             '    Disable MCLR pin
             '    Enable brown out detect
        
        '
        '    Hardware configuration
        '    ======================
        TRISIO   = %001111         ' GPIO<5:4> as output
                                   ' GPIO<3:0> as input
                                   '
        CMCON    = 7               ' disable analog comparator
        ADCON0   = %10000001       ' Right justified results & enable A/D
        ANSEL    = %00110011       ' Clock source=FRC
                                   ' AN<1:0> : analog other to digital
                                   
        DEFINE ADC_SAMPLEUS 50     ' Set sampling time in microseconds 
    
    
        '                      
        '    Hardware connection
        '    ===================
        LED0                    var GPIO.4
        LED1                    var GPIO.5
    
        '   
        '    Variables definition 
        '    ===================
        ADChannel0              var word
        ADChannel1              var word
        
        '
        '    Hardware/Software initialisation
        '    ================================
        GPIO = 0                               ' clear all output
        Pause 50                               ' internal oscillator settle time
                               
        '
        '    Main Program
        '    ============
    Start:
        adcin 0,adchannel0                     ' Read AN0
        adcin 1,adchannel1                     ' Read AN1
             '     
             '    A/D results duty
             '    ================
        if adchannel0 < adchannel1 then
           High Led0
           Low  Led1
           write 0, adchannel0.highbyte        ' Store result in internal EEPROM
           write 1, adchannel0.lowbyte
           
           else
               High Led1
               low  Led0
               write 0, adchannel1.highbyte    ' Store result in internal EEPROM
               write 1, adchannel1.lowbyte
    
           endif
        pause 500
        goto start
    Have fun!
    Last edited by mister_e; - 20th May 2006 at 21:58.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Why do you need to use sleep? If it's in case you want to sleep when results change.. you may use the internal comparator interrupt... it should work... it should.
    Last edited by mister_e; - 20th May 2006 at 21:51.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    marad73's Avatar
    marad73 Guest


    Did you find this post helpful? Yes | No

    Thumbs up Steve - thanks!

    It is sooooo.... much easier when someone who has already done something shows the "new kid on the block" how to!
    PS Now the horse found the starting gate and even knows which way to run at the bell!!!!
    Thanks again
    Ron

  5. #5
    marad73's Avatar
    marad73 Guest


    Did you find this post helpful? Yes | No

    Smile sleep

    Steve, I need sleep to really conserve power. This thing gets its power from photovoltaics in daylight. It stores Vcc in large electrolytic caps!
    Also, it only has to operate for about 20 seconds every 15 minutes or so. (wake by WDT) I also need to store data in the eeprom - but nothing in the registers can reset when it goes to sleep. Using sleepuncal to do that. Don't give a flip about the actual sleep time tolerance. I Think it will work, but not sure yet!!
    Thanks
    Ron

  6. #6
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Be careful using the internal oscillator and the MCLR pin as an input. We just discussed this on another thread. You will not be able to reprogram it if you do.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    > Be careful using the internal oscillator and the MCLR pin as an input. We just discussed this on another thread. You will not be able to reprogram it if you do.

    There is NO PROBLEM with this combination - it's used all the time - in fact it's my preferred choice for this PIC. There is no correlation internally within the PIC between your OSCILLATOR choice and your MCLR choice. Simply drop it into your programmer and away you go with whatever settings you desire.

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    And now... it also depend of how good your device programmer is. An crapy Programming sequence timing and signal will ruine your life.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=878&stc=1&d=1148149000 ">

    As many here use free solution, there's many chance that it do some bugs. But i do understand why some choose these solution as PIC programming is not their main job or they simply can't afford the price of a good programmer.

    I heard that some have fix some bugs when using a driver as in the ICSP guide of MicroChip... i can't say... http://ww1.microchip.com/downloads/e...Doc/30277d.pdf
    Attached Images Attached Images  
    Last edited by mister_e; - 21st May 2006 at 19:21.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    marad73's Avatar
    marad73 Guest


    Did you find this post helpful? Yes | No

    Talking Thanks all!

    Steve, thanks for all your help - really appreciated.
    One more thing I've got to do is:
    When the reset (mclr) is pulled low, (pushbutton) this thing goes into a reset routine, which I can write with no problem. This routine must reset (or stop) the wdt cycle, turn on a couple of outputs in sequence and run the ADs each time until they are equal. Then, it has to engage the wdt again and go to sleep for 2 minutes or so. (outputs actually running motors until ADs are equal)
    Without pushing mclr putton, it needs to then wake up from sleep every 2 minutes, run the ADs, then turn on the outputs, recheck ADs until equal, then go to sleep again for another 2 minutes.
    These two functions are baffling to me because I find no info about how to use the wdt or mclr to reset as above, in the manual at all. If you can help with some sample code to do this, or tell me where to find it, that will be REALLY appreciated.
    Thanks all!
    Ron
    PS This thing, times 2, is for an azimuth drive for my telescope-in case you are curious! As mentioned before, it operates most of the night, totally off of sunlight it gets during the day.
    PPS I understand seeing stars better than PIC code!!!

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Section 9.6 watch dog timer, have to be your friend now. Set the right prescaller in OPTION register and use the TO bit of STATUS.

    This should be something good enough to start.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. 18F8722 sample code
    By George in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th June 2008, 13:42
  5. LANC code 12F675
    By MikeDD in forum General
    Replies: 4
    Last Post: - 9th May 2008, 05:44

Members who have read this thread : 2

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

Posting Permissions

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