Steven5103
- Aug 20, 2010
- 10
- Joined
- Aug 20, 2010
- Messages
- 10
i need help...
the ultrasonic sensor could not work using the software i'm having...
there are current going to PIC but the PIC has no output for the ultrasonic.
i think the problem should be on the software...
but i cant figure out which part of the software has mistakes...
i need help please...
thank you..
The software :
#include <stdio.h>
#include <htc.h>
#include "delay.h"
#include "lcd.h"
#define ULTRASONIC_SENSOR RC2
#define MOTOR1_SIGNAL RB7
#define MOTOR1_DIRECTION RB6
#define MOTOR2_SIGNAL RB5
#define MOTOR2_DIRECTION RB4
__CONFIG(0x3f71);
void main ( void )
{
unsigned int sensorPulseRisingEdge, sensorPulseFallingEdge;
unsigned int sensorPulseWidth;
char LCDString [ 17 ];
// Initializations
TRISB = 0x00;
TRISC = 0x00;
lcd_init();
lcd_goto ( 0x00 );
lcd_puts ( "Pulse width:" );
MOTOR1_DIRECTION = MOTOR2_DIRECTION = 0;
T1CON = 0x01;
while ( 1 )
{
// Body
TRISC2 = 0;
RC2 = 1;
DelayUs ( 5 );
RC2 = 0;
TRISC2 = 1;
// Measure pulse width of ultrasonic sensor
while ( RC2 == 0 ) // wait for RC2 to go high
continue;
sensorPulseRisingEdge = ( TMR1H << 8 ) + TMR1L;
while ( RC2 == 1 ) // wait for RC2 to go low
continue;
sensorPulseFallingEdge = ( TMR1H << 8 ) + TMR1L;
sensorPulseWidth = sensorPulseFallingEdge - sensorPulseRisingEdge;
lcd_goto ( 0x40 );
sprintf ( LCDString, "%d us ", sensorPulseWidth );
lcd_puts ( LCDString );
DelayMs ( 250 );
DelayMs ( 250 );
}
}
the ultrasonic sensor could not work using the software i'm having...
there are current going to PIC but the PIC has no output for the ultrasonic.
i think the problem should be on the software...
but i cant figure out which part of the software has mistakes...
i need help please...
thank you..
The software :
#include <stdio.h>
#include <htc.h>
#include "delay.h"
#include "lcd.h"
#define ULTRASONIC_SENSOR RC2
#define MOTOR1_SIGNAL RB7
#define MOTOR1_DIRECTION RB6
#define MOTOR2_SIGNAL RB5
#define MOTOR2_DIRECTION RB4
__CONFIG(0x3f71);
void main ( void )
{
unsigned int sensorPulseRisingEdge, sensorPulseFallingEdge;
unsigned int sensorPulseWidth;
char LCDString [ 17 ];
// Initializations
TRISB = 0x00;
TRISC = 0x00;
lcd_init();
lcd_goto ( 0x00 );
lcd_puts ( "Pulse width:" );
MOTOR1_DIRECTION = MOTOR2_DIRECTION = 0;
T1CON = 0x01;
while ( 1 )
{
// Body
TRISC2 = 0;
RC2 = 1;
DelayUs ( 5 );
RC2 = 0;
TRISC2 = 1;
// Measure pulse width of ultrasonic sensor
while ( RC2 == 0 ) // wait for RC2 to go high
continue;
sensorPulseRisingEdge = ( TMR1H << 8 ) + TMR1L;
while ( RC2 == 1 ) // wait for RC2 to go low
continue;
sensorPulseFallingEdge = ( TMR1H << 8 ) + TMR1L;
sensorPulseWidth = sensorPulseFallingEdge - sensorPulseRisingEdge;
lcd_goto ( 0x40 );
sprintf ( LCDString, "%d us ", sensorPulseWidth );
lcd_puts ( LCDString );
DelayMs ( 250 );
DelayMs ( 250 );
}
}
Last edited by a moderator: