macclock.c

来自「adhoc汇聚节点程序源代码(点对多点)——for atmega128」· C语言 代码 · 共 55 行

C
55
字号
/*
****************************************************************************  
*                        
*              宁波中科集成电路设计中心  版权所有 Copyright 2005
*
*文件名:  macClock.c
*程序员:  xp
*主要内容:mac时钟源
*完成日期:2005.6.10
****************************************************************************
*/

#include "macClock.h"
#include "os.h"
#include "led.h"
#include "mac.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>


#define SCALE_1ms 1
#define INTERVAL_1ms 7650  // 7650

void ClockStart(void)
{
    uint8_t intEnabled, scale = SCALE_1ms;
	uint16_t interval = INTERVAL_1ms;
	scale |= 0x8;
	cbi(TIMSK, OCIE1A);						// 关比较器A的输出中断
	intEnabled = bit_is_set(SREG, 7);
	cli();									// 访问寄存器前先关中断
	outw(TCNT1L, 0);						// 清空寄存器
	outw(OCR1AL, interval);					// 设置比较匹配寄存器
	if (intEnabled) 
		sei();
	outp(scale, TCCR1B);					// 设置为8分频
	sbi(TIMSK, OCIE1A);						// 开中断
}

INTERRUPT(SIG_OUTPUT_COMPARE1A)				// 中断服务程序
{
    MACClockFire();
}

void TimeStampGetTime32(uint32_t *timePtr)	// 得到当前时钟计数器中的值,用于时间戳
{
	uint8_t intEnabled = bit_is_set(SREG, 7);
	cli();     
	*timePtr = (uint32_t)inw(TCNT1L);		// 读TCNT1
	if (intEnabled) sei();
}

⌨️ 快捷键说明

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