本帖最后由 xyz549040622 于 2019-12-21 23:18 编辑
#include "LPC11xx.h"
#define GAIN1 (1<<0)//P3.0
#define GAIN0 (1<<11)//P0.11
#define SPEED (1<<11)//P2.11
#define SCLK (1<<6)//P0.6
#define DRDY (1<<8)//P0.8
#define PDWN (1<<5)//P3.5
#define TEMP (1<<11)//P1.11
#define A0 (1<<4)//P3.4
#define TEMP_L (LPC_GPIO1->DATA&=~(1<<11))
#define TEMP_H (LPC_GPIO1->DATA|=(1<<11))
#define PDWN_L (LPC_GPIO3->DATA &= ~PDWN)
#define PDWN_H (LPC_GPIO3->DATA |= PDWN)
#define SCLK_L (LPC_GPIO0->DATA &= ~SCLK)
#define SCLK_H (LPC_GPIO0->DATA |= SCLK)
#define SPEED_L (LPC_GPIO2->DATA &= ~SPEED)
#define SPEED_H (LPC_GPIO2->DATA |= SPEED)
#define A0_L (LPC_GPIO3->DATA &= ~A0)
#define A0_H (LPC_GPIO3->DATA |= A0)
#define GAIN1_L (LPC_GPIO3->DATA &= ~GAIN1)
#define GAIN1_H (LPC_GPIO3->DATA |= GAIN1)
#define GAIN0_L (LPC_GPIO0->DATA &= ~GAIN0)
#define GAIN0_H (LPC_GPIO0->DATA |= GAIN0)
#define uchar unsigned char
#define GPIO_BASE (0x50000000ul)
#define GPIO0MASKED_ACCESS(bit) (*(volatile unsigned long*)(GPIO_BASE+0x00000+(bit))) //gpio0---0x0000
// sfr P0 = 0x0000;
unsigned char TempData[3];
float Voltage;
unsigned long Ads1232Read(void);
unsigned char WeightCounter;
extern void Delay1ms(void); //ÑÓʱ1ms
extern unsigned char free[];
uint8_t bad1[]="getting datas...";
uint8_t bad2[]="stacked here ...";
extern void UARTSend(uint8_t *BufferPtr, uint32_t Length);
void Delay_Us(unsigned char time)
{
unsigned int i;
i=50*time;
while(i>0){i--;}
}
void Ads1232InitA0(void)
{
uchar i;
PDWN_L; //POWERDOWN
SCLK_L;
SPEED_H; //0--10HZ 1--80HZ
TEMP_L ;
GAIN0_L; // PGA 0 0 1
GAIN1_L; // 0 1 2
// // 1 0 64
// 1 1 128
A0_H; //ͨµÀ2
Delay_Us(50);
PDWN_H; //Éϵç
for(i=0;i<26;i++)
{
SCLK_H;
Delay_Us(1);
SCLK_L;
}
}
/**********************************************************************
Ãû³Æ£º
¹¦ÄÜ£º
ÃèÊö£º
Ð޸ģº
***********************************************************************/
void ADCDeal(void)
{
// unsigned long X[9];
unsigned char TempData1[3];
unsigned long Y;
unsigned char tmp;
unsigned long Voltag;
// unsigned char i;
// for(i=0;i<8;i++)
// {
Y=Ads1232Read(); //Delay_Us(10);
// }
// Y= X[5]+X[6]+X[7]+X[4];
// Y=(Y/4);
Voltage=(float)(Y*5.0/(0xffffff-1));
Voltag=Voltage*100000000;
free[190]=Voltag/100000000+0x30;
free[191]='.';
free[192]=(Voltag/10000000)%10+0x30;
free[193]=(Voltag/1000000)%10+0x30;
free[194]=(Voltag/100000)%10+0x30;
free[195]=(Voltag/10000)%10+0x30;
free[196]=(Voltag/1000)%10+0x30;
free[197]=(Voltag/100)%10+0x30;
free[198]=(Voltag/10)%10+0x30;
free[199]=(Voltag%10)+0x30; //ge
TempData[0]=(unsigned char)((Y)&0x000000ff);
TempData[1]=(unsigned char )((Y>>8) &0x000000ff);
TempData[2]=(unsigned char )((Y>>16)&0x000000ff);
TempData1[0]=TempData[2];
TempData1[1]=TempData[1];
TempData1[2]=TempData[0];
UARTSend( (uint8_t *)TempData1, 3 );
free[76]=((TempData[2]>>7)+0x30);
tmp=(TempData[2]>>6);
tmp=(tmp&0x01);
free[77]=(tmp+0x30);
tmp=(TempData[2]>>5);
tmp=(tmp&0x01);
free[78]=(tmp+0x30);
tmp=(TempData[2]>>4);
tmp=(tmp&0x01);
free[79]=(tmp+0x30);
tmp=(TempData[2]>>3);
tmp=(tmp&0x01);
free[80]=(tmp+0x30);
tmp=(TempData[2]>>2);
tmp=(tmp&0x01);
free[81]=(tmp+0x30);
tmp=(TempData[2]>>1);
tmp=(tmp&0x01);
free[82]=(tmp+0x30);
tmp=(TempData[2]&0x01);
free[83]=(tmp+0x30);
free[85]=((TempData[1]>>7)+0x30);
tmp=(TempData[1]>>6);
tmp=(tmp&0x01);
free[86]=(tmp+0x30);
tmp=(TempData[1]>>5);
tmp=(tmp&0x01);
free[87]=(tmp+0x30);
tmp=(TempData[1]>>4);
tmp=(tmp&0x01);
free[88]=(tmp+0x30);
tmp=(TempData[1]>>3);
tmp=(tmp&0x01);
free[89]=(tmp+0x30);
tmp=(TempData[1]>>2);
tmp=(tmp&0x01);
free[90]=(tmp+0x30);
tmp=(TempData[1]>>1);
tmp=(tmp&0x01);
free[91]=(tmp+0x30);
tmp=(TempData[1]&0x01);
free[92]=(tmp+0x30);
free[94]=((TempData[0]>>7)+0x30);
tmp=(TempData[0]>>6);
tmp=(tmp&0x01);
free[95]=(tmp+0x30);
tmp=(TempData[0]>>5);
tmp=(tmp&0x01);
free[96]=(tmp+0x30);
tmp=(TempData[0]>>4);
tmp=(tmp&0x01);
free[97]=(tmp+0x30);
tmp=(TempData[0]>>3);
tmp=(tmp&0x01);
free[98]=(tmp+0x30);
tmp=(TempData[0]>>2);
tmp=(tmp&0x01);
free[99]=(tmp+0x30);
tmp=(TempData[0]>>1);
tmp=(tmp&0x01);
free[100]=(tmp+0x30);
tmp=(TempData[0]&0x01);
free[101]=(tmp+0x30);
}
/**********************************************************************
Ãû³Æ£º
¹¦ÄÜ£º
ÃèÊö£º
Ð޸ģº
***********************************************************************/
unsigned long Ads1232Read(void)
{
unsigned char i;
unsigned long Ads_ReadData;
while(GPIO0MASKED_ACCESS(1<<10));//==(1<<8));//DOUT ¸ßµçƽ£¬µÈ´ý£¬Ò»Ö±µ½Êý¾ÝÓÐЧºó±äΪµÍµçƽ
for(i = 0; i < 24; i++)
{
SCLK_H; //ÉÏÉýÑضÁÈ¡Êý¾Ý
Ads_ReadData<<=1; //ÏÈÓÒÒÆһ룬ÔÚ¶Ô×îµÍλÉèÖÃ
if(GPIO0MASKED_ACCESS(1<<10))//==(1<<8)) //¶Á³öµÄÊý¾ÝΪ1
{
Ads_ReadData |= 0x01;
}
else ; //¶Á³öµÄÊý¾ÝΪ0
SCLK_L;
Delay_Us(1);
}
SCLK_H;
Delay_Us(1);
SCLK_L;
Delay_Us(1);
SCLK_H;
Delay_Us(1);
SCLK_L; //Ïû³ýÀÛ¼ÆÎó²î
Ads_ReadData&=0x00ffffff;
// UARTSend(bad1, 17);
return(Ads_ReadData);
}
|