新手上路
- 积分
- 25
- 金钱
- 25
- 注册时间
- 2016-7-7
- 在线时间
- 8 小时
|
新人搞12864的程序,采用串行方式,一直调都显示不出来,求帮帮忙啊~~
#define RW_H GPIOB->BSRR=GPIO_Pin_4 ; //SID
#define RW_L GPIOB->BRR=GPIO_Pin_4 ;
#define EN_H GPIOC->BSRR=GPIO_Pin_12 ;//SCLK
#define EN_L GPIOC->BRR=GPIO_Pin_12 ;
#define RS_H GPIOB->BSRR=GPIO_Pin_6 ;//CS
#define RS_L GPIOB->BRR=GPIO_Pin_6 ;
GPIO_InitTypeDef GPIOStru;
void IOInitOut(void) //I/O的配置
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
GPIOStru.GPIO_Mode = GPIO_Mode_Out_PP
GPIOStru.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_6;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIOStru.GPIO_Mode = GPIO_Mode_Out_PP;
GPIOStru.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void Lcd_Init(void) //初始化程序
{
Write_Char(0,0x30);
delay_ms(5);
Write_Char(0,0x02);
delay_ms(5);
Write_Char(0,0x0c);
delay_ms(5);
Write_Char(0,0x01);
delay_ms(5);
Write_Char(0,0x06);
delay_ms(5);
Write_Char(0,0x1C);
}
void LCD_Set_XY(u8 x,u8 y) //位置的显示
{
u8 address;
switch(x)
{
case 1:
address=0x80+y;
break;
case 2:
address=0x90+y;
break;
case 3:
address=0x88+y;
break;
case 4:
address=0x98+y;
break;
default:
address=0x80+y;
break;
}
Write_Char(0, address);
}
void DisStr(u8 hang ,u8 lie, u8 *s) //显示的数组
{
LCD_Set_XY( hang , lie );
while(*s != '\0')
{
Write_Char( 1, *s );
s++;
delay_ms(5);
}
}
void Write_Char(u8 start, u8 ddata) //选择写命令还是写数据
{
unsigned char i;
u8 start_data,Hdata,Ldata;
RS_H;
if(start==0)
{
for(i=0;i<5;i++)
{ EN_L; //sclk
EN_H;
RW_H ;//SID
}
for(i=0;i<3;i++)
{
EN_L; //sclk
EN_H;
RW_L ;
}
Hdata=ddata&0xf0; //取高4位
Ldata=(ddata<<4)&0xf0; //取低4位
delay_ms(2);
Send_Byte(Hdata); //发送高8位
delay_ms(2);
Send_Byte(Ldata); //发送低8位
delay_ms(2);
}
else
{
for(i=0;i<5;i++)
{ EN_L; //sclk
EN_H;
RW_H ;//SID
}
EN_L; //sclk
EN_H;
RW_L ;
EN_L ; //sclk
EN_H ;
RW_H ;
EN_L; //sclk
EN_H;
RW_L;
Hdata=ddata&0xf0;
Ldata=(ddata<<4)&0xf0;
delay_ms(10);
Send_Byte(Hdata);
delay_ms(5);
Send_Byte(Ldata);
delay_ms(5);
}
}
void Send_Byte(unsigned char bbyte)
{
u8 i,k,w;
k=2;
RS_H ;
while(k--)
{
for(i=0;i<4;i++)
{
w=bbyte&0x80;
if(w==0x80)
{
EN_L; //sclk
EN_H;
RW_H;
}
else
EN_L; //sclk
EN_H;
RW_L ;
bbyte <<= 1;
}
for(i=0;i<4;i++)
{
EN_L ; //sclk
EN_H ;
RW_L ;
}
RS_L ;
unsigned char table []="adf3dgv";
int main(void)
{
delay_ms(8);
Lcd_Init();
DisStr(1 ,1, table) ;
while(1);
}
|
-
12864的时序图
|