Society of Robots - Robot Forum
Software => Software => Topic started by: daisordan on March 12, 2011, 01:40:08 PM
-
I have writen up the code for my SRF05 sensor with 18F4455 with MPLAB. When i just run the code, its working fine. But now if i put any code in the main..like LED flashing... The whole sensor doesnt work. I didnt use isr for my sensor measurement, is that case my whole sensor not working??
Thanks
-
Post code.
-
unsigned int distance;
void set_timer0(void)
{
OpenTimer0(T0_16BIT &
T0_SOURCE_INT &
T0_PS_1_1 );
}
void trig_pulse (void)
{
LATDbits.LATD2 = 1;
Delay10TCY();
LATDbits.LATD2 = 0;
Delay10TCYx(20);
void measure_pulse (void)
{
while(PORTDbits.RD3);
T0CONbits.TMR0ON = 0;
}
void main (void)
{
LATDbits.LATD2 = 0;
TRISD=0b00001000;
while(1)
{
trig_pulse();
set_timer0();
while(!PORTDbits.RD3);
measure_pulse();
distance = (int)TMR0L + (int)TMR0H << 8;
distance /= (int)58;
}
}
-
Or maybe somethings wrong with the MPLAB setting? When i plug in PICkits to program the chip ( only sensor code), the sensor is working(power from PICkit). Now i program it, plug out PICkit, connect the chip to another power supply, the sensor doesnt work .
-
Post all of the code including the Config bits, includes and variable definitions.
Are you building DEBUG or RELEASE code? MPLAB tool bar drop-down.
Have you run/stepped through your code in MPLAB's Simulator?