51 MCU timer 0 works in mode 2

Publisher:码字探险Latest update time:2012-12-01 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The 51 MCU timer 0 works in mode 2. The INT0 (P3.2) pin controls the timer/counter to count. The timer/counter 0 overflow interrupt makes the LED connected to the P2.0 pin flash. The timer/counter 0 overflow interrupt is 250μs, and the LED connected to the P2_0 pin turns on and off every 2s. The source code is as follows:
//Original work of 51hei MCU Network, all rights reserved.
#include "reg_c51.h"
#define reload_value 0x06 //The count value is 250, if the clock frequency is 12MHz, it is equivalent to 250μs
unsigned char hex[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E}; //Hexadecimal decoding table of digital tube
unsigned char n,nn; //Define the interrupt count variable
void main(void) //Main function
{
TMOD &= 0xF0; //Timer/Counter 0 works in mode 2, 8-bit reload mode
TMOD |= 0x0A; //GATE0=1; C/T0#=0; M1=1; M0=0;
TL0 = reload_value; //Set initial value
TH0 = reload_value; //Set initial value
ET0=1; //Enable timer/counter 0 interrupt
EA=1; //Enable total interrupt
TR0=1; //Start timer/counter 0
while(1) //Infinite loop
{
P1=hex[n/10]; //Display the high bit of interrupt count variable n
P0=hex[n%10]; //Display the low bit of interrupt count variable n
}}
void it_timer0(void) interrupt 1 //Timer/counter 0 interrupt function
{
nn=nn++; //Add 1 to nn for each interrupt, and 250μs interval between each interrupt
if (nn==40) //nn=40, which means 40 interrupts, equivalent to 40*250μs =10ms
{
nn=0;
n++; //Add 1 to n every 10ms
if(n==100) //n=100, which is equivalent to 10ms*100=1s
{n=0;
P2_0 = ~P2_0; //Every 1s, invert the level of the P2_0 pin to make the connected LED light flash
}}}
Reference address:51 MCU timer 0 works in mode 2

Previous article:Use Timer 0 to generate multiple time intervals
Next article:51 MCU timer/counter works in mode 1

Recommended ReadingLatest update time:2024-11-16 14:26

How to light up a light-emitting diode using a 51 single-chip microcomputer
This is an experiment that everyone who learns 51 single-chip microcomputers will do, and it should be the first experiment. It is so simple and popular that there is nothing much to say, but I thought of some things that can be put together and talked about. First, here are the pictures: This is the schematic d
[Microcontroller]
How to light up a light-emitting diode using a 51 single-chip microcomputer
51 single chip microcomputer pulse controller
This is modified based on the previous timer.     Pulse controller     Output 4 pulses, output mode:     First output P0 for 50ms, then stop for 100ms, then output P1 for 50ms, then stop for 100ms...     After P3 output is completed, stop for 10 seconds and then cycle     Since the time is relatively r
[Microcontroller]
Design of electric vehicle seesaw using 51 single chip microcomputer
1. System design, comparison and demonstration According to the basic requirements of the topic, the design task is to complete the stable driving of the electric vehicle along the specified path within the specified time, and to have the function of maintaining balance, and to process and display the relevant data
[Microcontroller]
Design of electric vehicle seesaw using 51 single chip microcomputer
DHT11 temperature and humidity digital tube display based on 51 single chip microcomputer
Press button1 to switch modes Mode 0 only displays temperature Mode 1: Humidity only Mode 2 Dynamically display temperature and humidity, switching every 5 seconds The actual product is as follows temperature display Humidity display decimal Mode selection, automatic display switching between humidity
[Microcontroller]
DHT11 temperature and humidity digital tube display based on 51 single chip microcomputer
51 MCU-temperature controller design detailed explanation + circuit + code
This 51 single chip microcomputer circuit needs to use:   AT89C51 x1 Main control microcontroller   AT24C02 x1 EEPROM-2K memory   DS180B2 x1 temperature sensor   10uF x1, 47uF x1 polarized capacitors   104 x3, 30pF x2 non-polar capacitors   12MHz x1 Quartz Crystal Oscillator   1K x2 resistor
[Microcontroller]
51 MCU-temperature controller design detailed explanation + circuit + code
8051 MCU Tutorial Lesson 11: Arithmetic Operation Instructions
Addition instruction without carry bit ADDA,#DATA;例:ADDA,#10H ADDA,direct;例:ADDA,10H ADDA,Rn;To: ADDA,R7 ADDA,@Ri;例:ADDA,@R0 Purpose: Add the value in A to the value after it, and the final result is returned to A. Example: MOVA, #30H ADDA,#10H After executing this instruction, the value in A is 40H.
[Microcontroller]
MCS-51 series single chip microcomputer parallel expansion bus
  The P0 and P2 ports of MCS-51 can be used as parallel expansion buses to expand 64K bytes of program memory and 64K bytes of RAM I/O ports. The      P2 port outputs the high 8-bit address A8~A15, and the P0 port is a multiplexed port. It first outputs the low 8-bit address A0~A7, and uses the negative jump of the AL
[Microcontroller]
MCS-51 series single chip microcomputer parallel expansion bus
Notes on using Keil C51 MCU development environment
It is best to use Keil to write C51 programs. You can also use Weifu, but Weifu's editing capabilities are far inferior. I am used to writing code with Keil, and then using Weifu hardware simulation (only WAVE simulation head). However, Keil is easy to use, but the key to writing code is still the C51 level, that is
[Microcontroller]
Notes on using Keil C51 MCU development environment
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号