Need assistance in PIC using C programming!!!

Discussion in 'Embedded Systems and Microcontrollers' started by keigo911, Aug 25, 2008.

  1. keigo911

    Thread Starter New Member

    Aug 15, 2008
    1
    0
    Hello guys, i am newbie here, was doing a project regarding infrared sensor autogate...

    what i wish to ask is how to write the command for the situation stated below?

    When a IR receiver received a signal from IR transmitter for more than 3 sec, only the DC motor will move CW or CCW? else, the motor will be remained stationary, even there is something pass by between.... the concept is some sort like a level sensor, to sense the container volume, which the IR receiver was triggered when the container full....

    I have try the delay command be4, but it does not work.... it just delay the time of the motor to move, even the IR receiver just get the signal.... so what i wish is to make sure that when the object is stick stationary for more than 3 sec only the motor will be triggered...

    thanks very much! hope some1 to help out......URGENT PROJECT!!!


    to let all more understand about the code, i hereby posted up the program to emphasize the prob i encounter now...



    #define IN1 PIN_B0
    #define IN2 PIN_B1
    #define IN3 PIN_B2
    #define IN4 PIN_B3

    #define MOTOR_1_CW 1
    #define MOTOR_1_CCW 2
    #define MOTOR_1_STOP 3
    #define MOTOR_2_CW 4
    #define MOTOR_2_CCW 5
    #define MOTOR_2_STOP 6

    #define OFF 1 //IR receiver open circuited
    #define ON 0 //IR receiver connected to ground

    void motor_motion(unsigned int motion);

    void main()
    {

    // setup_adc_ports(ALL_ANALOG);
    // setup_adc(ADC_CLOCK_INTERNAL);
    setup_psp(PSP_DISABLED);
    setup_spi(FALSE);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
    setup_timer_1(T1_DISABLED);
    setup_timer_2(T2_DISABLED,0,1);
    setup_comparator(NC_NC_NC_NC);
    setup_vref(FALSE);

    SET_TRIS_B(0x00);
    SET_TRIS_A(0xFF);

    motor_motion(MOTOR_1_STOP);
    motor_motion(MOTOR_2_STOP);

    while(1){
    if(input_state(PIN_A0) == ON
    || input_state(PIN_A1) == ON
    || input_state(PIN_A2) == ON
    || input_state(PIN_A3) == ON
    || input_state(PIN_A5) == ON){

    int i;
    i = 1;
    if(i < delay_ms(1000)){
    motor_motion(MOTOR_1_STOP);
    }
    motor_motion(MOTOR_1_CCW);
    }
    else motor_motion(MOTOR_1_STOP);


    >>> Here is the condition to make my situation proved, i nid some1 help here, my program ady written as, but it only works as stated above<<<
    }

    }

    void motor_motion(unsigned int command){
    if(command == MOTOR_1_CW){
    output_high(IN1);
    output_low(IN2);
    }
    else if(command == MOTOR_1_CCW){
    output_high(IN2);
    output_low(IN1);
    }
    else if(command == MOTOR_1_STOP){
    output_low(IN1);
    output_low(IN2);
    }
    }
     
Loading...