#include <STC12C5A60S2.h>
typedef unsigned char u8;
typedef enum
{
Tim0_L_Int0_H = 1,
Tim0_L_Int0_L,
Tim0_H_Int0_L,
}EnumCase;
sbit LED1 = P2 ^ 4;
sbit LED2 = P2 ^ 5;
sbit LED3 = P2 ^ 6;
sbit LED4 = P2 ^ 7;
sbit BEEP = P1 ^ 0;
sbit KEY1 = P3 ^ 2;
sbit KEY2 = P3 ^ 4;
//---------------------------------------------------------------------
static u8 i_1sCnt = 0;
static u8 LEDStatus = 0;
//---------------------------------------------------------------------
void delay_2ms(unsigned long int time) //2ms�Ļ�
{
unsigned long int i;
for (i = 0; i < time * 100; i++);
}
void SetPriorty(EnumCase chose)
{
switch (chose)
{
case Tim0_L_Int0_H:
IP = 0x01;
break;
case Tim0_L_Int0_L:
IP = 0x00;
break;
case Tim0_H_Int0_L:
IP = 0x02;
break;
default:
break;
}
}
void Timer0_Init()
{
TH0 = 0; // Maximum delay, about 130ms
TL0 = 0;
TMOD = 0x01;
TR0 = 1;
ET0 = 1;
EA = 1;
}
void Timer0() interrupt 1
{
TH0 = 0;
TL0 = 0;
i_1sCnt++;
if (i_1sCnt==15)
{
i_1sCnt = 0;
LEDStatus++;
switch (LEDStatus)
{
case 1:
LED1 = 0; LED2 = 1; LED3 = 1; LED4 = 1;
break;
case 2:
LED1 = 1; LED2 = 0; LED3 = 1; LED4 = 1;
break;
case 3:
LED1 = 1; LED2 = 1; LED3 = 0; LED4 = 1;
break;
case 4:
LED1 = 1; LED2 = 1; LED3 = 1; LED4 = 0;
LEDStatus = 0;
break;
default:
break;
}
}
}
void ISR_Init()
{
IT0 = 0;
EX0 = 1;
EA = 1;
}
void INT0_ISR() interrupt 0
{
EX0 = 0;
BEEP = 1;
delay_2ms(125);
BEEP = 0;
delay_2ms(125);
BEEP = 1;
delay_2ms(125);
BEEP = 0;
delay_2ms(125);
EX0 = 1;
}
//-------------------------------------------------------------------------
//Set the ones you want to view to 1, and the ones you don't want to view to 0. Only one is 1
#define TEST1 1
#define TEST2 0
#define TEST3 0
void main()
{
BEEP = 0;
#if TEST1
SetPriorty(Tim0_L_Int0_H);
#endif
#if TEST2
SetPriorty(Tim0_L_Int0_L);
#endif
#if TEST3
SetPriorty(Tim0_H_Int0_L);
#endif
Timer0_Init(); //
ISR_Init();
while (1);
}
Previous article:AT89C51 external interrupt experiment realizes 8 lights turning on and off at the same time (controlled by external switch)
Next article:External interrupt 0/1 to light up the LED code
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Comparison between microbit and CLUE
- STM32F3 MCU peripheral components and crystal oscillator selection reference
- Review summary: Anxinke NB-IoT development board EC-01F-Kit
- MPS gives benefits | Order online at the mall, get a JD card, and 8,000 yuan worth of gifts are waiting for you!
- Discussion on the Reasons for the Temperature Drop of MOS Tubes Connected in Parallel
- The easiest way to achieve the LED breathing light gradually brightening and fading effect, without the need for single-chip control
- Why is the IRQ pin of PN532 useless?
- Half the size, twice the power! - Gallium nitride technology revolutionizes robotics, renewable energy, telecommunications and more
- WIFI+Bluetooth chip
- FPGA is too difficult. Too difficult.