/*-----------------------------------------
硬件接线
CS0<-CLKX0
WR0<-CLKR0
RD0<-FSX0
INTR0->FSR0
----------------------------------------*/
#ifndef _MCBSP_ADC0809_h_
#define _MCBSP_ADC0809_h_
#include "mcbsp54.h"
void Delay_MS(unsigned int ms)//5ms
{
unsigned int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<80;j++) { ; }
}
}
//
int ADC_V()//0XBFFF地址线直接硬件配置
{
int intr1 = 1;
int DATA = 0, *P;
MCBSP_RX_RESET(0);
MCBSP_TX_RESET(0);//McBSP working in restoration
MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b00);// cs=0 wr=0 rd=0
Delay_MS(4);
intr1 = 1 ;
MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b00); //cs=0 wr=0 rd=0
Delay_MS(4);
MCBSP_SUBREG_BITWRITE(0,PCR_SUBADDR,CLKRP,CLKRP_SZ,1);
//MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b01);//cs=0 wr=1 rd=0
Delay_MS(4);
while(1==intr1)//Waiting for conversion to complete
{
MCBSP_SUBREG_BITREAD(0,PCR_SUBADDR,FSRP,1);
intr1=FSRP;
}
Delay_MS(4);
MCBSP_SUBREG_BITWRITE(0,PCR_SUBADDR,CLKXP,CLKXP_SZ,1);
//MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b03); //cs=1 wr=1 rd=0
Delay_MS(4);
MCBSP_SUBREG_BITWRITE(0,PCR_SUBADDR,CLKXP,CLKXP_SZ,0);
//MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b01); //cs=0 wr=1 rd=0
P=(int*)0xbFFF;
DATA = *P ;
DATA = DATA & 0X00FF ;
Delay_MS(30);
MCBSP_SUBREG_BITWRITE(0,PCR_SUBADDR,FSXP,FSXP_SZ,1);
//MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b09); //cs=0 wr=1 rd=1
Delay_MS(4);
MCBSP_SUBREG_BITWRITE(0,PCR_SUBADDR,CLKXP,CLKXP_SZ,1);
//MCBSP_SUBREG_WRITE(0,PCR_SUBADDR,0x3b0b); //cs=1 wr=1 rd=1
Delay_MS(4);
return DATA;
}
int ADC_I()//7FFF,地址线直接硬件配置
{
int intr1 = 1;
int DATA = 0, *P;
MCBSP_RX_RESET(1);
MCBSP_TX_RESET(1);//McBSP working in restoration
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b00);//stop ADC cs=0 wr=0 rd=0
Delay_MS(4);
intr1 = 1 ;
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b00); //cs=0 wr=0 rd=0
Delay_MS(4);
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b01);//cs=0 wr=1 rd=0
Delay_MS(4);
while(1==intr1)//Waiting for conversion to complete
{
MCBSP_SUBREG_BITREAD(1,PCR_SUBADDR,FSRP,1);
intr1=FSRP;
}
Delay_MS(4);
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b03); //cs=1 wr=1 rd=0
Delay_MS(4);
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b01); //cs=0 wr=1 rd=0
P=(int*)0x7FFF;
DATA = *P ;
DATA = DATA & 0X00FF ;
Delay_MS(30);
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b09); //cs=0 wr=1 rd=1
Delay_MS(4);
MCBSP_SUBREG_WRITE(1,PCR_SUBADDR,0x3b0b); //cs=1 wr=1 rd=1
Delay_MS(4);
return DATA;
}
|