tools.c

来自「采用mega8实现stk500 v2功能」· C语言 代码 · 共 50 行

C
50
字号
/**	\file
	<b>some tools</b><br>
	Autor: Matthias Wei遝r<br>
	Copyright 2005: Matthias Wei遝r<br>
	License: QPL (see license.txt)
	<hr>
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>

#include "tools.h"

volatile unsigned char t1_tick;
unsigned char t1_cnt;

//Konstanten im EEPROM
#define EEPROM  __attribute__ ((section (".eeprom")))

//Variablen im EEPROM
EEPROM unsigned char eeprom_sck_period=10;

ISR(SIG_OUTPUT_COMPARE1A)
{
  t1_tick=1;
  t1_cnt++;
}

unsigned char get_t1_tick(void)
{
  if (t1_tick)
    {
      t1_tick=0;
      return 1;
    }
  return 0;
}

/**
	Wartet n*1ms - 1ms max.
*/
void wait_ms(unsigned int n)
{
  while (n)
    {
      if (get_t1_tick()) n--;
    }
}

⌨️ 快捷键说明

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