timertick.c

来自「这是一个基于8255扩展端口的keil c51固件」· C语言 代码 · 共 59 行

C
59
字号
/*
  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 + =
减小字号Ctrl + -
显示快捷键?