MCU INT0 and INT1 counters

Publisher:zhaodawei617Latest update time:2021-12-10 Source: eefocusKeywords:MCU  INT0  INT1  Counter Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Hardware Connection:

Code:


#include

#define uchar unsigned char

#define uint unsigned int


sbit k3 = P3^4;

sbit k4 = P3^5;


uchar code DSY_CODE[]=

{

  0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff

};


uchar code Scan_BITs[]=

{

  0x20,0x10,0x08,0x04,0x02,0x01

};


uchar data Buffer_Counts[]={0,0,0,0,0,0};

uint Count_A=0;

uint Count_B=0;


void DelayMS(uint x)

{

  flying t;

while(x--)

{

for(t=0;t<120;t++);

}

}


void Show_Counts()

{

  uint i;

Buffer_Counts[2] = Count_A / 100;

Buffer_Counts[1] = Count_A % 100 /10;

Buffer_Counts[0] = Count_A % 10;

if(Buffer_Counts[2]==0)

{

Buffer_Counts[2] = 0x0a;

if(Buffer_Counts[1]==0)

{

Buffer_Counts[1]=0x0a;

}

}


Buffer_Counts[5] = Count_B / 100;

Buffer_Counts[4] = Count_B % 100 /10;

Buffer_Counts[3] = Count_B % 10;

if(Buffer_Counts[5]==0)

{

Buffer_Counts[5] = 0x0a;

if(Buffer_Counts[4]==0)

{

Buffer_Counts[4]=0x0a;

}

}

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

{

P2 = Scan_BITs[i];

P1 = DSY_CODE[Buffer_Counts[i]];

DelayMS(1);

}

}


void main()

{

  IT0 = 1;

IT1 = 1;

PX0 = 1;

IE  = 0x85;

while(1)

{

if(k3 == 0) Count_A = 0;

if(k4 == 0) Count_B = 0;

Show_Counts();

}

}


void EX_INT0() interrupt 0

{

  Count_A++;

}


void EX_INT1() interrupt 2

{

  Count_B++;

}

Keywords:MCU  INT0  INT1  Counter Reference address:MCU INT0 and INT1 counters

Previous article:TIMERO microcontroller controls water lamp
Next article:Single digital tube displays 4x4 matrix buttons

Recommended ReadingLatest update time:2024-11-23 12:06

Programming a clock program with preset start time using C language for PIC microcontroller
  (1) Hardware Circuit      Using the 4-digit LED digital tube display circuit, a clock circuit with a 24-hour or 12-hour cycle display can be made, and the clock can be manually preset at the starting time. That is, after the circuit is plugged in, it can be manually adjusted according to the real time at that time,
[Microcontroller]
Programming a clock program with preset start time using C language for PIC microcontroller
AVR microcontroller atmega16 serial port interrupt receiving and sending program
// Target : M16 // Crystal: 8.0000Mhz // AVR microcontroller atmega16 serial port interrupt receiving and sending program. After receiving the character, send it out #include iom16v.h #include macros.h unsigned char com_in_buf ; void port_init(void) {  PORTA = 0xFF;  DDRA = 0xFF;  PORTB = 0x00;  DDRB = 0x0
[Microcontroller]
Detailed explanation of 51 single-chip microcomputer crystal oscillator
What is a crystal oscillator? The full name is quartz crystal oscillator, which is a high-precision and high-stability oscillator. Through a certain external circuit, a sine wave with stable frequency and peak value can be generated. When the microcontroller is running, it needs a pulse signal as a trigger signal for e
[Microcontroller]
Realization of Voice Recording and Playing System Based on AT89C52 Single Chip Microcomputer
1 Introduction Microcontrollers have been rapidly developed and widely promoted due to their high reliability, high cost performance, low voltage, low power consumption and other advantages. They are widely used in industrial control systems, data acquisition systems, intelligent instruments and
[Microcontroller]
Realization of Voice Recording and Playing System Based on AT89C52 Single Chip Microcomputer
Overview of Qinheng's 8-bit enhanced USB master-slave microcontroller CH559
Overview CH559 is an enhanced E8051 core microcontroller compatible with MCS51. 79% of the instructions are single-byte single-cycle instructions. It has built-in 60K Code Flash and 6K+256B Ram. CH559 has a built-in USB controller and dual USB transceivers. It supports USB-Host host mode and USB-Device device mode.
[Microcontroller]
Overview of Qinheng's 8-bit enhanced USB master-slave microcontroller CH559
How to send data packets in the RAM area of ​​the microcontroller network card
  This paper studies in depth the use of single-chip microcomputer to control the network card, access Ethernet, that is, IEEE802.3 protocol network, to achieve the networking of serial port instruments.   1 Hardware structure and circuit design   1.1 Overall Design   The whole system design uses ATMEL's 8-bit g
[Microcontroller]
How to send data packets in the RAM area of ​​the microcontroller network card
Samsung wins STMicroelectronics' 16nm MCU outsourcing order for next-generation iPhone
According to sources in the semiconductor industry, Samsung Electronics has received a contract from STMicroelectronics to produce MCUs for Apple's next-generation iPhone using a 16nm process. This is the first time that STMicroelectronics has outsourced MCU production for major customers such as Apple. According to t
[Mobile phone portable]
Interface circuit and driver based on ADC081S051 and 51 single chip microcomputer
introduction The signals existing in nature are usually analog signals. In the measurement and control system, the collected analog signals are usually digitized and then handed over to the microprocessor or microcontroller for processing. Therefore, the analog-to-digital converter becomes an indispensable part of the
[Power Management]
Interface circuit and driver based on ADC081S051 and 51 single chip microcomputer
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号