|
硬件的连接:
PE8~PE15对应的是DS12C887的AD0~AD7,PE7~R/W,PB1~DS,PB10~AS,PB11~CS,PB0~IRO,另外MOT~GND VCC~5V,reset ~5v
初始化:
ds12c887_init();
ds12c887_writereg(0x0a,0x2f);//启动887的震荡
ds12c887_writereg(0x0B,0x16);//0001 0110 选更新中断+二进制格式,每秒产生一次中断
我在WHILE里面看看到底驱动成功没有:TAB_887A[0]=ds12c887_readreg(0x02);,一直是0XFF,
下面是子程序函数:
void ds12c887_setoutput(uint16_t i)
{
/*
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
*/
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15 ;
if(i)
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
}
else
{
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//GPIO_Mode_Out_PP;GPIO_Mode_IN_FLOATING
}
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void ds12c887_delay(uint32_t us);
/*
void ds12c887_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ds12c887_setoutput(0);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
CS_DESELECT();
AS_DISABLE();
WR_DISABLE();
RD_DISABLE();
ds12c887_delay(100000l);
}
*/
void ds12c887_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ds12c887_setoutput(0);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//ds12c887Z中断引脚说明,注意由于是漏极输出,所以必须上拉电阻输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
*/
CS_DESELECT();
AS_DISABLE();
WR_DISABLE();
RD_DISABLE();
ds12c887_delay(100000l);
}
void ds12c887_delay(uint32_t us)
{
uint32_t i,j;
for(j=0;j<us;j++)
for(i=0;i<72;i++);
}
void ds12c887_writeadd(uint8_t add)
{
u16 RTC_DATA_OUT = 0x0000 ;
u16 RTC_DATA_OUT1 = 0x0000;
ds12c887_setoutput(1);
//DAT_OUTPUT(add);
RTC_DATA_OUT = GPIO_ReadOutputData(GPIOE);
RTC_DATA_OUT &=0x00FF;
RTC_DATA_OUT1 = (u16)(add)<<8;
RTC_DATA_OUT |= RTC_DATA_OUT1;
GPIO_Write(GPIOE, RTC_DATA_OUT);
ds12c887_delay(10);
AS_ENABLE();
ds12c887_delay(10);
AS_DISABLE();
ds12c887_delay(10);
ds12c887_setoutput(0);
}
void ds12c887_writedat(uint8_t dat)
{
u16 RTC_DATA_OUT = 0x0000 ;
u16 RTC_DATA_OUT1 = 0x0000;
ds12c887_setoutput(1);
//DAT_OUTPUT(dat);
RTC_DATA_OUT = GPIO_ReadOutputData(GPIOE);
RTC_DATA_OUT &=0x00FF;
RTC_DATA_OUT1 = (u16)(dat)<<8;
RTC_DATA_OUT |= RTC_DATA_OUT1;
GPIO_Write(GPIOE, RTC_DATA_OUT);
ds12c887_delay(10);
WR_ENABLE();
ds12c887_delay(10);
WR_DISABLE();
ds12c887_delay(10);
ds12c887_setoutput(0);
}
uint8_t ds12c887_readdat(void)
{
uint8_t dat;
ds12c887_setoutput(0);
ds12c887_delay(10);
RD_ENABLE();
ds12c887_delay(10);
//dat = DAT_INPUT();
dat=(u8)((GPIOE->IDR)>>8);
RD_DISABLE();
ds12c887_delay(10);
return dat;
}
void ds12c887_writereg(uint8_t add,uint8_t dat)
{
CS_SELECT();
ds12c887_delay(10);
ds12c887_writeadd(add);
ds12c887_writedat(dat);
CS_DESELECT();
ds12c887_delay(10);
}
uint8_t ds12c887_readreg(uint8_t add)
{
uint8_t dat;
CS_SELECT();
ds12c887_delay(10);
ds12c887_writeadd(add);
dat = ds12c887_readdat();
CS_DESELECT();
ds12c887_delay(10);
return dat;
}
前辈们帮帮小弟,看看到底哪个环节出问题了,应该是我这个驱动程序的问题,硬件四块都试过了都不行,哎在线等,帮忙呀,江湖救急,好几天了
|
|