📄 ad_convert.c
字号:
/****************************************Copyright (c)**************************************************
********************************************************************************************************/
#define IN_ADCONVERT
#include "config.h"
extern OS_EVENT *QSem;
/********************************************
* *funcition:send the converted value to queue
********************************************/
void read_value(void)
{
uint32 txmsg;
txmsg=(uint32)rADCDAT0 & 0x3ff;
OSQPost(QSem, (void *)&txmsg); //send a message
}
/********************************************
* *
********************************************/
void AD_Exception(void)
{
rSUBSRCPND = (1<<10); //sub source pending
rINTPND = rINTPND;
rSRCPND = (1 << 31);
rINTPND = rINTPND;
read_value();
}
/*******************************************
* *
*******************************************/
void AD_init(void)
{
rCLKCON |= 1<<15; //enable the ADC clock
rINTSUBMSK &=~(1<<10); //
VICVectAddr[31] = (uint32) AD_Exception;
rINTMSK &= ~(1<<31); // 打开AD中断允许
}
/**********************************************
* *
**********************************************/
void start_adc(uint32 chanel)
{
int i;
static int prevCh=-1;
uint32 preScaler;
preScaler = 50000000/ADC_FREQ -1;
rADCCON = (1<<14) | (preScaler<<6) | (chanel<<3); //setup channel
rADCCON|=0x1; //start AD convert
//while(rADCCON & 0x1); //check if Enable_start is low
}
//---------------------------------------end------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -