怎么用带字库的12864显示自造的汉字,以及怎么显示图片?
[复制链接]
怎么用带字库的12864显示自造的汉字,以及怎么显示图片?
怎么显示自造的汉字我不清楚,显示图片那个方法我根据手册看懂了,可是写出的代码下载显示出12864花屏!!!求高手指导!!!搞了老半天仍然没有进展 ,求指导啊!
以下是我写的代码:
#ifndef __12864_H__ #define __12864_H__
#include "stm32f10x.h" #include "stdio.h"
#define LCD_SID GPIO_Pin_4 #define LCD_CLK GPIO_Pin_5 #define uchar unsigned char #define uint unsigned int
#define com 0 #define dat 1
void delayUs(unsigned char us); //void softspi_init(void); void LCD12864_Byte(unsigned char byte); void LCD12864_Write(unsigned char dat_com,unsigned char byt); void LCD12864_Init(void); void LCD12864_Clear(void); void LCD12864_SetAddr(unsigned char x,unsigned char y); void LCD12864_Write_Word(unsigned char *p); void LCD12864_Write_Str(unsigned char x,unsigned char y,char *buff); void LCD12864_Write_int(unsigned char x,unsigned char y,int buff);
#endif
源程序:
#include "12864.h" char clear[] = {" "}; //写0清除原 ROM里面的内容 void delayUs(unsigned char us)//delay us { unsigned char uscnt; uscnt=us>>1; /*12MHz频率*/ while(--uscnt); }
/*********************************************************************
向12864写入一个字节
**********************************************************************/
void LCD12864_Byte(unsigned char byte) //LCD寫字節指令 { unsigned char i; for(i=0;i<8;i++) { GPIO_WriteBit(GPIOD, LCD_CLK, (BitAction)0x00); // lcd_clk=0; delayUs(50); if(byte&0x80) { GPIO_WriteBit(GPIOD, LCD_SID, (BitAction)0x01); delayUs(50); } else { GPIO_WriteBit(GPIOD, LCD_SID, (BitAction)0x00); // lcd_rw=CY; delayUs(50); } byte<<=1; GPIO_WriteBit(GPIOD, LCD_CLK, (BitAction)0x01); // lcd_clk=1; delayUs(50); } }
/*************************************************************************lCD寫入數據子程式*****************************/ void LCD12864_Write(unsigned char dat_com,unsigned char byt) //lCD寫入數據子程式 { unsigned char temp; delayUs(3); if(dat_com==0) //如果為0,則表示寫入指令 temp=0xf8; //11111,RS(0),RW(0),0 else //為1,寫入數據 temp=0xfa; //11111,RS(1),RW(0),0 LCD12864_Byte(temp); //將首位寫入lCD LCD12864_Byte(byt&0xf0); //寫入高四位 LCD12864_Byte(byt<<4); //寫入低四位 }
/**********************************************************************lCD初始化******************************/ void LCD12864_Init(void) //lCD初始化 { u16 i;
//初始化相应引脚和对应时钟 GPIO_InitTypeDef GPIO_InitStructure; //使能由APB2时钟控制的外设中的PE端口 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD, ENABLE); /*LCD12864对应IO,PE14,PE15*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4| GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure);
LCD12864_Write(com,0x30); //基本指令功能. delayUs(220); LCD12864_Write(com,0x0c); //打開顯示.關閉光標,關閉反白 delayUs(250); LCD12864_Write(com,0x01); //清屏指令. delayUs(250); LCD12864_Write(com,0x06); //AC自動加一 //LCD_Write(com,0x0F); //整体显示,游标打开,游标反白允许 LCD12864_Write_Str(1,4,clear); for(i=0;i<1000;i++) {;} }
void LCD12864_Clear(void) { LCD12864_Write(com,0x30); //??????. LCD12864_Write(com,0x01); //????. }
/*********************************************************************LCD顯示漢字子程式********************/ /********************************************* 函数名称:LCD12864_Write_Str 函数功能:在X行Y列写入词组(X为1-4,y为0开始)显示字符串 **********************************************/ void LCD12864_Write_Str(unsigned char x,unsigned char y,char *buff) { unsigned char addr=0; if(x==1)addr=0x80; if(x==2)addr=0x90; if(x==3)addr=0x88; if(x==4)addr=0x98; addr=addr+y; LCD12864_Write(com,0x30); //基本指令功能8位数据.write_com(0x30); //delay_ms(10); LCD12864_Write(com,addr); //基本指令功能.write_com(addr); while(*buff!='\0') { LCD12864_Write(dat,*buff); //write_data(buff); buff++; } }
/********************************************************************** 将整数数字转换为字符串存储 例:1转换为字符串存储,应加上0x30 ***************************************************************************/
void LCD12864_Write_int(unsigned char x,unsigned char y,int buff) { unsigned char addr=0,i=0,j; char temp[10],Str[10],*p; if(x==1)addr=0x80; if(x==2)addr=0x90; if(x==3)addr=0x88; if(x==4)addr=0x98; addr=addr+y; LCD12864_Write(com,0x30); //基本指令功能.write_com(0x30); delayUs(10); LCD12864_Write(com,addr); //基本指令功能.write_com(addr); while(buff) { temp=buff%10+0x30; i++; buff/=10; } j=i; for(i=0;i<j;i++) { Str=temp[j-i-1]; } if(!i) {Str[i++]='\0';} Str='\0'; p=Str; while(*p) { LCD12864_Write(dat,*p); //write_data(buff); p++; } } /**********************以下是自造字库所需的函数*******************************/ /***************自造字库设置地址函数*****************/ void LCD12864_SetAddr(unsigned char x,unsigned char y) //x行;y列 { unsigned char addr=0; if(x==1)addr=0x80; if(x==2)addr=0x90; if(x==3)addr=0x88; if(x==4)addr=0x98; addr=addr+y; LCD12864_Write(com,0x30); //基本指令功能8位数据.write_com(0x30); delayUs(10); LCD12864_Write(com,addr); //基本指令功能.write_com(addr); }
/******************************写出自造的汉子*************************************************/ void LCD12864_Write_Word(unsigned char *p) { unsigned char i,j,k; unsigned char lcd_x = 0x80; unsigned char lcd_y = 0x80; LCD12864_Write(com,0x34); //允许用户自定义CGRAM ,写数据时关闭图形显示
LCD12864_SetAddr(2,4); for(k = 0;k < 2;k++) { for(i = 0; i < 32;i++ ) { LCD12864_Write(com,lcd_x + i); //先写入水平坐标 LCD12864_Write(com,lcd_y); //再写入垂直坐标 for(j = 0;j < 16;j++) { LCD12864_Write(dat,*p++); } } lcd_y = 0x88; } LCD12864_Write(com,0x36); }
各位大侠指导下啊!!!
|