6. Alarm generator

Publisher:jingwenLatest update time:2016-09-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1.  Experimental task: 
Use P1.0 to output 1KHz and 500Hz audio signals to drive the speaker as an alarm signal. The 1KHz signal is required to sound for 100ms and the 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, and when the switch is opened, the alarm signal stops. Write a program.
2.  Circuit diagram 

Figure 4.6.1
3.  Hardware connection on the system board 
(1. Connect the P1.0 port in the "MCU system" area to the SPK IN port in the "Audio amplifier module" area with a wire;
(2. Connect an 8-ohm or 16-ohm speaker to the SPK OUT port in the "
Audio amplifier module" area; (3. Connect the P1.7/RD port in the "MCU system" area to the K1 port in the "Four-way toggle switch" area with a wire;
4.  Program design content 
(1. Signal generation method
500Hz signal period is 2ms, signal level reverses once every 1ms, 1KHz signal period is 1ms, signal level reverses once every 500us;
  
5.  Program flowchart 
start

Is K1 pressed?

Is FLAG=0?

Set to 200 counts
P1.0 output inversion

Delay 500us

Is the count complete?

FLAG inversion

Set to 200 counts
P1.0 output inversion

Delay 1ms

Is the count complete?

FLAG inversion

 
Figure 4.6.2
6.  Assembly source program 
FLAG BIT 00H 
                                      ORG 00H 
START: JB P1.7,START 
                                      JNB FLAG,NEXT 
                                      MOV R2,#200 
DV: CPL P1.0 
                                      LCALL DELY500 
                                      LCALL DELY500 
                                      DJNZ R2,DV 
                                      CPL FLAG 
NEXT: MOV R2,#200 
DV1: CPL P1.0 
                                      LCALL DELY500 
                                      DJNZ R2,DV1 
                                      CPL FLAG 
                                      SJMP START 
DELY500: MOV R7,#250 
LOOP: NOP 
                                      DJNZ R7,LOOP 
                                      RET 
                                      END 
7.  C language source program 
#include  
#include  
  
bit flag; 
unsigned char count; 
  
void dely500(void) 

  unsigned char i; 
  for(i=250;i>0;i--) 
    { 
      _nop_(); 
    } 

  
void main(void) 

  while(1) 
    { 
      if(P1_7==0) 
        { 
          for(count=200;count>0;count--) 
            { 
              P1_0=~P1_0; 
              dely500(); 
            } 
          for(count=200;count>0;count--) 
            { 
              P1_0=~P1_0; 
              dely500(); 
              dely500(); 
            } 
        } 
    } 
}
Reference address:6. Alarm generator

Previous article:7. I/O parallel port directly drives LED display
Next article:5. Advertising lights (using meter reading method)

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号