EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / how to convert the program to generate sound using micro controller 8051 into hex code??

how to convert the program to generate sound using micro controller 8051 into hex code??

|

Microcontroller › 8051 › how to convert the program to generate sound using micro controller 8051 into hex code??

  • This topic has 3 replies, 3 voices, and was last updated 13 years ago by Sana Paul.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • April 16, 2013 at 2:35 pm #2271
    Sana Paul
    Participant

     

    // Program to generate different sounds using micro controller

    #include<reg51.h>
    sbit out=P1^0; //output pin 1

    void delay(unsigned char p,unsigned char q)
    {
    TMOD=0x01; //timer0 mode1(16 bit)
    TL0=q; //load TL0
    TH0=p; //load TH0
    TR0=1; //turn on T0
    while(TF0==0); // wait for flag generation
    TR0=0; // turn off T0
    TF0=0; // clear TF0
    }

    void play(unsigned char j,unsigned char k)
    {
    int i;
    for(i=0;i<1000;i++) //to play sound
    {
    out=1;
    delay(j,k);
    out=0;
    delay(j,k);
    }
    }

    void main()
    {
    int l;
    while(1)
    {
    play(0xfc,0x66); //playing sound of frequency of about 500 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00); //delay of 71 miliseconds
    }
    play(0xfe,0x33); //playing sound of frequency of about 1000 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00);
    }
    play(0xff,0xa3); //playing sound of frequency of about 5000 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00);
    }
    play(0xff,0xd1); //playing sound of frequency of about 10000 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00);
    }
    play(0xff,0xdc); //playing sound of frequency of about 13000 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00);
    }
    play(0xff,0xcc); //playing sound of frequency of about 9300 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00);
    }
    play(0xff,0xe8); //playing sound of frequency of about 20000 hertz with a delay between two frequencies
    for(l=0;l<5;l++)
    {
    delay(0x00,0x00);
    }
    }
    }

     

    April 16, 2013 at 3:11 pm #9506
    Savio
    Participant

    Which compiler are you using?

     

    In Keil C51, ‘Target’ options will allow you to create a .hex file when compiling the code.

     

    On the left side, right-click ‘Target’ and select ‘Target options’ —- then click ‘Output’ tab and tick’ create HEX file’.

    April 20, 2013 at 4:59 am #9537
    RUBEN KURIAKOSE
    Participant

    hi;

              

    In Keil u-vision,right click on ‘Target’ and options for target will allow you to create a .hex file in the output window.

     

    You should use a programmer or a burner to burn this hex code into the microcontroller.

    April 21, 2013 at 2:02 pm #9555
    Sana Paul
    Participant

    thank you so much for all your replies….smiley

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • S1MJ ? April 20, 2026
  • timing delay code statements using Swordfish April 20, 2026
  • Selection Criteria and Safe Usage of Cable Ties in Electronics Applications April 20, 2026
  • properly producing TDR on PNA network analyzer N5224B April 20, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise