Thread: Simple C programming question

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    2

    Simple C programming question

    Hello all,

    I have a simple question that deals with programming a PIC 12F675 micro controller using C.

    A little background: I have a comparator circuit in front of the PIC chip supplying either about 1.8V or 0V. These levels are supposed to act as either 'logic high' or 'logic low'.

    Basically I want the chip to read the logic high at an input and fire off 2 logic high signals at 2 separate outputs. If the chip reads a logic low, I want it to do nothing.

    I wanted to set a threshold level at 1.8V so the chip would interpret this or anything higher as 'logic high' since i can't get the full 5V to it. If the chip sees anything less than 1.8V, I want it to be considered logic low.

    My previous approach was to use the A2D converter built into the chip. The number 96 comes from the 1:64 prescalar and is supposed to represent 1.8V.

    I know this is simple and I may be way off. Any help is much appreciated!!!!!!!!!
    .................................................. .................................................. ..............
    #include <pic.h>

    __CONFIG(UNPROTECT & BORDIS & MCLRDIS & PWRTEN & WDTDIS & INTIO);

    main()
    {
    CMCON = 0b0000011; // Disable comparator
    ANSEL = 0b00111000; // Enable ADC
    ADCON0 = 0b00000001; // Turn on AD Control Register
    OPTION = 0b10000101; // Configure TMR0 with 1:64 prescalar
    TRISIO = 0b00111100; // Configure GP1 as ADC output
    // Configure GP0 as LED output
    // Configure GP4 as ADC input signal

    GPIO1=0; // Initially set ADC output low
    GPIO0=0; // Initially turn the LED off

    while(1)
    {
    while(ADRESH<96)
    {
    NOP();
    }
    while(ADRESH>96)

    {
    GPIO1=1;
    GPIO0=1;
    }
    }
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Feb 2008
    Location
    Delaware (USA)
    Posts
    8
    Hi Boxo, you may also want to post your project on the PIC12F6xx forum at Microchip Technology User Forums

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    2
    Thanks for the comments back..I actually got it working after 12 hrs of coding. Mountain dew made a lot of $ off me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM

Tags for this Thread