Help pic programming

Discussion in 'Embedded Systems and Microcontrollers' started by mattlove, Dec 15, 2009.

  1. mattlove

    Thread Starter New Member

    Dec 15, 2009
    4
    0
    need help..
    i am currrently trying to prgram my pic to receive a signal from sensor then just to put out an output. out put is just LED
    void main(void)
    {
    TRISA=0b11111111; //set PORTB as input
    TRISB=0b11111111; //set PORTC as output
    TRISC=0b00000000;
    TRISD=0b00000000;
    RD3=1;

    {
    if(RB5==0)
    {
    RC3=1;
    }
    else if (RB5==1)
    {
    RC3=0;
    }
    }
    }
    this is my programming.. how come the RC# does not lie up at all???
    can any1 help me pls
     
  2. maxpower097

    Well-Known Member

    Feb 20, 2009
    795
    388
    actually what pic are you programming that will help.
     
  3. mattlove

    Thread Starter New Member

    Dec 15, 2009
    4
    0
    pic 16f877A
     
  4. S_lannan

    Active Member

    Jun 20, 2007
    247
    2
    seems to me the program would just poll the rb5 input once and thats it.

    if you put an infinite loop such as a while(1) the program would continously poll. like this

    void main(void)
    {
    TRISA=0b11111111; //set PORTB as input
    TRISB=0b11111111; //set PORTC as output
    TRISC=0b00000000;
    TRISD=0b00000000;
    RD3=1;

    while(1)
    {
    if(RB5==0)
    {
    RC3=1;
    }
    else if (RB5==1)
    {
    RC3=0;
    }
    }
    }
     
  5. mattlove

    Thread Starter New Member

    Dec 15, 2009
    4
    0
    okie lets make it easy. i wanna have a output after getting an input signal.. how come can i make it with rb7 as input. but if i change the input to rb5 or others, the output like rc2 is always on.. nothing happens... pls i need help
     
  6. Nanophotonics

    Active Member

    Apr 2, 2009
    365
    3
    If you show us a schematic, we might be able to help you better.
     
  7. mattlove

    Thread Starter New Member

    Dec 15, 2009
    4
    0
    //============================================================================
    // Include
    //============================================================================
    #include <pic.h>
    #include "delay.h"
    #include "delay.c"
    //============================================================================
    // Configuration
    //============================================================================
    __CONFIG ( 0x3F32 );
    //============================================================================
    // Define
    //============================================================================
    //============================================================================
    // Function Prototype
    //============================================================================
    void control(void);
    //============================================================================
    // global variable
    //============================================================================
    //============================================================================
    // Main Function
    //============================================================================
    void main(void)
    {

    TRISA=0b11111111; //set PORTB as input
    TRISB=0b11111111; //set PORTC as output
    TRISC=0b00000000;
    TRISD=0b11111111;
    RC4=1;
    RC5=1;

    {
    control();
    }
    }
    //================================================================================
    // FUNCTIONS
    //================================================================================
    void control(void)
    {
    if (RB7==1)
    {
    RC3=1;

    }
    else
    {
    RC3=0;

    }
    }

    if i change the input part RB7 to RB6 or other ports, the RC3 will keep on lite up.. it wont turn off... i suspect its got somehintg to do with __config.. is there any possiblity???
     
Loading...