📄 lcd.c
字号:
#include "..\Visby\VisbyKernelDef.h"
#include "..\Visby\VisbyDevice.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define __CN_CHAR__
#include "Font\ENCL12.h" //this is the Lattices of the English Characters.
#ifdef __CN_CHAR__
#include "Font\HZK.h"
#endif
extern Visby_Device pVisby_Device[];
extern Visby_Task *pVisby_CurrTask;
#define LCD_XSIZE 320
#define LCD_XINTS 10
#define LCD_YSIZE 240
#define LCD_BUFFERSIZE (LCD_XSIZE*LCD_YSIZE/8)
#define LCD_CLKVAL 26 //60Mhz LCD_CLKVAL=10 ->151Hz
// LCD_CLKVAL=30 -> 52Hz
// LCD_CLKVAL=50 -> 31Hz
#define LCD_MVAL_USED 0
#define LCD_MVAL 13
#define LCD_HOZVAL (LCD_XSIZE/4-1)
#define LCD_LINEVAL (LCD_YSIZE-1)
#define M5D(n) ((n)&0x1fffff)
unsigned int *frameBuffer;
void LCD_Init()
{
int i;
if((unsigned int *)frameBuffer==0)
frameBuffer=(unsigned int *)heapalloc(LCD_BUFFERSIZE);
rLCDCON1=(0)|(1<<5)|(LCD_MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(LCD_CLKVAL<<12);
rLCDCON2=(LCD_LINEVAL)|(LCD_HOZVAL<<10)|(10<<21);
rLCDSADDR1=(0x0<<27)|(((unsigned int)frameBuffer>>22)<<21)|M5D((unsigned int)frameBuffer>>1);
rLCDSADDR2=M5D(((unsigned int)frameBuffer+(LCD_XSIZE*LCD_YSIZE/8))>>1)|(LCD_MVAL<<21);
rLCDSADDR3=LCD_XSIZE/16;
rLCDCON1=(1)|(1<<5)|(LCD_MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(LCD_CLKVAL<<12);
////////////////////////////////////////////////// Azbo Test Device Manager
pVisby_Device[DEV_LCD].Type = VB_DEV_ONE;
pVisby_Device[DEV_LCD].Desc = NULL;
pVisby_Device[DEV_LCD].pUser = NULL;
pVisby_Device[DEV_LCD].pWaitTask = NULL;
for(i=0;i<500000;i++);
///////////////////////////////////////////////////////////////////////////
}
void LCD_Cls(unsigned int c)
{
int i;
if( pVisby_Device[DEV_LCD].pUser != pVisby_CurrTask )return;
for(i=0;i<LCD_XINTS*LCD_YSIZE;i++)
frameBuffer[i]=c;
}
void LCD_Pixel(unsigned int x,unsigned int y,unsigned char color)
{
if(x<LCD_XSIZE&&y<LCD_YSIZE)
{
if(color==0)
frameBuffer[y*LCD_XINTS+(x>>5)]=frameBuffer[y*LCD_XINTS+(x>>5)]&(~(0x80000000>>(x&0x1F)));
else if(color==1)
frameBuffer[y*LCD_XINTS+(x>>5)]=frameBuffer[y*LCD_XINTS+(x>>5)]|(0x80000000>>(x&0x1F));
else if(color==2)
frameBuffer[y*LCD_XINTS+(x>>5)]=frameBuffer[y*LCD_XINTS+(x>>5)]^(0x80000000>>(x&0x1F));
}
}
void LCD_LoadBmp(unsigned int* bmp)
{
int i;
if( pVisby_Device[DEV_LCD].pUser != pVisby_CurrTask )return;
for(i=0;i<LCD_XINTS*LCD_YSIZE;i++)
frameBuffer[i]=bmp[i];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
void LCD_Line(int x0,int y0,int x1,int y1,unsigned char Color)
{
int x,y,sx,sy,e,dx,dy,temp;
if( pVisby_Device[DEV_LCD].pUser != pVisby_CurrTask )return;
dx=x1-x0;
dy=y1-y0;
if(!(dx|dy))
return;
if(ABS(dx)>ABS(dy))
{
if(x0>x1)
{
temp=x0;
x0=x1;
x1=temp;
temp=y0;
y0=y1;
y1=temp;
}
dx=x1-x0;
dy=y1-y0;
sy=SIGN(dy);
dy=ABS(dy);
e=(dy>>1);
y=y0;
for(x=x0;x<=x1;x++)
{
LCD_Pixel(x,y,Color);
e+=dy;
if(e>=dx)
{
y+=sy;
e-=dx;
}
}
}
else
{
if(y0>y1)
{
temp=x0;
x0=x1;
x1=temp;
temp=y0;
y0=y1;
y1=temp;
}
dx=x1-x0;
dy=y1-y0;
sx=SIGN(dx);
dx=ABS(dx);
e=(dx>>1);
x=x0;
for(y=y0;y<=y1;y++)
{
LCD_Pixel(x,y,Color);
e+=dx;
if(e>=dy)
{
x+=sx;
e-=dy;
}
}
}
}
void LCD_Bar(int x0,int y0,int x1,int y1,unsigned char LineColor,unsigned char FillColor)
{
int x,y,temp;
if( pVisby_Device[DEV_LCD].pUser != pVisby_CurrTask )return;
if(x0>x1)
{
temp=x0;
x0=x1;
x1=temp;
}
for(x=x0+1;x<x1;x++)
{
for(y=y0+1;y<y1;y++)
LCD_Pixel(x,y,FillColor);
}
for(x=x0;x<=x1;x++)
{
LCD_Pixel(x,y0,LineColor);
LCD_Pixel(x,y1,LineColor);
}
for(y=y0+1;y<y1;y++)
{
LCD_Pixel(x0,y,LineColor);
LCD_Pixel(x1,y,LineColor);
}
}
void LCD_Box(int x0,int y0,int x1,int y1,unsigned char Color)
{
int x,y,temp;
if( pVisby_Device[DEV_LCD].pUser != pVisby_CurrTask )return;
if(x0>x1)
{
temp=x0;
x0=x1;
x1=temp;
}
for(x=x0;x<=x1;x++)
{
LCD_Pixel(x,y0,Color);
LCD_Pixel(x,y1,Color);
}
for(y=y0+1;y<y1;y++)
{
LCD_Pixel(x0,y,Color);
LCD_Pixel(x1,y,Color);
}
}
int LCD_DrawText(char *str,int x,int y,char ForeColor,char BackColor) //Color:0-white,1-black,2-reverse,3-lucency
{
int i,k,n,qu,wei,location;
if( pVisby_Device[DEV_LCD].pUser != pVisby_CurrTask )return 0;
while(*str)
{
if(*str<128)
{
for(i=0;i<12;i++)
for(k=0;k<7;k++)
if((CL12[*str-32][i]>>k)&0x01)
{
if(ForeColor!=3)
LCD_Pixel(x+k,y+i,ForeColor);
}
else
{
if(BackColor!=3)
LCD_Pixel(x+k,y+i,BackColor);
}
x+=6;
str++;
}
#ifdef __CN_CHAR__
else
{
qu=*(str++)-0xa0;
wei=*(str++)-0xa0;
location=qu*94+wei;
for(n=0;n<NUM_STR;n++)
{
if(ZKQW[n]==location)
{
for(i=0;i<12;i++)
{
for(k=0;k<8;k++)
if((ZKDATA[n*24+i*2]>>(7-k))&0x01)
{
if(ForeColor!=3)
LCD_Pixel(x+k,y+i,ForeColor);
}
else
{
if(ForeColor!=3)
LCD_Pixel(x+k,y+i,BackColor);
}
for(k=0;k<4;k++)
if((ZKDATA[n*24+i*2+1]>>(7-k))&0x01)
{
if(ForeColor!=3)
LCD_Pixel(x+8+k,y+i,ForeColor);
}
else
{
if(ForeColor!=3)
LCD_Pixel(x+8+k,y+i,BackColor);
}
}
break;
}
}
x+=12;
}
#endif
}
return x;
}
void LCD_Printf(int x,int y,char ForeColor,char BackColor,char *fmt,...)
{
va_list ap;
char string[64];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
LCD_DrawText(string, x, y, ForeColor, BackColor);
va_end(ap);
}
int LCD_VirtualDrawText(char *str,int x) //for getting the pixel length of str
{
while(*str)
{
if(*str<128)
{
x+=6;
str++;
}
#ifdef __CN_CHAR__
else
{
str+=2;
x+=12;
}
#endif
}
return x;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -