📄 s60753.c
字号:
uchar distantX, distantY, swap;
/* 判断绘图条件是否合法 */
if((x0 >= 160)||(x0 < 0)||(y0 >= 160)||(y0 < 0))
return ERROR;
if((x1 >= 160)||(x1 < 0)||(y1 >= 160)||(y1 < 0))
return ERROR;
/* 显示图层 */
if((layer < 0)||(layer > 1))
return ERROR;
s60753_setCurrentLayer(layer);
if ((x1 < x0)||((x1 == x0)&&(y0 > y1 ))){
swap = x0;
x0 = x1;
x1 = swap;
swap = y0;
y0 = y1;
y1 = swap;
}
distantX = abs(x0 - x1) + 1;
distantY = abs(y0 - y1) + 1;
/* 设定绘图方向 */
if(distantX >= distantY)
drawDirection = 0;
else
drawDirection = 1;
/* 设定显示图层 */
if(layer == 0){
if((currentLayerState & 0x01) == 0)
currentLayerState = 0x11;
}else if(layer == 1){
if((currentLayerState & 0x10) == 0)
currentLayerState = 0x11;
}else
return ERROR;
if((color < 0x80) && (color > 0))
color = 0xFF;/* 颜色问题 */
/* 直线数据写入相应的ram */
if(drawDirection == 0){/* horizontal */
for(i = 0; i < distantX; i++)
currentLayer[162 * (y0 + (y1 - y0) * i/(x1 - x0)) + x0 + i + 2] = color;
}else{/* vertical */
if(y1 >= y0)
for(i = 0; i < distantY; i++)
currentLayer[162 * (y0 + i) + (x1 - x0) * i/(y1 - y0) + x0 + 2] = color;
else
for(i = 0; i < distantY; i++)
currentLayer[162 * (y0 - i) + (x1 - x0) * i/(y0 - y1) + x0 + 2] = color;
}
if(y0 <= y1){
return s60753_refreshArea(x0,y0, distantX, distantY);
}else{
return s60753_refreshArea(x0,y1, distantX, distantY);
}
}
/******************************************************************************
*
* s60753_fillRect - 填充矩形框
*
* INPUTS:
* int layer: 图层号
* int xstart: 起点的横坐标 pixels
* int ystart: 起点的纵坐标 pixels
* int width: 矩形框的宽度
* int height: 矩形框的高度
* int color: 颜色 1 黑色 0 白色
*
* RETURNS:
* 画点成功与否标志 0:成功 -1:坐标超出屏幕范围
*
******************************************************************************/
extern int s60753_fillRect(int layer, int xstart,int ystart,int width,int height,int color)
{
uchar i,j;
/* 判断绘图条件是否合法 */
if((xstart >= 160)||(xstart < 0)||(ystart >= 160)||(ystart < 0))
return ERROR;
if((xstart + width > SCREEN_HIGHT) || (ystart + height > SCREEN_HIGHT))
return ERROR;
/* 显示图层 */
if((layer < 0)||(layer > 1))
return ERROR;
s60753_setCurrentLayer(layer);
if((color < 0x80) && (color > 0))
color = 0xFF;/* 颜色问题 */
/* 设定显示图层 */
for(i = 0; i < height; i++)
for(j = 0; j < width; j++)
currentLayer[(ystart + i) * 162 + xstart + 2 + j] = color;
return s60753_refreshArea( xstart, ystart, width, height);
}
/******************************************************************************
*
* s60753_refreshArea - 更新指定的坐标位置数据
*
* INPUTS:
* int xstart: 起点的横坐标 pixels
* int ystart: 起点的纵坐标 pixels
* int width: 位图的宽度
* int height: 位图的高度
*
* RETURNS:
* 0:成功 -1:输入的位图数据为空 -2:位图范围超出屏幕范围
*
******************************************************************************/
static int s60753_refreshArea(int xstart,int ystart,int width,int height)
{
uchar i,j,line;
uchar refreshSX,refreshEX;/* 需更新的横坐标起始、终点值(按列计算) */
uchar refreshRSX,refreshREX;
unsigned int position=0;
/* 判断绘图条件是否合法 */
if((xstart >= SCREEN_WIDTH)||(xstart < 0)||(ystart >= SCREEN_HIGHT)||(ystart < 0))
return ERROR;
if((xstart + width > SCREEN_WIDTH) || (ystart + height > SCREEN_HIGHT))
return ERROR;
refreshSX = (xstart + 47)/3; /* 起点左边空白两像素 */
refreshEX = (xstart + width + 49)/3; /* 终点 */
refreshRSX = refreshSX * 3;
refreshREX = refreshEX * 3 + 3;
line = ystart + height - 1;
/*EXT 0*/
__LCDCommand(LCD_EXT_DISABLE);
/*Column Address Set*/
__LCDCommand(LCD_COLUMN_ADDR_SET);
__LCDParam(refreshSX); /* start column */
__LCDParam(refreshEX); /* end column */
/* Line Address Set */
__LCDCommand(LCD_LINE_ADDR_SET);
__LCDParam(ystart); /* start line */
__LCDParam(line); /* end line */
/* Writing to memory */
__LCDCommand(LCD_WRITE_DATA);
if(currentLayerState == 0x11){
switch(compMode){
case 0:
for(i = ystart; i < ystart + height; i++){
for(j = refreshRSX; j < refreshREX; j++){
position = 162 * i + j - 45;
LCD_DATA_OUT(layer0[position] | layer1[position]);
}
}
break;
case 1:
for(i = ystart; i < ystart + height; i++){
for(j = refreshRSX ; j < refreshREX; j++){
position = 162 * i + j - 45;
LCD_DATA_OUT(layer0[position] ^ layer1[position]);
}
}
break;
case 2:
for(i = ystart; i < ystart + height; i++){
for(j = refreshRSX; j < refreshREX; j++){
position = 162 * i + j - 45;
LCD_DATA_OUT(layer0[position] & layer1[position]);
}
}
break;
default:break;
}
/* only layer0 is open */
}else if(currentLayerState == 0x01){
for(i = ystart; i < ystart + height; i++)
for(j = refreshRSX; j < refreshREX; j++){
LCD_DATA_OUT(layer0[162 * i + j - 45]);
}
/* only layer1 is open */
}else if(currentLayerState == 0x10){
for(i = ystart; i < ystart + height; i++)
for(j = refreshRSX; j < refreshREX; j++){
LCD_DATA_OUT(layer1[162 * i + j - 45]);
}
}
return OK;
}
/******************************************************************************
*
* s60753_backLigth - 点亮/熄灭LCD背光
* INPUTS:
* int light: 大于0 点亮背光; 等于0 熄灭背光
*
* RETURNS:
* NONE
*
******************************************************************************/
extern void s60753_backLigth(int light)
{
if (light){
LCD_EL_ON();
}else{
LCD_EL_OFF();
}
}
/******************************************************************************
*
* s60753_contrast - 调节LCD对比度
* INPUTS:
* int upOrDown: 大于0 跳高对比度; 等于0 调低对比度
*
* RETURNS:
* NONE
*
******************************************************************************/
extern void s60753_contrast(int upOrDown)
{
int i;
if (upOrDown > 0) {
s_iLcdContrast++;
for(i = 0; i < 2; i++) __LCDCommand(LCD_VOL_UP);
} else if (upOrDown == 0) {
s_iLcdContrast--;
for(i = 0; i < 2; i++) __LCDCommand(LCD_VOL_DOWN);
}
}
/******************************************************************************
*
* s60753_tuneLight - 调节LCD亮度
* INPUTS:
* int upOrDown: 大于0 调高对比度; 等于0 调低对比度
*
* RETURNS:
* NONE
*
******************************************************************************/
extern void s60753_tuneLight(int upOrDown)
{
s60753_contrast(upOrDown);
}
/******************************************************************************
*
* s60753_tuneLightDefault - 设置对比度指定值
* INPUTS:
* int value: 对比度指定值
*
* RETURNS:
* NONE
*
******************************************************************************/
extern void s60753_tuneLightDefault(int value)
{
s_iLcdContrast = value;
}
/******************************************************************************
*
* s60753_tuneLightDefault - 调节LCD亮度到默认值
* INPUTS:
* int upOrDown: 大于0 高对比度; 等于0 调低对比度
*
* RETURNS:
* NONE
*
******************************************************************************/
extern void s60753_tuneLightSpecial(int value)
{
int diff = value - s_iLcdContrast;
if (diff > 0) {
while(diff-- > 0) s60753_contrast(1);
} else {
while(diff++ < 0) s60753_contrast(0);
}
}
extern void s60753_Cross_Line()
{
return;
}
extern int s60753_setCursor(int column,int row)
{
return OK;
}
extern int s60753_toBmp(uchar * f_nBmp)
{
int i, j;
int position;
printf("currentLayerState = %02X\n", currentLayerState);
if (currentLayerState == 0x11){
switch(compMode){
case 0:
for(i = 0; i < 160; i++){
for(j = 0; j < 162; j++){
position = 162 * i + j;
f_nBmp[position] = (layer0[position] | layer1[position]);
}
}
break;
case 1:
for(i = 0; i < 160; i++){
for(j = 0; j < 162; j++){
position = 162 * i + j;
f_nBmp[position] = (layer0[position] ^ layer1[position]);
}
}
break;
case 2:
for(i = 0; i < 160; i++){
for(j = 0; j < 162; j++){
position = 162 * i + j;
f_nBmp[position] = (layer0[position] & layer1[position]);
}
}
break;
default:
for(i = 0; i < 160; i++){
for(j = 0; j < 162; j++){
position = 162 * i + j;
f_nBmp[position] = (currentLayer[position]);
}
}
break;
}
}else if(currentLayerState == 0x01){
for(i = 0; i < 160; i++){
for(j = 0; j < 162; j++){
position = 162 * i + j;
f_nBmp[position] = (layer0[position]);
}
}
}else if(currentLayerState == 0x10){
for(i = 0; i < 160; i++){
for(j = 0; j < 162; j++){
position = 162 * i + j;
f_nBmp[position] = (layer1[position]);
}
}
}
return 0;
}
/***************************** End of s60753.c ******************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -