|
|
修改自动弘毅提供的SPI库
原来的库显示字符函数只接受无符号字符数组,不支持反白显示,驱动芯片本身也只支持1-3行和2-4行同时反白.没什么意义.
网上查到 ST7920驱动字符显示的CGRAM和图形的GGRAM是相互独立的面显示的内容是两个RAM异或的结果
显示字符串函数.这样好用多了.
- void LCD12864RSPI::M_DisplayString(int M_X,int M_Y,String *str)
- {
- int strl=(*str).length();
- uchar pr[strl];
- if (strl+M_Y<17)
- {
- for (int i = 0; i < strl; i++){
- pr[i]=(*str).charAt(i);
- }
- DisplayString(M_X,M_Y,pr,strl);
- }
- }
复制代码
清除反白.在反白前要先清除翻否则会有噪点.
- void LCD12864RSPI::Disp_black()
- {
- unsigned char i,j;
- WriteCommand(0x34);
- for(i=0;i<32;i++){
- WriteCommand(0x80+i);
- WriteCommand(0x80);
- for(j=0;j<16;j++) {
- WriteData(0x00);
- }
- }
- for(i=0;i<32;i++){
- WriteCommand(0x80+i);
- WriteCommand(0x88);
- for(j=0;j<16;j++) {
- WriteData(0x00);
- }
- }
- WriteCommand(0x30);
- }
复制代码
反白
CX和CY 是起始坐标
width 是要反白的字符数
YN 是反白为1是否则取消反白.
- void LCD12864RSPI::convertChar(int CX,int CY, int width,int YN)
- {
- int basicBlock;
- switch(CX){
- case 0: CY |= 0x80; CX=0x80; break;
- case 1: CY |= 0x80; CX=0x90; break;
- case 2: CY |= 0x88; CX=0x80; break;
- case 3: CY |= 0x88; CX=0x90; break;
- default: break;
- }
- for (int i=16; i != 0; i--)
- {
- basicBlock = width;
- WriteCommand(0x34);
- WriteCommand(CX);
- WriteCommand(CY);
- WriteCommand(0x30);
- for (;basicBlock != 0; basicBlock--)
- {
- if(YN==1){
- WriteData(0xff);
- }else{
- WriteData(0x00);
- }
- }
- CX++;
- }
- WriteCommand(0x36);
- WriteCommand(0x30);
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|