问题已经解决,借用论坛中128*64液晶ST7565程序,可以显示字符和汉字,但是page0是从中间开始,和预期差别很大。

2019-07-20 22:35发布

http://www.openedv.com/posts/list/46417.htm

[mw_shl_code=c,true] WriteToLCD(0x60, 1); // 此液晶屏是从33行开始[/mw_shl_code]
 [mw_shl_code=c,true]int main(void) { delay_init(); //延时 InitLCD(); ClearScreen(); DisplayStr(1,8,"1"); DisplayStr(2,16,"2"); DisplayStr(3,24,"3"); DisplayStr(4,32,"4"); DisplayStr(5,40,"5"); DisplayStr(6,48,"6"); DisplayStr(7,56,"7"); DisplayStr(8,64,"8"); }  [/mw_shl_code] [mw_shl_code=c,true]void InitLCD(void) { GPIO_InitTypeDef GPIO_InitStructure;        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //????PB?????±?? GPIO_InitStructure.GPIO_Pin = LCD_RESET | LCD_SCLK | LCD_CS | LCD_RS |LCD_SDA; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LCD_GPIO, &GPIO_InitStructure); GPIO_SetBits(LCD_GPIO,LCD_RESET | LCD_SCLK | LCD_CS | LCD_RS |LCD_SDA); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //????PB?????±?? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì???? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_SetBits(GPIOC, GPIO_Pin_4); delay_us(40); GPIO_ResetBits(LCD_GPIO, LCD_RESET); delay_us(40); GPIO_SetBits(LCD_GPIO, LCD_RESET); delay_us(40); WriteToLCD(0xE2, 1); //1110 0010 delay_us(40); WriteToLCD(0x2c, 1); //????????1 delay_us(40); WriteToLCD(0x2e, 1); //????????2/ Delay(5); delay_us(40); WriteToLCD(0x2f, 1); //????????3/ delay_us(40); WriteToLCD(0x24, 1); //???÷??±????????è??·??§20??27 WriteToLCD(0x81, 1); //???÷??±??? // WriteToLCD(0x1a, 1); //???÷??±????????????è??·??§0??63 1f WriteToLCD(0x32, 1); WriteToLCD(0xa2, 1); //1/9????±??¨bias?©[/mw_shl_code] [mw_shl_code=c,true][/mw_shl_code] [mw_shl_code=c,true]WriteToLCD(0xc8, 1); //???¨?è???ò?????????? WriteToLCD(0xa0, 1); //???¨?è???ò????×ó???? WriteToLCD(0x60, 1); // 此液晶屏是从33行开始 [/mw_shl_code] [mw_shl_code=c,true]ClearScreen(); WriteToLCD(0xaf, 1); //?????? } /********************************************************************************************************* ** ????????: DisplayStr ** ?????è??: ????×?·??® ** ?? ????: page:??,column:??,text:??±????? ** ?? ????: ?? ** ????±???: ?? ** ?÷?????é: ?? ********************************************************************************************************/ void DisplayStr(unsigned short page,unsigned short column,char *text) { unsigned short i=0,j,k,n; GPIO_ResetBits(LCD_GPIO, LCD_CS); while(text>0x00) { if((text>=0x20)&&(text<=0x7e)) { j=text-0x20; for(n=0;n<2;n++) { LCDAddr(page+n,column); for(k=0;k<8;k++) { WriteToLCD(ascii_table_8x16[j][k+8*n],0); } } i++; column+=8; } else { i++; } } GPIO_SetBits(LCD_GPIO, LCD_CS); } /********************************************************************************************************* ** ????????: WriteToLCD ** ?????è??: 写数据进LCD ** ?? ????: data:写数据 ** flg:标识,0:数据,1:命令 ** ?? ????: ?? ** ????±???: ?? ** ?÷?????é: ?? ********************************************************************************************************/ void WriteToLCD(unsigned char data, unsigned char flg) { unsigned char i; delay_us(40); GPIO_ResetBits(LCD_GPIO, LCD_CS); if(flg) { GPIO_ResetBits(LCD_GPIO, LCD_RS); } else { GPIO_SetBits(LCD_GPIO, LCD_RS); } for(i=0;i<8;i++) { GPIO_ResetBits(LCD_GPIO, LCD_SCLK); if(flg)Delay(2); if(data&0x80) { GPIO_SetBits(LCD_GPIO, LCD_SDA); } else { GPIO_ResetBits(LCD_GPIO, LCD_SDA); } delay_us(300); GPIO_SetBits(LCD_GPIO, LCD_SCLK); delay_us(40); data <<= 1; } delay_us(20); GPIO_SetBits(LCD_GPIO, LCD_SDA); delay_us(20); GPIO_SetBits(LCD_GPIO, LCD_CS); } void ClearScreen(void) { unsigned char i,j; for(i=0;i<9;i++) { GPIO_ResetBits(LCD_GPIO, LCD_CS); WriteToLCD(0xb0+i,1); WriteToLCD(0x10,1); WriteToLCD(0x00,1); for(j=0;j<132;j++) { WriteToLCD(0x00,0); } } } /********************************************************************************************************* ** ????????: LCDAddr ** ?????è??: LCD???·????,???????? ** ?? ????: page:??,column:?? ** ?? ????: ?? ** ????±???: ?? ** ?÷?????é: ?? ********************************************************************************************************/ void LCDAddr(unsigned char page,unsigned char column) { GPIO_ResetBits(LCD_GPIO, LCD_CS); column--; page--; WriteToLCD(0xb0+page,1); WriteToLCD(((column>>4)&0x0f)+0x10,1); //?????·??4?? WriteToLCD(column&0x0f,1); //?????·???4?? } [/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。