Use of 51 MCU timer T1 1-interrupt method

Publisher:阳关三迭Latest update time:2020-07-06 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Method 1: Delay method

Hardware: 11.0592MHz crystal, STC89C52, RXD P1.0 TXD P1.1

Baud rate: 9600

Description: T1 is used for timing, mode 1, timing time 50ms, interrupt mode, timing time is up, TF1=1, use the simulated serial port to send character 0x69

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

#include "reg52.h"

#define uchar unsigned char

 

sbit P1_0 = 0x90;

sbit P1_1 = 0x91;

sbit P1_2 = 0x92;

 

#define RXD P1_0

#define TXD P1_1

#define WRDYN 44 //Write delay

#define RDDYN 43 //Read delay

 

void Delay2cp(unsigned char i);

 

//Write a byte to the serial port

void WByte(uchar input)

{

uchar i=8;

TXD=(bit)0; //Send start bit

Delay2cp(39);

 

//Send 8 bits of data

while(i--)

{

TXD=(bit)(input&0x01); //Transmit low bit first

Delay2cp(36);

input=input>>1;

}

 

//Send check digit (none)

TXD=(bit)1; //Send end bit

Delay2cp(46);

}

 

//Read a byte from the serial port

uchar RByte(void)

{

uchar Output=0;

uchar i=8;

uchar temp=RDDYN;

 

//Send 8 bits of data

Delay2cp(RDDYN*1.5); //Note here, wait until the start bit

while(i--)

{

Output >>=1;

if(RXD) Output |=0x80; //Receive low bit first

Delay2cp(35); //(96-26)/2, the loop takes up 26 instruction cycles in total

}

 

while(--temp) //Search for the end position within the specified time.

{

Delay2cp(1);

if(RXD)break; //exit after receiving the end bit

}

 

return Output;

}

 

//Delay program*

void Delay2cp(unsigned char i)

{

     while(--i); //Exactly two instruction cycles.

}

 

void main()

{

 

 

TMOD=0x10; //T1 mode 1

 

TH1=0x9E; //50ms initial value

TL1=0x58; //50ms initial value

 

TR1=1; //Enable timer T1

ET1=1; //Open timer T1 interrupt

EA=1; //Open the general interrupt

 

while(1){;}

 

}

 

void timer1(void) interrupt 3

{

TH1=0x9E; //Reset the timing initial value

TL1=0x58;

 

WByte(0x69); //Send character

TF1=0; //Software clears interrupt flag

}

Reference address:Use of 51 MCU timer T1 1-interrupt method

Previous article:Use of 51 MCU timer T1 2-query method
Next article:51 MCU IO port simulation serial communication 6

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号