使用stemwin会使开发界面编的简单快捷。对于单色屏19264只需要编写打点和获取点这两个函数。19264在Y方向显示上使用分页显示,即有8页 192列,所以在编写dadi大点函数时最简便的方法就是分配一块显示hua缓存,所有数据的显示都通过操作这块现存来实现。下面贴出代码方便以后查看
//定义显示缓存64行192列 由于64行 必须同时操作一页所以数组定义64/8页
char g_arrDispBuf[64/8][192]={0,};
const uint8_t aOrTab[8] = {0x01, 0x02, 0x04, 0x08,0x10,0x20,0x40,0x80};
const uint8_t aAndTab[8] = {0xFE, 0xFD, 0xFB, 0xF7,0xEF,0xDF,0xBF,0x7F};
#define LCD_RST_0 LCD_RST_PORT->BSRRH = LCD_RST_PINS
#define LCD_RST_1 LCD_RST_PORT->BSRRL = LCD_RST_PINS
#define LCD_CS_0 LCD_CS_PORT->BSRRH = LCD_CS_PINS
#define LCD_CS_1 LCD_CS_PORT->BSRRL = LCD_CS_PINS
#define LCD_CD_0 LCD_CD_PORT->BSRRH = LCD_CD_PINS
#define LCD_CD_1 LCD_CD_PORT->BSRRL = LCD_CD_PINS
#define LCD_SCK_0 LCD_SCK_PORT->BSRRH = LCD_SCK_PINS
#define LCD_SCK_1 LCD_SCK_PORT->BSRRL = LCD_SCK_PINS
#define LCD_SDA_0 LCD_SDA_PORT->BSRRH = LCD_SDA_PINS
#define LCD_SDA_1 LCD_SDA_PORT->BSRRL = LCD_SDA_PINS
#define LCD_BL_ON LCD_BL_PORT->BSRRH = LCD_BL_PINS
#define LCD_BL_OFF LCD_BL_PORT->BSRRL = LCD_BL_PINS
//写指令到 LCD 模块
void LCD_SendCmd(int data)
{
char i;
LCD_CS_0;
LCD_CD_0;
for(i=0;i<8;i++)
{
LCD_SCK_0;
if(data&0x80)
{
LCD_SDA_1;
}
else
{
LCD_SDA_0;
}
LCD_SCK_1;
data=data<<=1;
}
LCD_CS_1;
}
//写数据到 LCD 模块
void LCD_SendData(int data)
{
char i;
LCD_CS_0;
LCD_CD_1;
for(i=0;i<8;i++)
{
LCD_SCK_0;
if(data&0x80)
{
LCD_SDA_1;
}
else
{
LCD_SDA_0;
}
LCD_SCK_1;
data=data<<=1;
}
LCD_CS_1;
}
//u8 page(0-7共8页),
//u8 column(列0-191)
void LCD_SetAddr(u8 page,u8 column)
{
//设置页地址。每页是 8 行。一个画面的 64 行被分成 8 个页。
//0-7页共8页
LCD_SendCmd(0xb0+page);
//0-191列共192列
//设置列地址的高 4 位
LCD_SendCmd(((column>>4)&0x0f)+0x10);
//设置列地址的低 4 位
LCD_SendCmd(column&0x0f);
}
/*
(x 0,y 0)
..............................................(y 0,x 191)
. |
. |
. |
.-----------.(y 4,x 12)
.
.
.
.
.
(y 63,x 0)
*/
//y(0-63) x(0-191) nColor(0不显示 1显示)
void LCD_DrawDots(u8 x,u8 y, u8 nColor)
{
//判断X(列0-191)在哪一列
u8 nColumnIndex;
//判断Y(行0-64)在哪一页
u8 nPageIndex ;
//判断这一页的哪一位
u8 nBitIndex;
u8 h = y;//行
u8 l = x;//列
//y(0-63) x(0-191)
//LIMIT(0,l,191);
//LIMIT(0,h,63);
//判断列(0-191)在哪一列
nColumnIndex = l;
//判断行(0-64)在哪一页
//nPageIndex = row/8;
nPageIndex = h>>3;
//判断这一页的哪一位
//nBitIndex = row%8;
nBitIndex = h-(nPageIndex<<3);
//显示
if(nColor == 0)
{
//g_arrDispBuf[nColumnIndex][nPageIndex] |= (0x01<
g_arrDispBuf[nPageIndex][nColumnIndex] |= aOrTab[nBitIndex];
}
else
{
//g_arrDispBuf[nColumnIndex][nPageIndex] &= ~(0x01<
g_arrDispBuf[nPageIndex][nColumnIndex] &= aAndTab[nBitIndex];
}
//设置地址
LCD_SetAddr(nPageIndex,nColumnIndex);
//写数据
LCD_SendData(g_arrDispBuf[nPageIndex][nColumnIndex]);
}
//y(0-63) x(0-191) nColor(0不显示 1显示)
u8 LCD_GetDots(u8 x,u8 y)
{
//判断X(列0-191)在哪一列
u8 nColumnIndex;
//判断Y(行0-63)在哪一页
u8 nPageIndex ;
//判断这一页的哪一位
u8 nBitIndex;
//查找出这一页的这一列缓存数据
u8 h = y;//行
u8 l = x;//列
//判断列(0-191)在哪一列
nColumnIndex = l;
//判断行(0-64)在哪一页
//nPageIndex = row/8;
nPageIndex = h>>3;
//判断这一页的哪一位
//nBitIndex = row%8;
nBitIndex = h-(nPageIndex<<3);
//显示
//return ((g_arrDispBuf[nPageIndex][nColumnIndex] & (0x01<
return ((g_arrDispBuf[nPageIndex][nColumnIndex] & aOrTab[nBitIndex])?0:1);
}
//全屏清屏
void LCD_ClearScreen(void)
{
//行row 列column
u8 page,column;
for(page=0;page<8;page++)
{
LCD_SetAddr(page,0);
for(column=0;column<192;column++)
{
LCD_SendData(0x00);
g_arrDispBuf
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』