/********************************************************************************/
/* @file ad8370.c */
/* @version V1.00 */
/* $author: yuanxihua@21cn.com */
/* $Date: 2023/09/09 02:54 $ */
/* @brief SWM181CBT6 Series AD8370 Driver Sample Code */
/* */
/* @note */
/* Copyright (C) 2010-2023 PM9GZY Technology Corp. All rights reserved. */
/* */
/********************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/*
________________________________________________
| SWM181CBT6 AD8370 |
| |
| PB5 PC2 PD1 PC5 ----> DATA |
| PB6 PC3 PD2 PC6 ----> CLCK |
| PB7 PC4 PD3 PC7 ----> LTCH |
|_______________________________________________|
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
typedef struct {GPIO_TypeDef *port;uint32_t pin;}pin_t;
pin_t data[4]={{GPIOB, PIN5},{GPIOC, PIN2},{GPIOD, PIN1},{GPIOC, PIN5}};
pin_t clck[4]={{GPIOB, PIN6},{GPIOC, PIN3},{GPIOD, PIN2},{GPIOC, PIN6}};
pin_t ltch[4]={{GPIOB, PIN7},{GPIOC, PIN4},{GPIOD, PIN3},{GPIOC, PIN7}};
#define AD8730_delay 2
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void AD8370_Set_value(uint8_t chn,uint8_t pga)
{
if(chn>3){return;}
// printf("\n\rDATA:PORT=%x PIN=%x ",(int)data[chn].port,(int)data[chn].pin);
// printf("\n\rCLCK:PORT=%x PIN=%x ",(int)clck[chn].port,(int)clck[chn].pin);
// printf("\n\rLTCH:PORT=%x PIN=%x ",(int)ltch[chn].port,(int)ltch[chn].pin);
GPIO_ClrBit(clck[chn].port, clck[chn].pin);// CLCK = LOW
GPIO_SetBit(ltch[chn].port, ltch[chn].pin);// LTCH = HIGH
GPIO_ClrBit(data[chn].port, data[chn].pin);// DATA = LOW
delay_ms(1);
GPIO_ClrBit(ltch[chn].port, ltch[chn].pin);// LTCH = LOW
delay_us(AD8730_delay);
for(int i=0;i<8;i++)
{
if(pga&0x80){GPIO_SetBit(data[chn].port, data[chn].pin);}// DATA = HIGH
else {GPIO_ClrBit(data[chn].port, data[chn].pin);}// DATA = LOW
delay_us(AD8730_delay);
GPIO_SetBit(clck[chn].port, clck[chn].pin); // CLCK = HIGH
delay_us(AD8730_delay);
GPIO_ClrBit(clck[chn].port, clck[chn].pin); // CLCK = LOW
pga<<=1;
}
GPIO_ClrBit(data[chn].port, data[chn].pin);// DATA = LOW
delay_us(AD8730_delay);
GPIO_SetBit(ltch[chn].port, ltch[chn].pin);// LTCH = HIGH
}
//代码完毕
|