[mw_shl_code=c,true]//IO配置代码
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //推挽输出,GPIOD应该是作为并行数据线
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_All);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //推挽输出,
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14); //
LCD_RES_SET;
delay_ms(1);
LCD_RES_CLR;
delay_ms(200);
LCD_RES_SET;
delay_ms(200);
//读取ID
lcd_writecmd(0XDA00);
id=lcd_readdata(); //读回0X00
printf("%x\n",id);
lcd_writecmd(0XDB00);
id=lcd_readdata(); //读回0X80
id<<=8;
printf("%x\n",id);
lcd_writecmd(0XDC00);
id|=lcd_readdata();
printf("ID IS:");
printf("%x\n",id);[/mw_shl_code]
[mw_shl_code=c,true]//命令的读写
void lcd_writecmd(u16 reg)
{
LCD_RD_SET;
LCD_RS_CLR;//命令
LCD_CS_CLR; //片选选中
//delay_us(1);
LCD_WR_CLR; //写使能
DATAOUT(reg); //载入数据
reg=reg;
LCD_WR_SET; //写除能
LCD_CS_SET; //取消片选
}
uint16_t lcd_readdata()
{
uint16_t test=0X00;
GPIOC->MODER=0x00;//将端口模式设置为输出
LCD_WR_SET;
LCD_RS_SET;//数据
LCD_CS_CLR; //片选选中
LCD_RD_CLR; //写使能
test=GPIOC->IDR; //载入数据
LCD_RD_SET; //写除能
LCD_CS_SET; //取消片选
GPIOC->MODER=0x55555555;//将端口模式重新设置为输出
return test;
}[/mw_shl_code]
在调试的过程中,发现写入数据时是正确的,但是读取到的ID并不正确,希望大神能够予以解答,OTL.
|