#include "TSL1401.h"函數
void CCDInitConfiguration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=SI_Pin;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(SI_Port,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=CLK_Pin;
GPIO_Init(CLK_Port,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=AO_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_Init(AO_Port,&GPIO_InitStructure);
ADC_Configuration();
}學習
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode=ADC_Mode_Independent;//ADC2/ADC2工做在獨立模式
ADC_InitStructure.ADC_ScanConvMode=DISABLE;//工做在單通道模式下
ADC_InitStructure.ADC_ContinuousConvMode=ENABLE;//工做在連續模式下
ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None;//轉換由軟件觸發
ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right;//右對齊模式
ADC_InitStructure.ADC_NbrOfChannel=1;//順序進行規則轉換的 ADC 通道的數目
ADC_Init(ADC2,&ADC_InitStructure);
ADC_RegularChannelConfig(ADC2,A0_ADCChannel,1,ADC_SampleTime_239Cycles5);
ADC_Cmd(ADC2,ENABLE);
ADC_ResetCalibration(ADC2);//從新指定ADC的校準寄存器
while(ADC_GetResetCalibrationStatus(ADC2));//獲取ADC重置校準寄存器的狀態ui
ADC_StartCalibration(ADC2);//開始指定 ADC 的校準狀態
while(ADC_GetCalibrationStatus(ADC2));//獲取指定 ADC 的校準程序 es5
ADC_SoftwareStartConvCmd(ADC2,ENABLE);//使能或者失能指定的 ADC 的軟件轉換啓動功能
}
void StartIntergration(void)
{
unsigned char i;
SI_SetVal;
SamplingDelay();
CLK_SetVal;
SamplingDelay();
SI_ClrVal;
SamplingDelay();
CLK_ClrVal;
for(i=0; i<127; i++)
{
SamplingDelay();
SamplingDelay();
CLK_SetVal;
SamplingDelay();
SamplingDelay();
CLK_ClrVal;
}
SamplingDelay();
SamplingDelay();
CLK_SetVal;
SamplingDelay();
SamplingDelay();
CLK_ClrVal;
}
void ImageCapture(unsigned char * ImageData)
{
unsigned char i;
extern u8 AtemP ;
SI_SetVal;
SamplingDelay();
CLK_SetVal;
SamplingDelay();
SI_ClrVal;
SamplingDelay();
for(i=0;i<255;i++)
{
SamplingDelay();
}
ADC_SoftwareStartConvCmd(ADC2,ENABLE);
while(!ADC_GetFlagStatus(ADC2,ADC_FLAG_EOC));
*ImageData=ADC_GetConversionValue(ADC2)>>4;
ImageData++;
CLK_ClrVal;
for(i=0;i<127;i++)
{
SamplingDelay();
SamplingDelay();
CLK_SetVal;
SamplingDelay();
SamplingDelay();
ADC_SoftwareStartConvCmd(ADC2,ENABLE);
while(!ADC_GetFlagStatus(ADC2,ADC_FLAG_EOC));
*ImageData=ADC_GetConversionValue(ADC2)>>4;
ImageData++;
CLK_ClrVal;
}
SamplingDelay();
SamplingDelay();
CLK_SetVal;
SamplingDelay();
SamplingDelay();
CLK_ClrVal;
}
void SamplingDelay(void)
{
volatile uint8_t i ;
for(i=0;i<1;i++)
{
__NOP();
__NOP();
}
}ci
.h文件源碼以下:開發
#ifndef _TSL1401_H_
#define _TSL1401_H_get
#include "stm32f10x_gpio.h"
#include "stm32f10x_adc.h"源碼
//能夠根據本身的須要修改響應的引腳it
#define SI_Pin GPIO_Pin_0
#define SI_Port GPIOCio
#define CLK_Pin GPIO_Pin_1
#define CLK_Port GPIOC
#define AO_Pin GPIO_Pin_2
#define AO_Port GPIOC
#define A0_ADCChannel ADC_Channel_12
#define SI_SetVal GPIO_SetBits(SI_Port,SI_Pin)
#define SI_ClrVal GPIO_ResetBits(SI_Port,SI_Pin)
#define CLK_SetVal GPIO_SetBits(CLK_Port,CLK_Pin)
#define CLK_ClrVal GPIO_ResetBits(CLK_Port,CLK_Pin)
void CCDInitConfiguration(void);
void StartIntergration(void);
void ADC_Configuration(void);
void ImageCapture(unsigned char * ImageData) ;
void SendImageData(unsigned char * ImageData);
void SamplingDelay(void);
#endif
使用過程當中有任何問題能夠一塊兒交流學習。
聲明:本次分享源代碼來源於藍宙電子的源驅動代碼,只用做交流學習,不用作商業用途。