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

📄 timertick.c

📁 这是一个基于8255扩展端口的keil c51固件
💻 C
字号:
/*
  Copyright (C) 2003 Bart Bilos <boombox666@yahoo.com>.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation, 
  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

/*
  Timer library, basically functions to see how much time has elapsed
  since boot of the program, handy to use to calculate timeouts and 
  benchmarks.
*/

#include <Dallas\REG320.H>
#include "timertick.h"

// how many units since boot
unsigned int timeunits=UNIT_SEC;
unsigned long int seconds=0;

// ISR for timer ticker
void int1(void) interrupt 1 using 3 {
	timeunits--;
	if(timeunits==0){
		timeunits=UNIT_SEC;	
		seconds++;
	}
}

void inittimer(void) {
    // timer mode 1 reload mode
	TMOD = (TMOD & 0xF0) | (0x02);
	// cycle count
	TL0 = 0xFF - CYCLE_COUNT;	   	
	// cycle count
	TH0 = 0xFF - CYCLE_COUNT;	   	
    // timer 0 on
	TR0 = 1;
	// allow interrupts from timer 0
	IE = IE | 0x82;
}

// return amount of seconds elapsed since init of timer
long int getseconds(void) {
return seconds;
}

⌨️ 快捷键说明

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