资源简介
arduino,中断用的函数库,可以进行定时器作用。为了说明这个问题,再举一例子。假设你有一个朋友来拜访你,但是由于不知道何时到达,你只能在大门等待,于是什么事情也干不了。如果在门口装一个门铃,你就不必在门口等待而去干其它的工作,朋友来了按门铃通知你,你这时才中断你的工作去开门,这样就避免等待和浪费时间。计算机也是一样,例如键盘输入,如果不采用中断技术,CPU将不断扫描键盘有否输入,经常处于等待状态,效率极低。而采用了中断方式,CPU可以进行其它的工作,只键盘有按键并发出中断请求时,才予以响应,暂时中断当前工作转去执行读取键盘按键,读完成后又返回执行原来的程序。这样就大大地提高了计算机系统的效率。
代码片段和文件信息
/*
MsTimer2.h - Using timer2 with 1ms resolution
Javier Valencia
History:
29/May/09 - V0.5 added support for Atmega1280 (thanks to Manuel Negri)
19/Mar/09 - V0.4 added support for ATmega328P (thanks to Jerome Despatis)
11/Jun/08 - V0.3
changes to allow working with different CPU frequencies
added support for ATMega128 (using timer2)
compatible with ATMega48/88/168/8
10/May/08 - V0.2 added some security tests and volatile keywords
9/May/08 - V0.1 released working on ATMEGA168 only
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not write to the Free Software
Foundation Inc. 51 Franklin St Fifth Floor Boston MA 02110-1301 USA
*/
#include
unsigned long MsTimer2::msecs;
void (*MsTimer2::func)();
volatile unsigned long MsTimer2::count;
volatile char MsTimer2::overflowing;
volatile unsigned int MsTimer2::tcnt2;
void MsTimer2::set(unsigned long ms void (*f)()) {
float prescaler = 0.0;
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)
TIMSK2 &= ~(1< TCCR2A &= ~((1< TCCR2B &= ~(1< ASSR &= ~(1< TIMSK2 &= ~(1<
if ((F_CPU >= 1000000UL) && (F_CPU <= 16000000UL)) { // prescaler set to 64
TCCR2B |= (1< TCCR2B &= ~((1< prescaler = 64.0;
} else if (F_CPU < 1000000UL) { // prescaler set to 8
TCCR2B |= (1< TCCR2B &= ~((1< prescaler = 8.0;
} else { // F_CPU > 16Mhz prescaler set to 128
TCCR2B |= ((1< TCCR2B &= ~(1< prescaler = 128.0;
}
#elif defined (__AVR_ATmega8__)
TIMSK &= ~(1< TCCR2 &= ~((1< TIMSK &= ~(1< ASSR &= ~(1<
if ((F_CPU >= 1000000UL) && (F_CPU <= 16000000UL)) { // prescaler set to 64
TCCR2 |= (1< TCCR2 &= ~((1< prescaler = 64.0;
} else if (F_CPU < 1000000UL) { // prescaler set to 8
TCCR2 |= (1< TCCR2 &= ~((1< prescaler = 8.0;
} else { // F_CPU > 16Mhz prescaler set to 128
TCCR2 |= ((1< TCCR2 &= ~(1< prescaler = 128.0;
}
#elif defined (__AVR_ATmega128__)
TIMSK &= ~(1< TCCR2 &= ~((1< TIMSK &= ~(1<
if ((F_CPU >= 1000000UL) && (F_CPU <= 16000000UL)) { // pre
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2009-05-29 12:49 MsTimer2\
文件 353 2008-06-12 10:11 MsTimer2\MsTimer2.h
文件 4706 2009-05-29 12:48 MsTimer2\MsTimer2.cpp
目录 0 2008-05-19 21:20 MsTimer2\examples\
目录 0 2009-05-29 12:50 MsTimer2\examples\FlashLed\
文件 289 2008-05-09 21:12 MsTimer2\examples\FlashLed\FlashLed.pde
- 上一篇:配电网pscad雷击模型
- 下一篇:触摸式感应按键的设计原理及指南
相关资源
- Arduino 亚博智能平衡小车源码
- Arduino_Uno-原理图
- flexitimer2库
- Arduino 超声波库函数
- arduino 读取温湿度dht11
- arduino电子时钟
- 人体检测模块
- arduino 原理图 PCB
- DallasTemperature,OneWire库
- DS1302的Arduino函数库
- TB6600步进电机Arduino控制程序
- Arduino UNO引脚分布图
- 气压传感器SDP810的Arduino控制代码
- arduino软串口库文件SoftwareSerial
- Arduino感光灯
- Arduino驱动四线电阻触摸屏代码
- 武术擂台机器人代码arduino
- arduino 5路循迹小车代码
- 基于Arduino的PM2.5和空气湿度检测装置
- 手势识别传感器paj7620 arduino板使用代
- ARDUINO开发板与读卡模块的连接使用
- Face-tracking.zip
- Dht11温湿度模块库文件
- Arduino uno+esp8266+onenet+dht11温湿度传感器
- Arduino与LabVIEW互动设计
- 智能小车超声波避障实验+源码(有舵
- Arduino通过ESP8266模块使用HTTP协议连接
- TLC5615 arduino库文件
- arduino开源平衡车源代码
- Arduino 格力空调红外编码库,当时做的
评论
共有 条评论