📄 ca320240.c-1
字号:
continue;
}
code=*(str++);
if(code<128){/*为ascii码*/
if(code<31){/*为控制字符*/
ca320240_control_text(&x,&y,code);
continue;/*控制字符不进行显示*/
}/*为控制字符*/
code=code*12+1;
if(x>(AP*8-8)){
x=0;
y+=(CHARACTER_HEIGH+1);
}
for(j=0;j<12;j++){
ch=character_house_asc[code++];
switch(color){
case 0:
ch=0x00;
break;
case 2:
ch=~ch;
break;
default:
break;
}
ca320240_output_one_data(x,y+j,6,ch,color);/*英文字符宽度为6*/
}
x+=6;/*英文字符宽度为6*/
}else{/*为汉字*/
if(x>(AP*8-CHARACTER_WIDTH)){
x=0;
y+=(CHARACTER_HEIGH+1);
}
code=gb2312_0_char_offset(str-1)*16*CHARACTER_HEIGH/8;/*在字库中默认为16宽度*/
str++;
if(str!=ptr)
ca320240_output_ch(x,y,code,color);
i++;
x+=(CHARACTER_WIDTH);/*中文字符宽度*/
}
}/*显示字符*/
*l=x;
*h=y;
return 0;
}
/***********************************************************
输出英文显示
x---x坐标(以字符位单位)
y---y坐标(以字符位单位)
len--字符长度;
str---英文字符
color----0 底色
1 白色
2 反白
************************************************************/
int text_print(unsigned int x,unsigned int y,unsigned char *str,int len,int color)
{
x*=8;
y*=8;
return ca320240_output_en_drv(&x,&y,len,str,color);
}
/***********************************************************
输出英文显示
x---x坐标
y---y坐标
len--字符长度;
str---英文字符
color----0 底色
1 白色
2 反白
************************************************************/
int graphics_print(unsigned int x,unsigned int y,unsigned char *str,int len,int color)
{
return ca320240_output_en_drv(&x,&y,len,str,color);
}
/***********************************************************
画点函数
x---x坐标(0---319)
y---y坐标(0---239)
color---颜色
0---LCM_BLACK
1---LCM_WHITE
2---LCM_INVERT
************************************************************/
static void _graphics_point(int x,int y,int color)
{
int ptr;
unsigned char ch,temp;
if(x>CA320240_WIDTH)return;
if(y>CA320240_HEIGTH)return;
ptr=y*AP+x/8+SAD2;
/*设置指针右移*/
ca320240_pr1(CA320240_CSDIR_RIGHT);
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*读取当前显示的数据*/
ca320240_pr1(CA320240_MREAD);
ch=ca320240_pr3();
/*合成数据*/
temp=1<<(unsigned char)(7-x % 0x8);
switch(color){
case LCM_BLACK:
ch&=(~temp);
break;
case LCM_WHITE:
ch|=temp;
break;
case LCM_INVERT:
ch^=temp;
break;
default:
break;
}
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*写入当前显示的数据*/
ca320240_pr1(CA320240_MWRITE);
ca320240_pr2(ch);
}
void graphics_point(int x,int y,int color)
{
ca320240_wait_for_write();
_graphics_point(x,y,color);
}
/***********************************************************
输出图片程序
************************************************************/
void put_bmp(char *bmp)
{
unsigned int i,j;
char *ptr=bmp;
int pos=0;
ca320240_wait_for_write();
/*CSRDIR 右移*/
ca320240_pr1(CA320240_CSDIR_RIGHT);
/*清除绘画屏*/
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(SAD2L);/*设置指针寄存器低8位*/
ca320240_pr2(SAD2H);/*设置指针寄存器高8位*/
/*MWRITE*/
ca320240_pr1(CA320240_MWRITE);
for(i=0;i<LF;i++){
ca320240_pr1(CA320240_CSRW);
pos=SAD2+i*AP;
ca320240_pr2((pos & 0xff));/*设置指针寄存器低8位*/
ca320240_pr2(((pos>>8) & 0xff));/*设置指针寄存器高8位*/
/*MWRITE*/
ca320240_pr1(CA320240_MWRITE);
for(j=0;j<AP;j++){
ca320240_pr2(*ptr++);
}
}
return ;
}
/***********************************************************
获取点函数
x---x坐标(0---319)
y---y坐标(0---239)
buf---buf
************************************************************/
char graphics_getpixel(int x,int y)
{
int ptr;
unsigned char ch;
if(x>CA320240_WIDTH)return 0;
if(y>CA320240_HEIGTH)return 0;
ptr=y*AP+x/8+SAD2;
/*设置指针右移*/
ca320240_pr1(CA320240_CSDIR_RIGHT);
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*读取当前显示的数据*/
ca320240_pr1(CA320240_MREAD);
ch=ca320240_pr3();
ch=((ch>>(7-x%8)) & 0x1);
return ch;
}
/***********************************************************
获取块函数
x---x坐标(0---319)
y---y坐标(0---239)
w---w块宽度(1--320)
h---h块高度(1--240)
buf---buf
************************************************************/
static unsigned char v_0[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
static unsigned char v_1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
static void graphics_getbox_line(int x,int y,int w,void *buffer)
{
int ptr,t,p;
unsigned char temps;
int i,count=0;
unsigned char *buf=(unsigned char *)buffer;
/***********填写中间代码**************/
t=x/8;
p=x%8;
ptr=y*AP+t+SAD2;
/*设置指针右移*/
ca320240_pr1(CA320240_CSDIR_RIGHT);
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
ca320240_pr1(CA320240_MREAD);
if(p){
temps=ca320240_pr3();
for(i=p;i<8;i++){
if(temps & v_0[i]){
buf[count++]=1;
}else{
buf[count++]=0;
}
if(count>=w){
return;
}
}
}
while(1){
temps=ca320240_pr3();
for(i=0;i<8;i++){
if(temps & v_0[i]){
buf[count++]=1;
}else{
buf[count++]=0;
}
if(count>=w){
return;
}
}
}
return;
}
static void graphics_putbox_line(int x,int y,int w,void *buffer)
{
int ptr,t0,t1,p0,p1;
unsigned char temp_color,temps=0,tempe=0;
int i,count=0,j;
int x0=x,y0=y,w0=w;
unsigned char *buf=(unsigned char *)buffer;
/***********填写中间代码**************/
t0=x0/8;
p0=x0%8;
if(p0){
w0-=(8-p0);
if(w0<0){
t1=0;
p1=0;
count=0;
}else{
t1=w0/8;
p1=w0%8;
count=8-p0;
}
}else{
count=0;
t1=w/8;
p1=w%8;
}
ptr=y0*AP+t0+SAD2;
/*设置指针右移*/
ca320240_pr1(CA320240_CSDIR_RIGHT);
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
if(p0){
ca320240_pr1(CA320240_MREAD);
temps=ca320240_pr3();
/*t0++;*/
ptr=y0*AP+t0+SAD2+1;
}
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);
ca320240_pr2((ptr>>8) & 0xff);
/*写入数据*/
ca320240_pr1(CA320240_MWRITE);
for(i=0;i<t1;i++){
/*printf("t1=%d\n",t1);*/
temp_color=0;
for(j=0;j<8;j++){
temp_color<<=1;
if(buf[count++] & 0x1){
temp_color|=1;
}
}
ca320240_pr2(temp_color);
}
if(p1){
ptr=y0*AP+t1+t0+SAD2;
if(p0)ptr++;
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
ca320240_pr1(CA320240_MREAD);
tempe=ca320240_pr3();
}
/**********补充开始字段**********/
i=0;
if(p0){
ptr=y0*AP+t0+SAD2;
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*写入数据*/
ca320240_pr1(CA320240_MWRITE);
i=8-p0;
if(w<i){
i=w;
}
count=0;
for(j=0;j<i;j++){
if(buf[count++] & 0x1){
temps|=v_0[p0+j];
}else{
temps&=v_1[p0+j];
}
}
ca320240_pr2(temps);
}
p0=i;
/**********补充结束字段**********/
if(p1){
ptr=y0*AP+t1+t0+SAD2;
if(p0){
ptr++;
}
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*写入数据*/
ca320240_pr1(CA320240_MWRITE);
i=p1;
count=t1*8+p0+i-1;
tempe<<=i;
for(j=0;j<i;j++){
tempe>>=1;
if(buf[count--] & 0x1){
tempe|=0x80;
}
}
ca320240_pr2(tempe);
}
}
void graphics_putbox(int x,int y,int w,int h,void *buffer)
{
int i;
int x0=x,y0=y;
char *ptr=(char *)buffer;
ca320240_wait_for_write();
for(i=0;i<h;i++){
graphics_putbox_line(x0,y0,w,ptr);
y0++;
ptr+=w;
}
}
void graphics_getbox(int x,int y,int w,int h,void *buffer)
{
int i;
char *buf=buffer;
int x0=x,y0=y;
ca320240_wait_for_write();
for(i=0;i<h;i++){
graphics_getbox_line(x0,y0,w,buf);
buf+=w;
y0++;
}
}
/***********************************************************
写块函数
x---x坐标(0---319)
y---y坐标(0---239)
w---w块宽度(1--320)
h---h块高度(1--240)
buf---buf
************************************************************/
static char h_mask[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
static char l_mask[]={0x00,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
void graphics_hline(int x,int y,int w,int color)
{
int ptr,t0,t1,p0,p1;
unsigned char temp_color,temps=0,tempe=0;
int i;
int x0=x,y0=y;
int x1=x+w,y1=y;
ca320240_wait_for_write();
/***********填写中间代码**************/
t0=x0/8;
t1=x1/8;
p0=x0%8;
p1=x1%8;
ptr=y0*AP+t0+SAD2;
ca320240_pr1(CA320240_CSDIR_RIGHT);
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
if(p0){
ca320240_pr1(CA320240_MREAD);
temps=ca320240_pr3();
t0++;
}
/*写入数据*/
ptr=y0*AP+t0+SAD2;
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
ca320240_pr1(CA320240_MWRITE);
if(color){
temp_color=0xff;
}else{
temp_color=0x00;
}
for(i=t0;i<t1;i++){
ca320240_pr2(temp_color);
}
if(p1){
ptr=y0*AP+t1+SAD2;
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
ca320240_pr1(CA320240_MWRITE);
ca320240_pr1(CA320240_MREAD);
tempe=ca320240_pr3();
}
/**********补充开始字段**********/
if(p0){
ptr=y0*AP+t0+SAD2-1;
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*写入数据*/
ca320240_pr1(CA320240_MWRITE);
if(color){
if(w<(8-p0)){
temps |= (temps | (l_mask[p0] & h_mask[8-((8-p0)-w)]));
}else{
temps=temps | l_mask[p0];
}
}else{
if(w<(8-p0)){
temps=(temps & (h_mask[p0] | l_mask[8-((8-p0)-w)]));
}else{
temps=temps & h_mask[p0];
}
}
ca320240_pr2(temps);
}
/**********补充结束字段**********/
if((p1) && (t0<=t1)){
ptr=y1*AP+t1+SAD2;
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*写入数据*/
ca320240_pr1(CA320240_MWRITE);
if(color){
tempe=tempe | h_mask[p1];
}else{
tempe=tempe & l_mask[p1];
}
ca320240_pr2(tempe);
}
}
void graphics_putbox(int x,int y,int w,int h,void *buffer);
/***********************************************************
画垂直直线函数
x---x坐标(0---319)
y---y坐标(0---239)
h---高度(0----239)
color---颜色
0---LCM_BLACK
1---LCM_WHITE
2---LCM_INVERT
************************************************************/
void graphics_vline(int x,int y,int h,int color)
{
int i;
unsigned char buf[241],temp;
int ptr;
ca320240_wait_for_write();
/*读取数据*/
ptr=y*AP+x/8+SAD2;
temp=1<<(unsigned char)(7-x % 0x8);
/*设置下移*/
ca320240_pr1(CA320240_CSDIR_DOWN);
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*设置读取当前显示的数据*/
ca320240_pr1(CA320240_MREAD);
for(i=0;i<h;i++){
buf[i]=ca320240_pr3();
/*合成数据*/
if(color){
buf[i]|=temp;
}else{
buf[i]&=(~temp);
}
}
/*写入数据*/
/*CSRW*/
ca320240_pr1(CA320240_CSRW);
ca320240_pr2(ptr & 0xff);/*设置指针寄存器低8位*/
ca320240_pr2((ptr>>8) & 0xff);/*设置指针寄存器高8位*/
/*写入当前显示的数据*/
ca320240_pr1(CA320240_MWRITE);
for(i=0;i<h;i++){
ca320240_pr2(buf[i]);
}
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -