驱动程序——TLC7226——基于STM32F103

来源:互联网 发布:公司logo在线制作软件 编辑:程序博客网 时间:2024/06/05 03:11

TLC7226 8 位,5us 四路 DAC,并行输入、单/双电源

时序图:



void IO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA
|RCC_APB2Periph_GPIOB
|RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=Relays1_0|Relays1_1|Relays1_2
|Relays2_0|Relays2_1|Relays2_2
|Relays3_0|Relays3_1|Relays3_2
|Relays4_0|Relays4_1|Relays4_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(Relays_PORT,&GPIO_InitStructure);
GPIO_Init(Beep_PORT,&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=DAC1_A0|DAC1_A1|DAC1_WR|DAC2_A0|DAC2_A1|DAC2_WR;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(DAC_CS_PORT,&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=DAC_D0|DAC_D1|DAC_D2|DAC_D3|DAC_D4|DAC_D5|DAC_D6|DAC_D7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(DAC_DATA_PORT,&GPIO_InitStructure);
//
}


void DAC_Config(unsigned char ch,unsigned char value)
{
if(ch<4)
GPIO_SetBits(DAC_CS_PORT,DAC1_WR);
else
GPIO_SetBits(DAC_CS_PORT,DAC2_WR);

switch(ch)
{
case 0:
GPIO_ResetBits(DAC_CS_PORT,DAC1_A0);
GPIO_ResetBits(DAC_CS_PORT,DAC1_A1);
break;
case 1:
GPIO_SetBits(DAC_CS_PORT,DAC1_A0);
GPIO_ResetBits(DAC_CS_PORT,DAC1_A1);
break;
case 2:
GPIO_ResetBits(DAC_CS_PORT,DAC1_A0);
GPIO_SetBits(DAC_CS_PORT,DAC1_A1);
break;
case 3:
GPIO_SetBits(DAC_CS_PORT,DAC1_A0);
GPIO_SetBits(DAC_CS_PORT,DAC1_A1);
break;
case 4:
GPIO_ResetBits(DAC_CS_PORT,DAC2_A0);
GPIO_ResetBits(DAC_CS_PORT,DAC2_A1);
break;
case 5:
GPIO_SetBits(DAC_CS_PORT,DAC2_A0);
GPIO_ResetBits(DAC_CS_PORT,DAC2_A1);
break;
case 6:
GPIO_ResetBits(DAC_CS_PORT,DAC2_A0);
GPIO_SetBits(DAC_CS_PORT,DAC2_A1);
break;
case 7:
GPIO_SetBits(DAC_CS_PORT,DAC2_A0);
GPIO_SetBits(DAC_CS_PORT,DAC2_A1);
break;
}
Delay(10);
if(ch<4)
GPIO_ResetBits(DAC_CS_PORT,DAC1_WR);
else
GPIO_ResetBits(DAC_CS_PORT,DAC2_WR);
Delay(10);
//for()
GPIO_SetBits(DAC_DATA_PORT, (value & 0xff)<<8); 
GPIO_ResetBits(DAC_DATA_PORT, (~value & 0xff)<<8); 
Delay(10);
if(ch<4)
GPIO_SetBits(DAC_CS_PORT,DAC1_WR);
else
GPIO_SetBits(DAC_CS_PORT,DAC2_WR);
Delay(10);
}



原创粉丝点击