Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Interface help for Two ultrasonic sensors with pic

Status
Not open for further replies.

kamalkannan12

Newbie level 4
Newbie level 4
Joined
Jan 4, 2015
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Chennai
Visit site
Activity points
30
Hi,
I've done interfacing of ultrasonic with pic16f887 . But I can't done coding for two or more ultrasonic with same PIC. Please tell me Some Ideas or sample codes.

Thank you.


My code for single ultrasonic is here:

Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections



char i;                              // Loop variable

  int a,b;
  char txt1[7],txt2[7];

void main()
{
  ANSEL  = 0;                        // Configure AN pins as digital I/O
  ANSELH = 0;

  TRISD=0x80;
  PORTD=0x00;

  Lcd_Init();

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,"ULTRASONIC");                 // Write text in first row

  Delay_ms(1000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

 T1CON = 0x10;                 //Initialize Timer Module

  while(1)
  {
   TMR1H = 0;
   TMR1L = 0;

   PORTD=0x40;                  // send trigger on D6
   Delay_us(10);              //10uS Delay
   PORTD=0x00;

   while(!((PORTD&0x80)==0x80));           //Waiting for Echo 1
   T1CON=T1CON|0x01;//Set Timer1: Start
   while((PORTD&0x80)==0x80);            //Waiting for Echo1 goes LOW
   T1CON=T1CON&0xFE; //Clear Timer1: Stop


    a = (TMR1L | (TMR1H<<8));   //Reads Timer Value
    a = a/58.82;                //Converts Time to Distance
    a = a + 1;                  //Distance Calibration


  
    if(a>=2 && a<=400)          //Check whether the result is valid or not
    {
     IntToStr(a,txt1);
     Ltrim(txt1);
     Lcd_Out(1,1,"Distance = ");
     Lcd_Out(1,11,txt1);
     Lcd_Out(1,15,"cm");
     Delay_ms(500);
    }
    
    else
    {
    Lcd_Out(2,1,"Out of range");
    }
  }
  
  

}
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top