Power-off test of AT89s52 microcontroller

Publisher:peon1989Latest update time:2017-01-17 Source: eefocusKeywords:AT89s52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

SMOD: This bit is related to serial port communication. 

    SMOD=0; When serial port mode is 1, 2, 3, the baud rate is normal. 

    SMOD=1; When serial port mode is 1, 2, or 3, the baud rate is doubled. 

GF1, GF0: Two general working flags, users can use them freely. 

    PD: Power-down mode setting bit. 

    PD=0 The microcontroller is in normal working state. 

    PD=1 The microcontroller enters the power down mode and can be awakened by an external interrupt or hardware reset mode. After entering the power down mode, the external crystal oscillator stops oscillating, the CPU, timer, and serial port all stop working, and only the external interrupt works. 

    IDL: Idle mode setting bit. 

      IDL=0 The microcontroller is in normal working state. 

    IDL=1 The MCU enters the idle mode. Except for the CPU, all other parts continue to work. In the idle mode, it can be awakened by any interrupt or hardware reset.

                                    

                            Test circuit diagram

 

The test procedure is as follows:


#include

#include

sbit key = P3^3; //Key to enter power-down mode

/****************************************

Function name: delay

Function: Delay for a period of time

***************************************/

void delay()

{

 unsigned int i;

 for(i=0;i<30000;i++);

}

/****************************************

Function name: delay20ms

Function: Delay 20ms

***************************************/

void delay20ms(void)     

{

  unsigned char i,j;

  for(i=0;i<100;i++)

   for(j=0;j<60;j++);

}

/****************************************

Function name: init

Function: Initialization program

***************************************/

void init()

{    

 EA=1; //Always enable interrupts

 EX0=1; //Open external interrupt 1

 IT0=1; //Falling edge trigger of external interrupt

}

/****************************************

Function name: keytest

Function: Keyboard program, press the key to enter power-down mode

***************************************/

void keytest()

{

   if(key==0)

 {

  delay20ms();

 if(key==0)

   {

   PCON=PCON|0x02; //Enter power-down mode

  }

  while(!key);

 } 

}

/****************************************

Function name: main

Function: Main function

***************************************/

void main()

{unsigned char aa = 0xfe;

 init();

 while(1)

 {//Realize the running light

  P0=aa;

  aa= _crol_(aa,1);

  delay();  

  keytest(); //Keyboard scan

 }

}

/****************************************

Function name: Int0

Function: interrupt service routine

***************************************/

 void Int0() interrupt 0 using 1

{

 P0=0x00; //All lights are on

 delay();

 delay();

 delay();

}


Experimental results: After the microcontroller is powered on, you can see the running lights rotating; when the key is pressed, the running lights stop and only one light is on; when the key connected to the P3.2 port is pressed, all 8 lights are on, and then the running lights continue to flow in the original position. Moreover, after power failure, the microcontroller is awakened by triggering an external interrupt through the key, the effect is good and it is easy to trigger.


Conclusion: After the AT89S52 microcontroller is awakened from power-down mode by an external interrupt, the external interrupt service program is executed first, and then it returns to the main program interrupt point to continue execution.


Keywords:AT89s52 Reference address:Power-off test of AT89s52 microcontroller

Previous article:Keil's C language compiler
Next article:51 MCU peripherals

Recommended ReadingLatest update time:2024-11-15 14:59

Design of an outdoor tester for transmitting devices with wireless terminals
Aiming at the problem that the field tester of the traditional air-to-air missile launcher cannot communicate directly with the aircraft cockpit, a field tester with a wireless module is designed. The tester can communicate with the cockpit wirelessly, which improves the test efficiency. At the same time, the wireless
[Microcontroller]
Design of an outdoor tester for transmitting devices with wireless terminals
Water Level Control System Based on AT89S52 Single Chip Microcomputer
  In order to achieve accurate control of the water level in the container, it is proposed to use AT89S52 as the main control chip, and the 24-bit high-precision A/D conversion chip HX711 processes the changes in the weak voltage signal output by the weighing sensor and converts it into a digital signal. The digital s
[Microcontroller]
Water Level Control System Based on AT89S52 Single Chip Microcomputer
Design of intelligent residential alarm system based on GSM
一 引言 随着经济的不断发展,人们的生活水平得到了显著提高;尤其是物质生活水平的提高,安全方面的问题越来越引起人们的重视。为了保障自家的财产安全,许多楼房住户都在自家地下室和住房的门、窗上安装了防盗门和防护栏等。然而,这些设备在防盗的同时,也带来了许多弊端:如,若防盗门钥匙丢失,会给户主带来很大的麻烦;家中遇到紧急情况,这些防盗设备也会给逃生及消防救援带来诸多不便。随着科学技术的不断进步,尖端科学技术应用的普及,许多智能化的报警系统也应运而生,它们将更便捷、更可靠地保障住户的财产安全。在本文中,笔者设计了一种基于GSM的住宅智能报警系统,该系统满足了现代住宅防盗的需要。 二 系统工作原理 该系统利用热释电红外传感器对防区实时
[Microcontroller]
Design of intelligent residential alarm system based on GSM
Analyze the design points of intelligent rescue robot
    O Introduction   Since the publication of "Rossum's Universal Robots" by Czechoslovak writer Karel Capek in 1920, people have been full of fantasies and expectations about robots. With the continuous development of society, the division of labor in various industries has become more and more detailed, and robots
[Microcontroller]
Analyze the design points of intelligent rescue robot
Serial interface of AT89S52 microcontroller
This article mainly studies the serial interface structure and related registers of the AT89S52 microcontroller. It is required to master the serial port structure and learn to reasonably set the control register to control the operation of the serial port. The serial interface inside the AT89S52 microcontroller can se
[Microcontroller]
Serial interface of AT89S52 microcontroller
Latest Microcontroller Articles
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号