C51 Timer/Counter

Publisher:RadiantEyesLatest update time:2016-10-14 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
//External connection: P1.0 is connected to T1 counter input terminal P3.5.

 


#include

sbit out=P1^0;

void main()
{
 //T0 timer, working mode 2. Its interrupt function makes the out pin output pulse

//T1 counter, working mode 1. Its interrupt function makes P2 output pulse
 TMOD=0x52;

 //Interrupt enable
 ET0=1;
 ET1=1;
 EA=1;

 //Set T0 time constant, timing 200us,
 TH0=56;
 TL0=56;

 //Set T1 time constant, count 2500
 TH1=(65536-2500)/256;
 TL1=(65536-2500)%256;

 //Start
 TR0=1;
 TR1=1;

 while(1)
 ;
}

//Call this function every 200us,
void t0fun() interrupt 1
{
 out=~out;  
 
}

// When T1 reaches 2500, call this function
void t1fun() interrupt 3
{
 P2=~P2;
 //Set T1 time constant, count 2500
 TH1=(65536-2500)/256;
 TL1=(65536-2500)%256;

}

Keywords:C51 Reference address:C51 Timer/Counter

Previous article:C51: INT0
Next article:LCD:1602 display program

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号