Question

In: Electrical Engineering

A PIC C code for Interfacing Ultrasonic sensor using PIC C 18F8722 microcontroller  

A PIC C code for Interfacing Ultrasonic sensor using PIC C 18F8722 microcontroller

 

Solutions

Expert Solution


#define trig RB0
#define echo RB1
#include <xc.h>

// Control Pin Declarations
#pragma config FOSC = HS      
#pragma config WDTE = OFF     
#pragma config PWRTE = ON     
#pragma config BOREN = ON     
#pragma config LVP = OFF      
#pragma config CPD = OFF      
#pragma config WRT = OFF      
#pragma config CP = OFF       

int t,S;

int main()
{
    TRISB0 = 0; //make trigger pin as output pin
    TRISB1 = 1; //make echo pin as input pin     
      
    T1CON=0x20;

      
    while(1)
    {
        TMR1H =0; TMR1L =0; //clear the timer bits
      
        trig= 1;
        __delay_us(10);         
        trig = 0;
      
        while (echo==0);
            TMR1ON = 1;
        while (echo==1);
            TMR1ON = 0;
      
        t = (TMR1L | (TMR1H<<8));        // time take for receiving echo
        S = (0.0272*t)/2;   // Distance measured  
          
      
    }
    return 0;
}


Related Solutions

What is the purpose of the status register in PIC microcontroller architecture? Draw this register and...
What is the purpose of the status register in PIC microcontroller architecture? Draw this register and define the function of each of its bits. Find C, Z, and DC flag bits for each of the following codes: a) MOVLW 9FH ADDLW 61H C = , Z = , DC = b) MOVLW 82H ADDLW 22H C = , Z = , DC = c) MOVLW 67H ADDLW 99H C = , Z = , DC =
Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed,...
Using an arduino, breadboard,  ultrasonic sensor, buzzer, lcd and red led display distance in centimeters, If needed, use a rotary potentiometer, male to male cable (m-m) female to male cable (f-m) or any resistor provided in the kit. display distance in centimeters to lcd. If the object is in distance, turn on Active buzzer(play sound) and turn on red led. If the object is not in range, display out of range or "Object now close'.  on the lcd, make sure the buzzer...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
An example of a PIC C program code for line following and obstacle avoiding robot? For...
An example of a PIC C program code for line following and obstacle avoiding robot? For it move forward and avoid an obstacle? PIC18F86722
An example of a PIC C program code for line following and obstacle avoiding robot? For...
An example of a PIC C program code for line following and obstacle avoiding robot? For it move forward and avoid an obstacle?
Write a code of digital alarm clock 8051 microcontroller using pin AT89S52
Write a code of digital alarm clock 8051 microcontroller using pin AT89S52
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and...
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and Port B and LED’s with PORTD. Write a code to read input from PortB and C and perform following. Addition of both inputs, Subtraction, Multiplication, Division, And, Or, Nor,Xor. (b)- A switch is connected to PD0 and LED’s to Port B and Port C. Write a code to perform following: When switch is 0 send your roll number to Port B. When Switch is...
Create a schematic of a circuit using and write C program to run on a PIC...
Create a schematic of a circuit using and write C program to run on a PIC 16F88 that will flash between a red and green LED at 5Hz with the green on 75% of the time and the red on 25% of the time.
DTMF home automation system using ATMEGA8 i need the circuit and the code for the microcontroller
DTMF home automation system using ATMEGA8 i need the circuit and the code for the microcontroller
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
Draw the schematic and code for an Arduino controlled system using a temperature sensor and fan.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT