12F675 code sample


Results 1 to 10 of 10

Threaded View

  1. #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.

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 : 0

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