stc15系列单片机 timer组件



/**
 *  文件名:timer.h
 */

#ifndef _TIMER_H
#define _TIMER_H

#define SYS_MCLK 11059200	//系统主时钟
#define FOSC	 11059200	//晶振频率



#define USING_T0
#define USING_STC15_T2



#ifdef USING_T0
	extern uint8_t tmr0LowByte, tmr0HighByte;
	void tmr0_init(uint8_t ms);
#endif



#ifdef USING_T1
	extern uint8_t tmr1LowByte, tmr1HighByte;
	void tmr1_init(uint8_t ms);
#endif



#ifdef USING_T2
	void tmr2_init(uint8_t ms);
#endif



#ifdef USING_STC15_T2
	void stc15_tmr2_init(uint8_t ms);
#endif



#endif



/**
 *  文件名:timer.c
 */

#include <stc15f2k60s2.h>
#include "stdint.h"
#include "timer.h"


/**
 * 定时器0
 */
#ifdef USING_T0
uint8_t tmr0LowByte, tmr0HighByte;

void tmr0_init(uint8_t ms) {	//!!8bits
	uint32_t tmp;	//小心溢出

	tmp = ms * SYS_MCLK / 12 / 1000;
	tmp = 65536 - tmp;
	tmr0Lo
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值