After the alarm starts to work, the AT89C51 microcontroller first initializes the system, turns off the external devices such as the high tone alarm, the digital tube and the dazzling light, turns off the external interrupt 1 permission bit and the timing counter T0, and turns on the total interrupt permission bit, the external interrupt 0 permission bit and the timing counter T1. The deployment / removal button is used to trigger external interrupt 0, pyroelectric sensor is used to trigger external interrupt 1, and the opening and closing of external interrupt 1 permission bit is controlled by external interrupt 0, which is convenient for deployment and removal of alarm. The time counter t0 is used to control the sound frequency of the treble alarm to make it sound; the time counter T1 is used as a delay function. According to the above working principle and hardware structure analysis, the main program flow chart of the system is shown in Figure 3-14