⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer0.c

📁 学习C51时写的定时器程序,提供给刚学单片机程序的朋友参考
💻 C
字号:
//This program is just for S51E&AVR board.
//If you want to see more informations
//please login our website: http//www.mcu2008.com 
//copy rights by NanJing Victor Electronic Co.,Ltd
//定时器中断实验一
//功能:利用定时器0产生的中断从而定时控制小灯的闪烁。
#include <reg51.h>
#define const_time 100;   //100x5ms=500ms=0.5s
unsigned char buff_time;  //buffer for storing the times
bit LED_Buffer;
sbit light0 = P1^0;

void main() 
{ TMOD=0x01;   //set the timer's mode
  TH0=(65536-5000)/256; //fill the timer0's higher register 
  TL0=(65536-5000)%256; //fill the timer0's lower register
  IE=0x82;   //EA=1,IT0=1
  LED_Buffer=0;
  light0=0;
  buff_time=const_time;
  TR0=1;     //start the timer!
  while(1){
  light0=LED_Buffer;
  }  
}

void T0Int() interrupt 1
{TH0=(65536-5000)/256; //fill the timer0's higher register 
 TL0=(65536-5000)%256; //fill the timer0's lower register 
 buff_time--;
 if (buff_time==0)
{buff_time=const_time; // refill the buffer
 LED_Buffer=!LED_Buffer;  // opposite the LED display
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -