Use 89S51 single chip microcomputer P1^0 to output 1KHZ and 500HZ audio signals

Publisher:Jinghua6666Latest update time:2015-06-16 Source: 51heiKeywords:89S51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Use 89S51 stand-alone P1^0 to output 1KHZ and 500HZ audio signals. 1KHZ signal is required to sound for 100ms, 500HZ signal is required to sound for 200ms alternately. P1^7 is connected to a switch for control. When the switch is closed, the alarm signal sounds. When the switch is open, the alarm stops. Write the program as follows

#include
#define uchar unsigned char
sbit K =P1^7;
sbit out =P1^0;
void main ( )
{while ( 1)
{if (K ==0)
uchar i ;
for (i =200;i >0;i --)
{m _500HZ ( );
}
for (i =200;i >0;i --)
{m _1KHZ ( );
}
}
}
}
void m _500HZ ( )
{out =~out
delay (2);
}
void m _1KHZ ( )
{out =~out
delay (1)
}
void delay (uchar z )
{uchar x ;
uchar y ;
for (x =z;x >0;x --)
{for (y =55;y >0;y --)
}
}

Keywords:89S51 Reference address:Use 89S51 single chip microcomputer P1^0 to output 1KHZ and 500HZ audio signals

Previous article:51 MCU pin functions and registers
Next article:Based on 51 single chip microcomputer to drive S8330E C language program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号