以下程序与硬件有关,LCD屏从左到右从上到下编码.
本贴point是keil编译环境下,字符串指针与数组的结合应用,我从新学习了c语言指针这部分内容,操作方法如下:
函数形参是指针类型,赋值为字符串,后面是字符串横纵坐标地址
void LCDGB2312_X_Ydisplay(uint8_t *String , uint8_t x, uint8_t y)
赋值为字符串操作例:
LCDGB2312_X_Ydisplay("您好中国年",0,0);
中文字符用引号,字符串转换成编码,GB2312编码方式
调用内容:
LCDGB2312_X_Ydisplay("您好中国年",0,0);
函数内容如下:
void LCDGB2312_X_Ydisplay(uint8_t *String , uint8_t x, uint8_t y)
{
uint8_t i=0,j=0,StringAdd[32]={0};
uint32_t Address ;
uint16_t BaseAdd=0;
for (i=0 ;String[i*2] != ' '; i++)
{
if(String[i*2] ==0xA9 && String[i*2+1] >=0xA1)
Address = (282 + (String[i*2+1] - 0xA1 ))*32+BaseAdd;
else if(String[i*2] >=0xA1 && String[i*2] <= 0xA3 && String[i*2+1] >=0xA1)
Address =( (String[i*2] - 0xA1) * 94 + (String[i*2+1] - 0xA1))*32+ BaseAdd;
else if(String[i*2] >=0xB0 &&String[i*2] <= 0xF7 && String[i*2+1] >=0xA1)
Address = ((String[i*2] - 0xB0) * 94 + (String[i*2+1] - 0xA1)+ 846)*32+ BaseAdd;
StringAdd[i*4] = 0X03;
StringAdd[i*4+3] = Address;
StringAdd[i*4+2] = Address>>8;
StringAdd[i*4+1] = Address>>16;
}
for( i = 0; StringAdd [i*4] != 0x00; i++)
{
uint8_t StringAdd1[4] = {0};
uint8_t SPIrecebuffer[32] = {0};
StringAdd1[0] = StringAdd[i*4];
StringAdd1[1] = StringAdd[i*4+1];
StringAdd1[2] = StringAdd[i*4+2];
StringAdd1[3] = StringAdd[i*4+3];
HAL_GPIO_WritePin(ROM_CS_GPIO_Port, ROM_CS_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1,StringAdd1,4,10);
HAL_SPI_Receive(&hspi1,SPIrecebuffer,32,10);
HAL_GPIO_WritePin(ROM_CS_GPIO_Port, ROM_CS_Pin, GPIO_PIN_SET);
if (y%8 == 0) //two page situation
{
for(j=0 ;j<16; j++)
{
lcdMem[(7-y/8-1)*128+x+j+ 16*i] =SPIrecebuffer[j];
lcdMem[(7-y/8)*128+x+j+ 16*i] = SPIrecebuffer[j+16];
}
}
else //three page sityation
{
for(j=0 ;j<16; j++)
{
lcdMem[(7-y/8-2)*128+x+j+ 16*i] &= 0xff>>(y%8+1);
lcdMem[(7-y/8-2)*128+x+j+ 16*i] ^= SPIrecebuffer[j] << (7-y%8);
lcdMem[(7-y/8-1)*128+x+j+ 16*i] &= 0x00;
lcdMem[(7-y/8-1)*128+x+j+ 16*i] ^= ((SPIrecebuffer[j]>>(y%8+1))^(SPIrecebuffer[j+16]<<(7-y%8)));
lcdMem[(7-y/8)*128+x+j+ 16*i] &= 0xff<<(7-y%8);
lcdMem[(7-y/8)*128+x+j+ 16*i] ^= SPIrecebuffer[j+16]>>(y%8+1);
}
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
lcdMem[(7-y/8-2)*128+x+j+ 16*i] &= 0xff>>(y%8+1);
lcdMem[(7-y/8-2)*128+x+j+ 16*i] ^= SPIrecebuffer[j] << (7-y%8);
lcdMem[(7-y/8-1)*128+x+j+ 16*i] &= 0x00;
lcdMem[(7-y/8-1)*128+x+j+ 16*i] ^= ((SPIrecebuffer[j]>>(y%8+1))^(SPIrecebuffer[j+16]<<(7-y%8)));
lcdMem[(7-y/8)*128+x+j+ 16*i] &= 0xff<<(7-y%8);
lcdMem[(7-y/8)*128+x+j+ 16*i] ^= SPIrecebuffer[j+16]>>(y%8+1);
调整坐标原点和调整跨页情况的位操作,个人喜欢数学那样定义坐标原点 所以做了些数据处理
里面有个错误,一个是 lcdMem[(7-y/8-2)*128+x+j+ 16*i] &= 0xff>>(y%8+1); 括号中的应为y%8 不需要减一下面同理
另一个 lcdMem[(7-y/8-2)*128+x+j+ 16*i] ^= SPIrecebuffer[j] << (7-y%8); 括号内应该用8-y%8
8,128,16什么的都用移位替换
而且总感觉计算可以更简单点
虚心接受,感谢!
一周热门 更多>