📄 lcd.c.bak
字号:
bb = (long)b * b;
x = 0;
y = b;
d = 4 * bb + aa * (-b * 4 + 1);
while (4 * bb * (x + 1) < aa * (4 * y - 2))
{
if (flag)
{
draw_h_line( right + y, left - y, bottom + x,color);
if (x != 0)draw_h_line(right + y, left - y, top - x,color);
}
if (d < 0)
{
d += 4 * bb * (2 * x + 3);
x++;
}
else
{
if (!flag)
{
draw_h_line(right + x, left- x, bottom + y ,color);
draw_h_line(right + x, left- x, top - y,color);
}
d += 4 * bb * (2 * x + 3) + 4 * aa * (-2 * y + 2);
x++;
y--;
}
}
y = 0;
x = a;
d = 4 * aa + bb * (-a * 4 + 1);
while (4 * bb * (x + 1) > aa * (4 * y - 2))
{
if (!flag)
{
draw_h_line( right + x, left - x, bottom + y,color);
if (y != 0) draw_h_line(right + x, left - x, top - y,color);
}
if (d < 0)
{
d += 4 * aa * (2 * y + 3);
y++;
}
else
{
if (flag)
{
draw_h_line( right + y, left - y, bottom + x,color);
draw_h_line( right + y, left - y, top - x,color );
}
d += 4 * aa * (2 * y + 3) + 4 * bb * (-2 * x + 2);
y++;
x--;
}
}
}
void arrow(int startx,int starty,int baseline,unsigned char direct,unsigned int color)
{
int h;
int loop;
int x1 =0,x2 = 0;
int y1 =0,y2 = 0;
int dirflg = 0;
int sw;
h = ((baseline-1)>>1)+1;
sw = 0;
switch(direct)
{
case ARROW_UP:
dirflg = 1;
sw = 1;
x1 = startx;
x2 = startx+baseline-1;
y1 = starty;
break;
case ARROW_DOWN:
dirflg = -1;
sw = 1;
x1 = startx;
x2 = startx+baseline-1;
y1 = starty;
break;
case ARROW_LEFT:
dirflg = -1;
sw = 2;
x1 = startx;
y1 = starty;
y2 = starty+baseline-1;
break;
case ARROW_RIGHT:
dirflg = 1;
sw = 2;
x1 = startx;
y1 = starty;
y2 = starty+baseline-1;
break;
}
for(loop=0; loop<h;loop++)
{
switch(sw)
{
case 1:
line(x1,y1,x2,y1,color);
y1+=dirflg;
x1++;
x2--;
break;
case 2:
line(x1,y1,x1,y2,color);
x1+=dirflg;
y1++;
y2--;
break;
}
}
return ;
}
unsigned char LCD_DrawICON(unsigned char startX, unsigned char startY, unsigned int index,const IMAGESTYLE mImage)
{
unsigned int endX,endY;
unsigned long totalPixels,addr,i;
unsigned int sizeX, sizeY;
unsigned char lcd_buf, cTemp;
switch(mImage)
{
case Image22X10:
sizeX = 22;
sizeY = 10;
totalPixels = 440;
break;
case Image33X44:
sizeX = 33;
sizeY = 44;
totalPixels = 2904;
break;
case Image44X44:
sizeX = 44;
sizeY = 44;
totalPixels = 3872;
break;
case Image56X36:
sizeX = 56;
sizeY = 36;
totalPixels = 2*56*36;
break;
case Image20X26:
sizeX = 20;
sizeY = 26;
totalPixels = 1040;
break;
case Image24X24:
sizeX = 24;
sizeY = 24;
totalPixels = 1152;
break;
case Image320X26:
sizeX = 320;
sizeY = 26;
totalPixels = 16640;
break;
default:
return 1;
}
endX = startX+sizeX-1;
endY = startY+sizeY-1;
LCD_Set_XY(startX,startY);
if(index == 290)
{
LCD_Set_Window(214,0,239,319);
}
else if(297 == index)
{
LCD_Set_Window(0,0,26,319);
}
else
{
LCD_Set_Window(startY,startX,endY,endX);
}
//---------------------------------------------------------------------------
//从flash中读取数据
addr = (unsigned long)index << 12;
LATCbits.LATC14 = 0;
LATGbits.LATG6 = 0;
while(SPI2STAT&0x02);
SPI2BUF = 0x0B;
while(SPI2STAT&0x02);
SPI2STATbits.SPIROV = 0;
while(!(SPI2STAT&0x01));
cTemp = SPI2BUF;
SPI2BUF = (addr&0xffffff) >> 16;
while(SPI2STAT&0x02);
SPI2STATbits.SPIROV = 0;
while(!(SPI2STAT&0x01));
cTemp = SPI2BUF;
SPI2BUF = (addr&0xffff) >> 8;
while(SPI2STAT&0x02);
SPI2STATbits.SPIROV = 0;
while(!(SPI2STAT&0x01));;
cTemp = SPI2BUF;
SPI2BUF = addr&0xff;
while(SPI2STAT&0x02);
SPI2STATbits.SPIROV = 0;
while(!(SPI2STAT&0x01));
cTemp = SPI2BUF;
SPI2BUF = 0xff;
while(SPI2STAT&0x02);
while(!(SPI2STAT&0x01));
cTemp = SPI2BUF;
LCD_Write_Start();
__asm__ volatile( "disi #0x3FFF" );
for(i = 0; i< totalPixels;i++)
{
SPI2BUF = 0xff;
while(SPI2STAT&0x02);
SPI2STATbits.SPIROV = 0;
while(!(SPI2STAT&0x01));
lcd_buf = SPI2BUF;
LCD_Write_LCD_Data(lcd_buf);
}
LCD_Write_End();
__asm__ volatile( "disi #0x0000" );
LATGbits.LATG6 = 1;
LATCbits.LATC14 = 1;
return 0;
}
unsigned char cmp_w[8]={128,64,32,16,8,4,2,1};
void Drawicon24X24(int x, int y, unsigned char * FontModule,unsigned int color)
{
int row,c;
for(row=0;row<24;row++)
{
for(c=0;c<8;c++)
{
if((FontModule[row*3]&cmp_w[c])!=0)
putpixel(c+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*3+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*3+2]&cmp_w[c])!=0)
putpixel(c+16+x,row+y,color);
}
}
}
void Drawicon32X32(int x, int y, unsigned char * FontModule,unsigned int color)
{
int row,c;
for(row=0;row<32;row++)
{
for(c=0;c<8;c++)
{
if((FontModule[row*4]&cmp_w[c])!=0)
putpixel(c+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*4+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*4+2]&cmp_w[c])!=0)
putpixel(c+16+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*4+3]&cmp_w[c])!=0)
putpixel(c+24+x,row+y,color);
}
}
}
void Drawicon48X48(int x, int y, unsigned char * FontModule,unsigned int color)
{
int row,c;
for(row=0;row<48;row++)
{
for(c=0;c<8;c++)
{
if((FontModule[row*6]&cmp_w[c])!=0)
putpixel(c+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*6+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*6+2]&cmp_w[c])!=0)
putpixel(c+16+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*6+3]&cmp_w[c])!=0)
putpixel(c+24+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*6+4]&cmp_w[c])!=0)
putpixel(c+32+x,row+y,color);
}
for(c=0;c<8;c++)
{
if((FontModule[row*6+5]&cmp_w[c])!=0)
putpixel(c+40+x,row+y,color);
}
}
}
void Drawicon16X16(int x, int y, unsigned char * FontModule,unsigned color)
{
int row,c;
for(row=0;row<16;row++)
{
for(c=0;c<8;c++)
{
if((FontModule[row*2]&cmp_w[c])!=0)
putpixel(c+x,row+y,color);
//putpixel(row+y,c+x,15);
}
for(c=0;c<8;c++)
{
if((FontModule[row*2+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y,color);
//putpixel(row+y,c+10+x,15);
}
}
}
void * memmove_kk(unsigned char * dest,const unsigned char *src,unsigned int count)
{
char *tmp, *s;
if (dest <= src)
{
tmp = (char *) dest;
s = (char *) src;
while (count--)
*tmp++ = *s++;
}
else
{
tmp = (char *) dest + count;
s = (char *) src + count;
while (count--)
*--tmp = *--s;
}
return dest;
}
void outtext(int x,int y,unsigned char *str,int fontStyle,unsigned int color)
{
unsigned int address = 0;
unsigned char xWidthByte = 0;
const unsigned char *pFont = NULL;
unsigned char poffset[128];
unsigned char chtmp;
unsigned char choffset,number = 0;
unsigned char row,c;
switch(fontStyle)
{
case FONT_16X24:
xWidthByte = 48;
pFont = FONT16X24;
break;
case FONT_12X16:
//xWidthByte = 24;
xWidthByte = 16;
pFont = FONT12X16;
break;
case FONT_32X32:
xWidthByte = 128;
pFont = FONT32X32;
break;
default:
break;
}
while(*str)
{
chtmp = *str;
++number;
if(chtmp>=0x30&&chtmp<=0x39)
{
choffset = chtmp-0x30;
if(fontStyle == FONT_32X32)
{
address = choffset * xWidthByte;
}
else
{
address = 52*xWidthByte + choffset * xWidthByte;
}
}
else if(chtmp >= 'A' && chtmp <= 'Z')
{
choffset = chtmp-'A';
address = 26*xWidthByte + choffset * xWidthByte;
}
else if(chtmp >= 'a' && chtmp <= 'z')
{
choffset = chtmp-'a';
address = choffset * xWidthByte;
}
else
{
switch(chtmp)
{
case ':':
address = (52 + 10)*xWidthByte ;
break;
case '-':
address = (52 + 10)*xWidthByte + xWidthByte;
break;
case '.':
address = (52 + 10)*xWidthByte + 2*xWidthByte;
break;
case '/':
address = (52 + 10)*xWidthByte + 3*xWidthByte;
break;
case '?':
address = (52 + 10)*xWidthByte + 4*xWidthByte;
break;
default:
break;
}
}
if(0x20==chtmp)
{
memset(poffset,0x00,xWidthByte);
}
else
{
memmove(poffset,pFont+address,xWidthByte);
}
str++;
if(fontStyle == FONT_16X24)
{
for(row=0;row<16;row++)
{
for(c=0;c<8;c++)
{
if((poffset[row*3]&cmp_w[c])!=0)
putpixel(c+x,row+y+number*11,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*3+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y+number*11,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*3+2]&cmp_w[c])!=0)
putpixel(c+16+x,row+y+number*11,color);
}
}
}
if(fontStyle == FONT_8X16)
{
for(row=0;row<8;row++)
{
for(c=0;c<8;c++)
{
if((poffset[row*2]&cmp_w[c])!=0)
putpixel(c+x,row+y+number*8,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*2+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y+number*8,color);
}
}
}
if(fontStyle == FONT_12X16)
{
for(row=0;row<8;row++)
{
for(c=0;c<8;c++)
{
if((poffset[row*2]&cmp_w[c])!=0)
putpixel(c+x,row+y+number*9,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*2+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y+number*9,color);
}
}
}
if(fontStyle == FONT_32X32)
{
for(row=0;row<32;row++)
{
for(c=0;c<8;c++)
{
if((poffset[row*4]&cmp_w[c])!=0)
putpixel(c+x,row+y+number*18,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*4+1]&cmp_w[c])!=0)
putpixel(c+8+x,row+y+number*18,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*4+2]&cmp_w[c])!=0)
putpixel(c+16+x,row+y+number*18,color);
}
for(c=0;c<8;c++)
{
if((poffset[row*4+3]&cmp_w[c])!=0)
putpixel(c+24+x,row+y+number*18,color);
}
}
}
}
}
void bar( int x0, int y0, int width, int height,unsigned color)
{
int i;
int j;
LCD_Set_Window(x0,y0,x0+width,y0+height);
LCD_Write_Start();
__asm__ volatile( "disi #0x3FFF" );
for (i=y0; i<y0+height; i++)
{
for (j=x0; j<x0+width; j++)
{
LCD_Write_Data(color);
}
}
__asm__ volatile( "disi #0x0000" ); //enable interrupts
LCD_Write_End();
draw_v_line(y0,y0 + height,x0 + width,color);
draw_v_line(y0,y0 + height,x0 + width-1,color);
draw_v_line(y0,y0 + height,x0 ,color);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -