I am using a HCSR04 Ping Sensor and a PIC16F1829 board I am

I am using a HC-SR04 Ping Sensor and a PIC16F1829 board. I am also using the XC8 3.40 compiler.

Any idea what could be wrong with my code? It\'s running into my \"if\" statements. Also, its giving me this \"error\" in the debugger console \"No source code lines were found at current PC 0xffffffffffffffff\" and I\'m not entirely sure what that could mean.

Any adivce or help would be greatly appriciated

// PIC16F1829 Configuration Bit Settings

// \'C\' source line config statements

// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)

// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)


#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
//#include \"LCDpara.h\"


#define _XTAL_FREQ 4000000
#define RS RC0
#define RW RC6
#define E RC3

void Init_LCD(void);
void PutCMD_LCD(char);
void PutDATA_LCD(char);
  

int main(int argc, char** argv) {
  
__delay_ms(30);
ANSELB = 0;
TRISB = 0;
ANSELC = 0;
TRISC = 0x04;
OSCCON = 0X6A;
  

  
Init_LCD();
int i, a;

__delay_ms(3000);

T1CON = 0x10;
  


while(1){

TMR1H = 0;
TMR1L = 0; //Sets the Initial Value of Timer

RC1 = 1; //TRIGGER HIGH
__delay_us(10); //10uS Delay
RC1 = 0; //TRIGGER LOW
  
  
while(!RC2);
TMR1ON = 1;
  
  
while(RC2);
TMR1ON = 0;
  
  
  
  
a = (TMR1L | (TMR1H<<8)); //Reads Timer Value
a = a/58;
  
  
  
if(a>=2 && a<=400) //Check whether the result is valid or not
{
  
PutCMD_LCD (0x01);
PutDATA_LCD(\'F\');
}
else
{
PutCMD_LCD (0x01);
PutDATA_LCD(\'E\');
}

__delay_ms(400);
}


  

}

void Init_LCD(void){
int Dum;

RS=0;
RW=0;
E =0;
__delay_us(10);   
//First send 3 8 bit bytes of 0X3x to ensure proper power up
PORTB = (0x30); //One.....
__delay_us(10);
E = 1;
__delay_us(10);
E = 0;
__delay_us(10);
PORTB = (0x30); //2.....
__delay_us(10);
E = 1;
__delay_us(10);
E = 0;
__delay_us(10);
PORTB = (0x30); //3.....
__delay_us(10);
E = 1;
__delay_us(10);
E = 0;
__delay_us(10);
PORTB = (0x20); //Put in 4 bit mode
__delay_us(10);
E = 1;
__delay_us(10);
E = 0;
//Then turn on display with blinking cursor
PutCMD_LCD (0x0F);
//Put in 2 line mode 5x7 chars
PutCMD_LCD (0x28);
//clear display
PutCMD_LCD (0x01);
__delay_ms(10);
//clear display
PutCMD_LCD (0x02);
__delay_ms(10);
return;
}
// *****************************************************************

void PutCMD_LCD(char Command){
RS=0;
RW=0;
E = 1;
__delay_us(10); //short delay Dummy not used otherwise
PORTB = (Command); //send the high 4 bits first to RB4,5,6,7
__delay_us(10);
E = 0;
__delay_us(10); //short delay Dummy not used otherwise
E = 1;
__delay_us(10); //short delay Dummy not used otherwise
PORTB = (Command << 4); //Send the low nibble to RB 4,5,6,7
__delay_us(10); //short delay Dummy not used otherwise
E = 0;
__delay_ms(10); // May need a long delay for clear command
return;
}
// *********************************************************************
void PutDATA_LCD(char Data){
__delay_us(10);
RS=1;
RW=0;
E =1;
__delay_us(10);
PORTB = (Data); //send the high 4 bits first to RB4,5,6,7
__delay_us(10);
E = 0;
__delay_us(10);
E = 1;
__delay_us(10);
PORTB = (Data << 4); //Send the low nibble to RB 4,5,6,7
__delay_us(10);
E = 0;
__delay_us(10);
return;
}
  

Solution

If the above program compiles, then it is fine, issue is with MPLabX -

Here am enclosing the snippet of the \'If\' block -

if(a>=2 && a<=400) //validating condition
{
  
lcd_write(0x01);
lcd_write(\'f\'); // small alphabet \'f\'
//lcd_printf(\"off\"); // If u want this message to be printed, this statement of \'off\' could be used
}
else
{
lcd_write(0x01);
lcd_write(\'e\');
}
__delay_ms(400);
}

//Please try the above code snippet of \'IF\' block in your program, should complie.

I am using a HC-SR04 Ping Sensor and a PIC16F1829 board. I am also using the XC8 3.40 compiler. Any idea what could be wrong with my code? It\'s running into my
I am using a HC-SR04 Ping Sensor and a PIC16F1829 board. I am also using the XC8 3.40 compiler. Any idea what could be wrong with my code? It\'s running into my
I am using a HC-SR04 Ping Sensor and a PIC16F1829 board. I am also using the XC8 3.40 compiler. Any idea what could be wrong with my code? It\'s running into my
I am using a HC-SR04 Ping Sensor and a PIC16F1829 board. I am also using the XC8 3.40 compiler. Any idea what could be wrong with my code? It\'s running into my

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site