亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pulse.c

?? avr cpu 庫源代碼 對avr單片機編程很有幫助
?? C
字號:
/*! \file pulse.c \brief Pulse/frequency generation function library. */
//*****************************************************************************
//
// File Name	: 'pulse.c'
// Title		: Pulse/frequency generation function library
// Author		: Pascal Stang - Copyright (C) 2000-2002
// Created		: 2002-08-19
// Revised		: 2003-05-29
// Version		: 0.7
// Target MCU	: Atmel AVR Series
// Editor Tabs	: 4
//
// This code is distributed under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>

#include "global.h"
#include "timer.h"
#include "pulse.h"

// Global variables
// pulse generation registers
volatile static unsigned char  PulseT1AMode;
volatile static unsigned short PulseT1ACount;
volatile static unsigned short PulseT1APeriodTics;
volatile static unsigned char  PulseT1BMode;
volatile static unsigned short PulseT1BCount;
volatile static unsigned short PulseT1BPeriodTics;

// pulse mode bit definitions
// PULSE_MODE_COUNTED
//		if true, the requested number of pulses are output, then output is turned off
//		if false, pulses are output continuously
#define PULSE_MODE_CONTINUOUS	0x00
#define PULSE_MODE_COUNTED		0x01

// functions

void pulseInit(void)
{
	// initialize timer1 for pulse operation
	pulseT1Init();
}

void pulseT1Init(void)
{
	// try to make sure that timer1 is in "normal" mode
	// most importantly, turn off PWM mode
	timer1PWMOff();

	// set some reasonable initial values
	// in case the user forgets to
	PulseT1AMode = 0;
	PulseT1BMode = 0;
	PulseT1ACount = 0;
	PulseT1BCount = 0;
	PulseT1APeriodTics = 0x8000;
	PulseT1BPeriodTics = 0x8000;

	// attach the pulse service routines to
	// the timer 1 output compare A and B interrupts
	timerAttach(TIMER1OUTCOMPAREA_INT,pulseT1AService);
	timerAttach(TIMER1OUTCOMPAREB_INT,pulseT1BService);
}

void pulseT1Off(void)
{
	// turns pulse outputs off immediately
	
	// set pulse counters to zero (finished)
	PulseT1ACount = 0;
	PulseT1BCount = 0;
	// disconnect OutputCompare action from OC1A pin
	cbi(TCCR1A,COM1A1);
	cbi(TCCR1A,COM1A0);
	// disconnect OutputCompare action from OC1B pin
	cbi(TCCR1A,COM1B1);
	cbi(TCCR1A,COM1B0);
	// detach the pulse service routines
	timerDetach(TIMER1OUTCOMPAREA_INT);
	timerDetach(TIMER1OUTCOMPAREB_INT);
}

void pulseT1ASetFreq(u16 freqHz)
{
	// set the frequency of the pulse output
	// we need to find the requested period/2 (in timer tics)
	// from the frequency (in hertz)

	// calculate how many tics in period/2
	// this is the (timer tic rate)/(2*requested freq)
	PulseT1APeriodTics = ((u32)F_CPU/((u32)timer1GetPrescaler()*2*freqHz));
}

void pulseT1BSetFreq(u16 freqHz)
{
	// set the frequency of the pulse output
	// we need to find the requested period/2 (in timer tics)
	// from the frequency (in hertz)

	// calculate how many tics in period/2
	// this is the (timer tic rate)/(2*requested freq)
	PulseT1BPeriodTics = ((u32)F_CPU/((u32)timer1GetPrescaler()*2*freqHz));
}

void pulseT1ARun(u16 nPulses)
{
	// set the number of pulses we want and the mode
	if(nPulses)
	{
		// if the nPulses is non-zero, use "counted" mode
		PulseT1AMode |= PULSE_MODE_COUNTED;
		PulseT1ACount = nPulses<<1;
	}
	else
	{
		// if nPulses is zero, run forever
		PulseT1AMode &= ~PULSE_MODE_COUNTED;
		PulseT1ACount = 1<<1;
	}
	// set OutputCompare action to toggle OC1A pin
	cbi(TCCR1A,COM1A1);
	sbi(TCCR1A,COM1A0);

	// now the "enabling" stuff

	// set the output compare one pulse cycle ahead of current timer position 
	// to make sure we don't have to wait until the timer overflows and comes
	// back to the current value
	// set future output compare time to TCNT1 + PulseT1APeriodTics
	//outw(OCR1A, inw(TCNT1) + PulseT1APeriodTics);
	OCR1A += PulseT1APeriodTics;

	// enable OutputCompare interrupt
	sbi(TIMSK, OCIE1A);
}

void pulseT1BRun(u16 nPulses)
{
	// set the number of pulses we want and the mode
	if(nPulses)
	{
		// if the nPulses is non-zero, use "counted" mode
		PulseT1BMode |= PULSE_MODE_COUNTED;
		PulseT1BCount = nPulses<<1;
	}
	else
	{
		// if nPulses is zero, run forever
		PulseT1BMode &= ~PULSE_MODE_COUNTED;
		PulseT1BCount = 1<<1;
	}
	// set OutputCompare action to toggle OC1B pin
	// (note: with all the A's and B's flying around, TCCR1A is not a bug)
	cbi(TCCR1A,COM1B1);
	sbi(TCCR1A,COM1B0);

	// now the "enabling" stuff

	// set the output compare one pulse cycle ahead of current timer position 
	// to make sure we don't have to wait until the timer overflows and comes
	// back to the current value
	// set future output compare time to TCNT1 + PulseT1APeriodTics
	//outw(OCR1B, inw(TCNT1) + PulseT1BPeriodTics);
	OCR1B += PulseT1BPeriodTics;

	// enable OutputCompare interrupt
	sbi(TIMSK, OCIE1B);
}

void pulseT1AStop(void)
{
	// stop output regardless of remaining pulses or mode
	// go to "counted" mode
	PulseT1AMode |= PULSE_MODE_COUNTED;
	// set pulses to zero
	PulseT1ACount = 0;
}

void pulseT1BStop(void)
{
	// stop output regardless of remaining pulses or mode
	// go to "counted" mode
	PulseT1BMode |= PULSE_MODE_COUNTED;
	// set pulses to zero
	PulseT1BCount = 0;
}

u16 pulseT1ARemaining(void)
{
	// return the number of pulses remaining for channel A
	// add 1 to make sure we round up, >>1 equivalent to /2
	return (PulseT1ACount+1)>>1;
}

u16 pulseT1BRemaining(void)
{
	// return the number of pulses remaining for channel A
	// add 1 to make sure we round up, >>1 equivalent to /2
	return (PulseT1BCount+1)>>1;
}

void pulseT1AService(void)
{
	// check if TimerPulseACount is non-zero
	//		(i.e. pulses are still requested)
	if(PulseT1ACount)
	{
		//u16 OCValue;
		// read in current value of output compare register OCR1A
		//OCValue =  inp(OCR1AL);		// read low byte of OCR1A
		//OCValue += inp(OCR1AH)<<8;	// read high byte of OCR1A
		// increment OCR1A value by PulseT1APeriodTics
		//OCValue += PulseT1APeriodTics;
		// set future output compare time to this new value
		//outp((OCValue>>8),		OCR1AH);	// write high byte
		//outp((OCValue & 0x00FF),OCR1AL);	// write low byte

		// the following line should be identical in operation
		// to the lines above, but for the moment, I'm not convinced
		// this method is bug-free.  At least it's simpler!
		//outw(OCR1A, inw(OCR1A) + PulseT1APeriodTics);
		// change again
		OCR1A += PulseT1APeriodTics;
						
		// decrement the number of pulses executed
		if(PulseT1AMode & PULSE_MODE_COUNTED)
			PulseT1ACount--;
	}
	else
	{
		// pulse count has reached zero
		// disable the output compare's action on OC1A pin
		cbi(TCCR1A,COM1A1);
		cbi(TCCR1A,COM1A0);
		// and disable the output compare's interrupt to stop pulsing
		cbi(TIMSK, OCIE1A);
	}
}

void pulseT1BService(void)
{
	// check if TimerPulseACount is non-zero
	//		(i.e. pulses are still requested)
	if(PulseT1BCount)
	{
		//u16 OCValue;
		// read in current value of output compare register OCR1B
		//OCValue =  inp(OCR1BL);		// read low byte of OCR1B
		//OCValue += inp(OCR1BH)<<8;	// read high byte of OCR1B
		// increment OCR1B value by PulseT1BPeriodTics
		//OCValue += PulseT1BPeriodTics; 
		// set future output compare time to this new value
		//outp((OCValue>>8),		OCR1BH);	// write high byte
		//outp((OCValue & 0x00FF),OCR1BL);	// write low byte

		// the following line should be identical in operation
		// to the lines above, but for the moment, I'm not convinced
		// this method is bug-free.  At least it's simpler!
		//outw(OCR1B, inw(OCR1B) + PulseT1BPeriodTics);
		// change again
		OCR1B += PulseT1BPeriodTics;

		
		// decrement the number of pulses executed
		if(PulseT1BMode & PULSE_MODE_COUNTED)
			PulseT1BCount--;
	}
	else
	{
		// pulse count has reached zero
		// disable the output compare's action on OC1B pin
		cbi(TCCR1A,COM1B1);
		cbi(TCCR1A,COM1B0);
		// and disable the output compare's interrupt to stop pulsing
		cbi(TIMSK, OCIE1B);
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美色精品在线视频| 成人丝袜18视频在线观看| 久久成人免费网| 国产一区二区三区蝌蚪| 在线观看国产日韩| 久久久综合九色合综国产精品| 国产精品久久三| 日韩国产欧美视频| 99久久精品费精品国产一区二区| 宅男在线国产精品| 最新国产精品久久精品| 久久成人免费电影| 欧美精三区欧美精三区| 国产精品污污网站在线观看| 日韩av一区二| 色婷婷久久久亚洲一区二区三区| 精品成人一区二区三区四区| 亚洲最大成人综合| bt欧美亚洲午夜电影天堂| 久久综合色婷婷| 日韩av二区在线播放| 欧美在线不卡一区| 成人免费小视频| 国产成人免费视频| 久久久精品tv| 久草在线在线精品观看| 91精品在线一区二区| 亚洲午夜精品17c| 色国产综合视频| 18成人在线观看| 国产成人精品在线看| 精品久久人人做人人爰| 午夜av电影一区| 欧美人与禽zozo性伦| 亚洲另类在线一区| 色琪琪一区二区三区亚洲区| 国产精品久线在线观看| 国产成人免费9x9x人网站视频| 久久伊人蜜桃av一区二区| 麻豆精品视频在线观看免费| 9191国产精品| 久久国产精品99久久人人澡| 精品乱人伦一区二区三区| 久久69国产一区二区蜜臀| 日韩久久久精品| 国内一区二区在线| 国产日韩精品一区二区三区| 岛国一区二区三区| 国产精品初高中害羞小美女文| 成人av免费网站| 亚洲人妖av一区二区| 91精品福利在线| 亚洲国产成人91porn| 制服丝袜亚洲色图| 老司机午夜精品99久久| 日韩美女一区二区三区| 国产精品中文有码| 国产精品成人在线观看 | 亚洲福利视频导航| 在线不卡免费av| 日本成人在线视频网站| www激情久久| 成人高清视频在线| 一区二区三区欧美日韩| 777欧美精品| 国产传媒一区在线| 亚洲尤物在线视频观看| 欧美一区二区三区在线视频| 狠狠色丁香九九婷婷综合五月| 国产精品色噜噜| 欧美撒尿777hd撒尿| 精品制服美女久久| 亚洲欧美怡红院| 91精品蜜臀在线一区尤物| 高清shemale亚洲人妖| 一区二区三区在线观看视频| 91精品国产综合久久香蕉麻豆| 国产河南妇女毛片精品久久久| 中文字幕永久在线不卡| 欧美一区二区三区影视| 成人午夜又粗又硬又大| 午夜精品成人在线| 欧美韩国日本不卡| 欧美精品色一区二区三区| 国产91丝袜在线观看| 亚洲电影第三页| 中文在线免费一区三区高中清不卡| 91久久精品国产91性色tv| 国产精品一区二区在线播放| 亚洲国产综合色| 国产精品伦一区| 欧美大白屁股肥臀xxxxxx| 91视频观看免费| 国产精品亚洲视频| 日韩高清不卡一区| 亚洲理论在线观看| 欧美国产精品v| 欧美大胆人体bbbb| 欧美日韩一区二区三区高清| 成人在线视频首页| 国精品**一区二区三区在线蜜桃| 亚洲一区二区中文在线| 中文字幕第一区| 欧美精品一区视频| 欧美精品日日鲁夜夜添| 欧美影院一区二区三区| 成人性生交大合| 国产一区二区三区精品视频| 青青草成人在线观看| 亚洲自拍偷拍av| 一区二区三区四区蜜桃| 国产精品伦一区二区三级视频| 久久蜜桃一区二区| 精品国产区一区| 欧美成人精品福利| 911国产精品| 欧美一区二区三区性视频| 欧美日韩国产中文| 欧美色网一区二区| 欧美色老头old∨ideo| 欧美艳星brazzers| 在线视频亚洲一区| 欧美在线视频全部完| 色av成人天堂桃色av| 91久久奴性调教| 欧美日韩色综合| 欧美三级在线视频| 在线播放中文一区| 日韩网站在线看片你懂的| 91精品国产黑色紧身裤美女| 在线成人免费视频| 2020日本不卡一区二区视频| 国产日韩欧美精品综合| 亚洲日本成人在线观看| 亚洲高清不卡在线| 日韩中文字幕91| 国内精品第一页| 国产**成人网毛片九色| 成人av影院在线| 欧美综合久久久| 欧美一级久久久| 国产日韩精品一区二区三区在线| 国产精品美女久久久久久久久| 亚洲天堂精品在线观看| 亚洲成年人影院| 韩国理伦片一区二区三区在线播放| 国产精品资源在线| 91国产免费看| 69堂精品视频| 亚洲国产激情av| 一区二区三区免费在线观看| 日本成人中文字幕在线视频| 国产精品91xxx| 欧美亚洲综合另类| 精品久久久久久久久久久久久久久 | 粉嫩一区二区三区在线看| av电影天堂一区二区在线| 日本久久一区二区| 欧美tk—视频vk| 亚洲视频综合在线| 麻豆精品视频在线观看| www.性欧美| 欧美一区二区三区爱爱| 中文字幕在线不卡一区| 日韩中文字幕一区二区三区| 成人深夜在线观看| 91麻豆精品国产91久久久 | 欧美日韩国产大片| 国产亚洲欧美激情| 午夜激情综合网| 成人激情av网| 欧美v亚洲v综合ⅴ国产v| 亚洲欧洲在线观看av| 久久er99热精品一区二区| 色婷婷久久久综合中文字幕| 久久久久久夜精品精品免费| 亚洲国产精品久久人人爱蜜臀| 国产成人综合在线| 欧美日韩aaa| ...中文天堂在线一区| 国内成+人亚洲+欧美+综合在线| 在线国产亚洲欧美| 中文子幕无线码一区tr| 久久se这里有精品| 欧美精品 日韩| 亚洲精品福利视频网站| 风间由美一区二区三区在线观看 | 伊人开心综合网| 国产酒店精品激情| 欧美一级片免费看| 亚洲丰满少妇videoshd| 色呦呦日韩精品| 亚洲欧洲精品一区二区三区| 久久国内精品视频| 欧美高清性hdvideosex| 亚洲在线观看免费| 在线精品视频小说1| 尤物av一区二区| 色婷婷精品久久二区二区蜜臂av| 国产欧美日韩在线观看|