Ultrasonic [HC-SR04] + PIC16F877A


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: Ultrasonic [HC-SR04] + PIC16F877A

    This works on PIC16F873A so should work on PIC16F877A
    Don't forget to pull MCLR high

    @ DEVICE PIC16F873A, HS_OSC 'Xtal OSC
    @ DEVICE PIC16F873A, WDT_OFF 'WDT off
    @ DEVICE PIC16F873A, PWRT_ON 'Power-up timer on
    @ DEVICE PIC16F873A, BOD_OFF 'Brown-out detect off

    ADCON1 = %00000110 'All PORTA digital

    define osc 4

    TRISA = %00000010
    TRISB = %00000000
    PORTB = %00000000

    w var word
    r var word
    a var word

    tr var PORTA.0 'Trig pin
    ec var PORTA.1 'Echo pin

    PORTB = %11111111 'Flash LED on PORTB
    pause 500 'to check PIC running
    PORTB = %00000000

    w = 0
    low tr

    Main :
    high tr
    pauseus 10
    low tr
    pulsin ec,1,w
    r = w/58
    if r < 10 then
    PORTB = %11111111
    else
    PORTB = %00000000
    endif
    pause 200
    goto main
    end

  2. #2
    Join Date
    Jun 2012
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: Ultrasonic [HC-SR04] + PIC16F877A

    Quote Originally Posted by Sherbrook View Post
    This works on PIC16F873A so should work on PIC16F877A
    Don't forget to pull MCLR high

    @ DEVICE PIC16F873A, HS_OSC 'Xtal OSC
    @ DEVICE PIC16F873A, WDT_OFF 'WDT off
    @ DEVICE PIC16F873A, PWRT_ON 'Power-up timer on
    @ DEVICE PIC16F873A, BOD_OFF 'Brown-out detect off

    ADCON1 = %00000110 'All PORTA digital

    define osc 4

    TRISA = %00000010
    TRISB = %00000000
    PORTB = %00000000

    w var word
    r var word
    a var word

    tr var PORTA.0 'Trig pin
    ec var PORTA.1 'Echo pin

    PORTB = %11111111 'Flash LED on PORTB
    pause 500 'to check PIC running
    PORTB = %00000000

    w = 0
    low tr

    Main :
    high tr
    pauseus 10
    low tr
    pulsin ec,1,w
    r = w/58
    if r < 10 then
    PORTB = %11111111
    else
    PORTB = %00000000
    endif
    pause 200
    goto main
    end
    Oh!! Thanks IT work

    But edit code r = w/58 >> r = ((w*10)/58)

    Thank you very much Sherbrook & LinkMTech

Similar Threads

  1. pic16f690 and ultrasonic tranducers
    By Nyaberi in forum Code Examples
    Replies: 1
    Last Post: - 3rd September 2012, 16:23
  2. Ultrasonic range meter
    By Crista in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th June 2008, 18:01
  3. Replies: 9
    Last Post: - 4th February 2008, 19:12
  4. ultrasonic sensor
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th May 2006, 20:26
  5. SRF08 Ultrasonic Rangefinder
    By rad in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th July 2003, 21:01

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts