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

📄 delay.c

📁 fat文件系统的源码 老外写的FAT32文件系统 还是有用的
💻 C
字号:
/*
  Written by:	Jesper Hansen <jesperh@telia.com>
  
  Rewritten by: Nikolai Vorontsov <nickviz@mail.be>

  From code by: Volker Oth <volkeroth@gmx.de>

  This file is part of the yampp system.

  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.
*/

#include "delay.h"

/*
Delay calculation - one outer loop contains:
sbiw, brcc_completed			= 2 + 2
ldi * 2							= 1 * 2
(subi, sbc, brcc_completed) * N	= (1 + 1 + 2) * N
subi, sbc, brcc_skipped			= 1 + 1 + 1

so, all above should be equal CYCLES_PER_10US => we can find N:
N = (CYCLES - 9) / 4 or with round-about N = (CYCLES - 7) / 4
For 7,3728MHz N ~= 16 that gives 73 cycles - almost fit for 73,7  
For 8MHz N ~= 18 that gives 81 cycles - almost fit for 80

If watchdog enabled this adds 1 cycle for each outer loop 
*/
void delay10(u16 count)
{
	register u16 delay_loops;

	while (count-- != 0)
	{
		WDR;
#ifdef ENABLE_WATCHDOG
		delay_loops = (CYCLES_PER_10US - 8) / 4;
#else
		delay_loops = (CYCLES_PER_10US - 7) / 4;
#endif
		while (delay_loops-- != 0);
	}
}


//
// Simple wrapper, we use a lot of delay10(1) calls 
//
void delay10us(void)
{
	delay10(1);
}

⌨️ 快捷键说明

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