element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum MPLAB coding
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 9 replies
  • Subscribers 462 subscribers
  • Views 777 views
  • Users 0 members are here
Related

MPLAB coding

Former Member
Former Member over 14 years ago

Hi Jeremy,

 

I am doing a project with the question like this: If the person is near the speaker, the volume will decrease and when the person is far from the speaker, the volume will increase.

 

I would like to ask if I am using MPLAB ICD 2 (P18F4520) mircocontroller and connecting it with a PING ultrasonics distance sensor #28015 to control the volume by using a stereo auto volume control (PGA 2311).

 

How do my coding sure write??  I need some example:

 

 

Best Regards,

 

Terry

terry_lee80@hotmail.com

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 14 years ago in reply to awinning +1
    Help me to take a look of this code.. there is not pulse for output port. what should i do? #include <p18f4520.h> #include "stdio.h" #include "stdlib.h" #include "SRF05.h" void setup(void); void setup_lcd…
  • awinning
    awinning over 14 years ago

    Hi Terry,

     

    It all depends on your inputs and outputs and what ratio you require from distance and volume

     

    I'm a bit rusty with programming, but would it be worth looking at

     

    d = distance in meters

    v = volume

    c = constant

     

    v = c x d

     

    So if you gave c a value of 2, v = 8 at 4m, and 16 at 8m.

     

    You'd probably have to mess around a little converting the inputs and outputs to the right area for calculating

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 14 years ago in reply to awinning
    Hi Alistair Winning,

     

    Thanks for your info.. but I am weak in programming, thats why looking for some help from here.

     

     

    Best Regards,

    Terry

    terry_lee80@hotmail.com

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • awinning
    awinning over 14 years ago in reply to Former Member

    Hi Terry,

     

    It's very hard to guess what you need without knowing the input from the sensor (Digital/Analog), the distances you want to measure, and the sound output scale.


    Ally

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • awinning
    awinning over 14 years ago in reply to Former Member

    Terry,

     

    I've also moved the discussion to Embedded Design. I think you have a much better chance of getting help here,


    Regards,


    Ally

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 14 years ago in reply to awinning
    Alistair Winning,
    thank you so much... ^^
    Best Regards,
    Terry
    terry_lee80@Hotmail.com
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 14 years ago in reply to awinning

    Help me to take a look of this code.. there is not pulse for output port. what should i do?

     

    #include <p18f4520.h>
    #include "stdio.h"
    #include "stdlib.h"
    #include "SRF05.h"

    void setup(void);
    void setup_lcd(void);
    void print_buff(void);
    void set_cursor(unsigned char pos);
    void SetTimer(unsigned int time);
    void Wait4Timer(void);
    void send_pulse(void);
    void measure_pulse(void);

    #define TRIG   LATDbits.LATD3   // used to trigger the srf05
    #define ECHO   PORTDbits.RD3   // Used to read the echo pulse back from  SRF05

    unsigned char s[21];       // used to print data to the LCD03

    void main(void)
    {
    unsigned int range;

    setup();
    //setup_lcd();       // Clear LCD03 screen and hide cursor
    //set_cursor(1);
    // sprintf(s, "SRF05 Example");
    // print_buff();

    while(1)
    {
      SetTimer(6500);      // Start a 50mS timer running with timer 0

      TRISDbits.TRISD3 = 0;    // Set the pin for SRF05 to output  
      send_pulse();      // Send a 10uS pulse to trigger the SRF05  
      TRISDbits.TRISD3 = 1;
       while(!ECHO);      // Wait for echo line to go high
      measure_pulse();     // Measure the length of the incoming pulse using timer 1

      range = (TMR1H << 8) + TMR1L;  // Get timer 1 values high byte and low byte into range
      range /= 58;      // Range is a reading in uS dividing this by 58 will give us the range
      //sprintf(s, "Range: %i  ", range);
         //set_cursor(21);
      //print_buff();

      Wait4Timer();      // Wait for the 50mS timer to finish before triggering the SRF05 again
    }
    }

    /*****************
    * SRF05 routines *
    *****************/

    void send_pulse(void)
    {
    TMR1H = 255;     // Set the clock to only need 2 counts to roll over   
    TMR1L = 253;     // This will give us 10uS before it rolls over

    TRIG = 1;       // Pin high to trigger ping from SRF05;

    PIR1bits.TMR1IF = 0;   // Clear timer 1 interupt flag
    T1CONbits.TMR1ON = 1;   // Start timer 1 running for 10us
    while(PIR1bits.TMR1IF == 0); // Wait for interupt to be set
    T1CONbits.TMR1ON = 0;
    TRIG = 0;       // Pin output for SRF05 low
    TMR1H = 0;      // Clear timer
    TMR1L = 0;    
    }

    void measure_pulse(void)
    {
    T1CONbits.TMR1ON = 1;   // Start timer 1 counting
    while(ECHO);     // Wait for echo line to go low
    T1CONbits.TMR1ON = 0;
    }

    /*****************
    * Timer Routines *
    *****************/
    void SetTimer(unsigned int time)
    {
    TMR0H = 0-(time/256);
    TMR0L = 0-(time&0xff);
    INTCONbits.TMR0IF = 0;
    }

    void Wait4Timer(void)
    {
    while(INTCONbits.TMR0IF==0);
    }

    /*************
    * Chip setup *
    *************/

    void setup(void)
    {
    OSCCON = 0x70;    // set 8MHz

    TRISDbits.TRISD3 = 0;  // pin output for SRF05
    LATDbits.LATD3 = 0;  

    T0CON = 0x83;    // 16bit, 64:1 prescaler
    T1CON = 0x10;    // Timer 1 16bit: 2:1 prescaler

    ADCON1 = 0x0f;    // all ports to digital
    TRISC = 0x1F;
    SSPSTAT = 0x80;    // slew diabled
    SSPCON1 = 0x38;    // master mode enabled
    SSPADD = 0x11;    // 100khz
    }


    Best Regards,

    Terry
    terry_lee80@hotmail.com

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    Hey guys,

     

               I have a question, I've just started out on the Arduino for a couple of months now, and i have an idea to try out on the Arduino, but don't have enough coding knowledge to do so. I do, however, have acquire some basic knowledge on coding overall. My question is, I have an idea on building a Novation Launchpad (Google that up if you don't know what that is) using just an Arduino UNO , a 4 x 4 keypad, and a speaker. My aim is to having it play some simple sounds, as well as able to combine those simple sounds to form a chord.

     

              To do this, i have already found a code called Multikey in the examples on the Arduino IDE. I have modified the code a little bit to make it work on a 4x4 Keypad.  What this code does is that it can keep track of how long you press a key on the keypad, as well as keeping track of multiple key presses. I figured i can make a few changes to the key to play a specific set of sounds found on pitch.h , but have no idea how to do so, so any help whether in the form of links / code would be very appreciated.

     

    Thank you.

     

    -Lim-

     

     

    contact me at :

    allforpro@gmail.com

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • vsluiter
    vsluiter over 11 years ago in reply to Former Member

    Hello Lim,

     

    Please start a new discussion for this, as it is not related to MPLAB coding (the subject of this thread).

    You'll probably get more and better answers then!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to vsluiter

    Oh, I'm sorry. I didn't know this was not a related topic here, I'm new here, so i don't know where to reply to.

     

    Thanks anyway image

     

    -Lim-

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube