|
发表于 2013-9-27 09:22:48
|
显示全部楼层
- #define ADC1_Port GPIOB
- #define ADC1_SCK_Pin ADC_SCK1
- #define ADC1_SDA_Pin ADC_SDA1
- #define ADC2_Port GPIOB
- #define ADC2_SCK_Pin ADC_SCK2
- #define ADC2_SDA_Pin ADC_SDA2
- #define ADC3_Port GPIOA
- #define ADC3_SCK_Pin ADC_SCK3
- #define ADC3_SDA_Pin ADC_SDA3
- #define ADC4_Port GPIOB
- #define ADC4_SCK_Pin ADC_SCK4
- #define ADC4_SDA_Pin ADC_SDA4
- #define CS5513_1 0x00
- #define CS5513_2 0x01
- #define CS5513_3 0x02
- #define CS5513_4 0x03
- /** @defgroup Private_TypesDefinitions
- * @{
- */
- typedef void (*pFunctionWriteBit)(void);
- typedef uint8_t (*pFunctionReadBit)(void);
- typedef enum SWITCHTAG {OFF,ON} SWITCH;
- /** @defgroup Private_Defines
- * @{
- */
- /** @defgroup Private_Macros
- * @{
- */
- /** @defgroup Private_Variables
- * @{
- */
-
- SWITCH ADC_SAMPLE_SWITCH[4] = {OFF,OFF,OFF,OFF};
- uint32_t ADC_SAMPLE_COUNT[4] = { 0, 0, 0, 0};
- /** @defgroup Private_FunctionPrototypes
- * @{
- */
- /** @defgroup Private_Functions
- * @{
- */
- void SetADC_SCK1(void) {GPIO_SetBits(ADC1_Port,ADC_SCK1);}
- void SetADC_SCK2(void) {GPIO_SetBits(ADC2_Port,ADC_SCK2);}
- void SetADC_SCK3(void) {GPIO_SetBits(ADC3_Port,ADC_SCK3);}
- void SetADC_SCK4(void) {GPIO_SetBits(ADC4_Port,ADC_SCK4);}
- void ResetADC_SCK1(void){GPIO_ResetBits(ADC1_Port,ADC_SCK1);}
- void ResetADC_SCK2(void){GPIO_ResetBits(ADC2_Port,ADC_SCK2);}
- void ResetADC_SCK3(void){GPIO_ResetBits(ADC3_Port,ADC_SCK3);}
- void ResetADC_SCK4(void){GPIO_ResetBits(ADC4_Port,ADC_SCK4);}
- uint8_t ReadADC_SDA1(void){return GPIO_ReadInputDataBit(ADC1_Port,ADC1_SDA_Pin);}
- uint8_t ReadADC_SDA2(void){return GPIO_ReadInputDataBit(ADC2_Port,ADC2_SDA_Pin);}
- uint8_t ReadADC_SDA3(void){return GPIO_ReadInputDataBit(ADC3_Port,ADC3_SDA_Pin);}
- uint8_t ReadADC_SDA4(void){return GPIO_ReadInputDataBit(ADC4_Port,ADC4_SDA_Pin);}
-
- /* ·´Ïò */
- const pFunctionWriteBit SetSck[4] = {
- ResetADC_SCK1,
- ResetADC_SCK2,
- ResetADC_SCK3,
- ResetADC_SCK4
- };
- /* ·´Ïò */
- const pFunctionWriteBit ResetSck[4] = {
- SetADC_SCK1,
- SetADC_SCK2,
- SetADC_SCK3,
- SetADC_SCK4
- };
- const pFunctionReadBit ReadSda[4] = {
- ReadADC_SDA1,
- ReadADC_SDA2,
- ReadADC_SDA3,
- ReadADC_SDA4
- };
-
- void EnableADCPinExitInterrupt(uint8_t channel)
- {
-
- }
- void DisableADCPinExitInterrupt(uint8_t channel)
- {
-
- }
- ERRORCODE EnableSample(uint8_t channel)
- {
- /* reset sclk */
- ResetSck[channel]();
- //SetSck[channel]();
- /* reset count */
- ADC_SAMPLE_COUNT[channel] = 0;
- /* enable exit sda high to low interrupt */
-
- EnableADCPinExitInterrupt(channel);
- ADC_SAMPLE_SWITCH[channel] = ON;
-
- /* if count > 5 the data is valid */
- return SUCCEED;
- }
- ERRORCODE DisableSample(uint8_t channel)
- {
- /* set sck */
- SetSck[channel]();
- //ResetSck[channel]();
- /* reset count */
- ADC_SAMPLE_COUNT[channel] = 0xFFFFFFFF;
- /* disable exit sda high to low interrupt */
- //DISABLE_EXIT;
- DisableADCPinExitInterrupt(channel);
- ADC_SAMPLE_SWITCH[channel] = OFF;
-
- /* */
- return SUCCEED;
- }
- ERRORCODE GetADCSampleValue(uint8_t channel,uint32_t *value)
- {
- uint8_t count = 0;
- *value = 0;
- for (count = 0;count < 24;count++)
- {
- /* set sck high */
- SetSck[channel]();
- SetSck[channel]();
- SetSck[channel]();
- SetSck[channel]();
- /* read sda */
- *value |= (uint32_t)ReadSda[channel]();
- (*value) <<= 1;
- SetSck[channel]();
- SetSck[channel]();
- SetSck[channel]();
- SetSck[channel]();
- SetSck[channel]();
-
- /* reset sck low */
- ResetSck[channel]();
- ResetSck[channel]();
- ResetSck[channel]();
- ResetSck[channel]();
- // ResetSck[channel]();/* Just for Delay */
- // ResetSck[channel]();
- }
- (*value) >>= 1;
- //SetSck[channel]();
-
- return SUCCEED;
- }
- 小思路···
复制代码 |
|