📄 ad.c
字号:
/********************************************************************
ATmega16L学习板初始化及中断函数源文件
晶振频率: 8MHz
编写: hanzhaowei@2911.net
********************************************************************/
#include <iom16v.h>
#include <macros.h>
#include "../include/board.h"
/*=========================ADC Interrupt============================*/
#pragma interrupt_handler ADC_interrupt: iv_ADC
static unsigned int ADCresult; // save the ADC result
static unsigned char ADCflag;
/*===================================================================
// 函数功能: AD启动
// 形参: void
// 返回: void
// 编写: 2004/6/23
===================================================================*/
void ADCStart(unsigned char channel)
{
ADMUX = channel; // select channel
ADCSRA |= (1 << ADEN) + (1 << ADSC) + (1 << ADIE); // start a AD Conversion and enable AD Interrupt
ADCflag = 0;
}
/*===================================================================
// 函数功能: AD中断服务程序
// 形参: void
// 返回: void
// 编写: 2004/6/23
===================================================================*/
void ADC_interrupt(void)
{
unsigned int temp;
ADCresult = ADCL;
temp = ADCH;
temp <<= 8;
ADCresult += temp;
ADCflag = 1;
}
unsigned char ADC_Read(unsigned int *result)
{
if(ADCflag)
{
*result = ADCresult;
return true;
}
else
{
return false;
}
}
void Delay(unsigned int time)
{
unsigned int i;
while(time--)
{
for(i = 0; i < 500; i++)
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -