ставил задержки аж в 10 мсек - бестолку
CODE
void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_Dat)
{
LCD_RD = 1;
LCD_CS = 0;
LCD_RS = 0;
GPIOC->ODR = (GPIOC->ODR&0xff00)|(LCD_Reg&0x00ff);
GPIOB->ODR = (GPIOB->ODR&0x00ff)|(LCD_Reg&0xff00);
LCD_WR = 0;
LCD_WR = 1;
LCD_RS = 1;
GPIOC->ODR = (GPIOC->ODR&0xff00)|(LCD_Dat&0x00ff);
GPIOB->ODR = (GPIOB->ODR&0x00ff)|(LCD_Dat&0xff00);
LCD_WR = 0;
LCD_WR = 1;
LCD_CS = 1;
}
uint16_t LCD_ReadReg(uint16_t LCD_Reg)
{
uint16_t temp;
LCD_RD = 1;
LCD_CS = 0;
LCD_RS = 0;
GPIOC->ODR = (GPIOC->ODR&0xff00)|(LCD_Reg&0x00ff);
GPIOB->ODR = (GPIOB->ODR&0x00ff)|(LCD_Reg&0xff00);
LCD_WR = 0;
LCD_WR = 1;
LCD_RS = 1;
GPIOB->CRH = (GPIOB->CRH & 0x00000000) | 0x44444444; //½«¶Ë¿Ú¸ß8λÅäÖóÉÊäÈë
GPIOC->CRL = (GPIOC->CRL & 0x00000000) | 0x44444444; //½«¶Ë¿ÚµÍ8λÅäÖóÉÊäÈë
LCD_RD = 0;
LCD_Delay(1);
temp = ((GPIOB->IDR&0xff00)|(GPIOC->IDR&0x00ff)); //¶ÁÈ¡Êý¾Ý(¶Á¼Ä´æÆ÷ʱ,²¢²»ÐèÒª¶Á2´Î)
LCD_CS = 1;
GPIOB->CRH = (GPIOB->CRH & 0x00000000) | 0x33333333; //ÊͷŶ˿ڸß8λΪÊä³ö
GPIOC->CRL = (GPIOC->CRL & 0x00000000) | 0x33333333; //ÊͷŶ˿ڵÍ8λΪÊä³ö
LCD_RD = 1;
return temp;
}
Инициализация
Код
void LCD_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC,ENABLE);
/* ÅäÖÃÊý¾ÝIO Á¬½Óµ½GPIOB *********************/
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; // Êä³öIO¿Ú×î´ó×îËÙΪ50MHZ
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* ÅäÖÿØÖÆIO Á¬½Óµ½PD12.PD13.PD14.PD15 *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3
| GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // ÍÆÍìÊä³ö·½Ê½
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Êä³öIO¿Ú×î´ó×îËÙΪ50MHZ
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // ÍÆÍìÊä³ö·½Ê½
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Êä³öIO¿Ú×î´ó×îËÙΪ50MHZ
GPIO_Init(GPIOC, &GPIO_InitStructure);
LCD_CS=1;
LCD_RD=1;
LCD_RS=1;
LCD_WR=1;
}