laitimes

Use timer T1 interrupt to control the LED and buzzer

Use timer T1 interrupt to control the LED and buzzer

Use the timer T1 interrupt to control two LEDs to blink in different cycles

#include// Contains a header file defined by 51 microcontroller registers

sbit D1=P0^0; Define bit D1 as the P0.0 pin

sbit D2=P0^1; Define bit D2 as the P0.1 pin

Note: Look at the schematic against the schematic, the schematic is not clear for zooming in.

unsigned char Countor1; Sets the global variable to store the number of timer T1 interrupts

unsigned char Countor2; Sets the global variable to store the number of timer T1 interrupts

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

Function function: Main function

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

void main(void)

{

EA=1; Turn on total interrupts

ET1=1; Timer T1 interrupt allowed

TMOD=0x10; Mode 1 using timer T1

TH1=(65536-46083)/256; The high 8 bits of timer T1 are assigned the initial value

TL1=(65536-46083)%256; The high 8 bits of timer T1 are assigned the initial value

TR1=1; Start timer T1

Countor1=0; Cumulative number of outages starting from 0

Countor2=0; Cumulative number of outages starting from 0

while(1)//Infinite loop waiting for interrupt

;

}

Function function: Interrupt service program for timer T1

void Time1(void) interrupt 3 using 0 //"interrupt" declares the function as an interrupt service function

The next 3 is the interrupt number of timer T1; 0 indicates the use of the 0th set of working registers

Countor1++; Countor1 adds 1

Countor2++; Countor2 adds 1

if(Countor1==2) // If the total is full 2 times, it is timed for 100ms

D1=~D1; Reverse the P2.0 pin output level

Countor1=0; Clear Counter1 to 0 and count from 0 again

if(Countor2==8) // If the total is full 8 times, it is timed for 400ms

D2=~D2; Bitwise invert the P2.1 pin output level

Countor2=0; Clear Counter1 to 0 and count from 0 again

TH1=(65536-46083)/256; The high 8 bits of timer T1 are reassigned to the initial value

TL1=(65536-46083)%256; The high 8 bits of timer T1 are reassigned to the initial value

The interrupt control buzzer with counter T1 emits 1KHz audio

sbit sound=P1^7; Define the sound bit as the P1.7 pin Note: Look at the schematic with the schematic unclear zoom in.

TMOD=0x10; TMOD=0001 000B, mode 1 using timer T1

TH1=(65536-921)/256; The high 8 bits of timer T1 are assigned the initial value

TL1=(65536-921)%256; The high 8 bits of timer T1 are assigned the initial value

sound=~sound;

TH1=(65536-921)/256; The high 8 bits of timer T1 are reassigned to the initial value

TL1=(65536-921)%256; The high 8 bits of timer T1 are reassigned to the initial value

Use timer T1 interrupt to control the LED and buzzer

Edit: Crossing the River Cloud

Read on