text_fun.c

来自「液晶MGLS2401128TA的控制程序」· C语言 代码 · 共 556 行

C
556
字号



#include <AT89X51.H>

#include <intrins.h>
#include <math.h>
#define DATA_PORT P0

sbit WR_PORT=P2^0 ;
sbit RD_PORT=P2^1 ;
sbit CE_PORT=P2^2 ;
sbit CD_PORT=P2^3 ;


code unsigned char tab2[][32]=
{
    0x04,0x80,0x0E,0xA0,0x78,0x90,0x08,0x90,0x08,0x84,0xFF,0xFE,0x08,0x80,0x08,0x90,
    0x0A,0x90,0x0C,0x60,0x18,0x40,0x68,0xA0,0x09,0x20,0x0A,0x14,0x28,0x14,0x10,0x0C,
    /*以上为"我"的点阵*/
    0x00,0x00,0x00,0x04,0x7F,0xFE,0x40,0x04,0x40,0x44,0x47,0xE4,0x44,0x44,0x44,0x44,
    0x44,0x44,0x44,0x44,0x47,0xC4,0x44,0x44,0x40,0x04,0x7F,0xFC,0x40,0x04,0x00,0x00,
    /*以上为"回"的点阵*/
    0x01,0x00,0x01,0x00,0x01,0x08,0x7F,0xFC,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x04,
    0xFF,0xFE,0x02,0x00,0x02,0x00,0x04,0x40,0x08,0x20,0x10,0x10,0x3F,0xF8,0x00,0x08,
    /*以上为"去"的点阵*/
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFF,0xFE,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    /*以上为"一"的点阵*/
    0x00,0x04,0xFF,0xFE,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x80,0x02,0x40,0x02,0x30,
    0x02,0x10,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,
    /*以上为"下"的点阵*/
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    /*以上为"—"的点阵*/
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    /*以上为"—"的点阵*/
    0x04,0x40,0x04,0x48,0x7F,0xFC,0x04,0x40,0x04,0x50,0x1F,0xF8,0x10,0x10,0x1F,0xF0,
    0x10,0x10,0x1F,0xF0,0x01,0x04,0xFF,0xFE,0x01,0x00,0x02,0x80,0x0C,0x60,0x70,0x1C,
    /*以上为"莫"的点阵*/
    0x08,0x40,0x1C,0x40,0xF0,0xFC,0x11,0x84,0x12,0x48,0xFC,0x30,0x10,0x60,0x39,0xA0,
    0x34,0x3E,0x54,0x42,0x90,0xC4,0x11,0x24,0x10,0x18,0x10,0x30,0x10,0xC0,0x17,0x00,
    /*以上为"移"的点阵*/
    0x10,0xA0,0x10,0xA0,0x10,0xA4,0x11,0x28,0xFD,0x30,0x13,0x60,0x35,0xA4,0x39,0x1C,
    0x55,0x40,0x50,0x44,0x97,0xFE,0x10,0x40,0x10,0x40,0x10,0x40,0x10,0x40,0x10,0x40,
    /*以上为"桦"的点阵*/
    
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,0x10,0x00,0x20,0x00,0x00,0x00,0x00,0x00,
    /*以上为","的点阵*/
    0x11,0x00,0x11,0x00,0x11,0x00,0x23,0xFC,0x22,0x04,0x64,0x08,0xA8,0x40,0x20,0x40,
    0x21,0x50,0x21,0x48,0x22,0x4C,0x24,0x44,0x20,0x40,0x20,0x40,0x21,0x40,0x20,0x80,
    /*以上为"你"的点阵*/
    0x01,0x00,0x11,0x00,0x11,0x10,0x1F,0xF8,0x11,0x00,0x21,0x00,0x01,0x04,0xFF,0xFE,
    0x04,0x80,0x04,0x80,0x04,0x80,0x08,0x80,0x08,0x82,0x10,0x82,0x20,0x7E,0x40,0x00,
    /*以上为"先"的点阵*/
    0x10,0x20,0x12,0x20,0x12,0x20,0x22,0x24,0x3F,0xFE,0x62,0x84,0xA2,0x44,0x22,0x44,
    0x2F,0xC8,0x28,0xA8,0x28,0xA8,0x28,0x90,0x28,0xA8,0x2F,0xA8,0x28,0x46,0x20,0x84,
    /*以上为"做"的点阵*/
    0x01,0x04,0x3F,0x84,0x21,0x04,0x21,0x24,0x21,0x24,0x3F,0x24,0x28,0x24,0x09,0x24,
    0xFF,0xA4,0x09,0x24,0x09,0x24,0x11,0x24,0x11,0x04,0x25,0x04,0x42,0x14,0x00,0x08,
    /*以上为"别"的点阵*/
    0x10,0x40,0x10,0x40,0x22,0x44,0x7F,0x7E,0x42,0x84,0x43,0x04,0x42,0x04,0x42,0x84,
    0x7E,0x64,0x42,0x24,0x42,0x04,0x42,0x04,0x42,0x04,0x7E,0x04,0x42,0x28,0x00,0x10,
    /*以上为"的"的点阵*/
    0x00,0x00,0x01,0x80,0x03,0xC0,0x03,0xC0,0x03,0xC0,0x01,0x80,0x01,0x80,0x01,0x80,
    0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x01,0x80,0x00,0x00,0x00,0x00,
    /*以上为"!"的点阵*/
0x08,0x40,0x08,0x40,0x0A,0x44,0x7F,0x7E,0x08,0x88,0x3F,0x08,0x08,0x48,0xFF,0x48,
0x10,0x48,0x1E,0x50,0x12,0x50,0x22,0x20,0x22,0x50,0x54,0x88,0x89,0x0E,0x02,0x04,
/*以上为"敖"的点阵*/
0x10,0x10,0x08,0x20,0x04,0x40,0x00,0x10,0x1F,0xF8,0x10,0x10,0x10,0x10,0x10,0x10,
0x1F,0xF0,0x10,0x10,0x02,0x00,0x51,0x84,0x50,0x92,0x90,0x12,0x0F,0xF0,0x00,0x00,
/*以上为"总"的点阵*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
/*以上为":"的点阵*/
}
;



//-------------delay the time---------//
//50us
void delay(unsigned int a)
{
    unsigned int i,j ;
    for(i=0;i<a;i++)
    for(j=0;j<6;j++);
}

//--------- LGD Read the Appearance from the lGD-------------//
unsigned char read_Appearance(void)
{
    unsigned char temp ;
    CE_PORT=1 ;
    DATA_PORT=0XFF ;
    CE_PORT=0 ;
    CD_PORT=1 ;
    //READ CODE
    RD_PORT=0 ;
    temp=DATA_PORT ;
    RD_PORT=1 ;
    CE_PORT=1 ;
    //del the  Total line
    return temp ;
}

//--------LGD STA0-STA1--------//
bit st00_st01(void)
{
    unsigned char temp ;
    temp=read_Appearance();
    temp=temp&0x03 ;
    
    if(temp==0x03)return 1 ;
    
    return 0 ;
    
}



//----------LGD STA3--------//
bit st03(void)
{
    unsigned char temp ;
    temp=read_Appearance();
    temp=temp&0x08 ;
    
    if(temp==0x08)return 1 ;
    
    return 0 ;
    
}
/*
//----------LGD STA2--------//
bit st02(void)
{
	unsigned char temp;
temp=read_Appearance();
temp=temp&0x04;

if(temp==0x04)return 1;

return 0;

}

//---------LGD STA5--------//
bit st05(void)
{
unsigned char temp;
temp=read_Appearance();
temp=temp&0x20;

if(temp==0x20)return 1;

return 0;

}

//--------LGD STA6--------//
bit st06(void)
{unsigned char temp;
temp=read_Appearance();
temp=temp&0x40;

if(temp==0x40)return 1;

return 0;

}

//--------LGD STA7-------//
bit st07(void)
{
unsigned char temp;
temp=read_Appearance();
temp=temp&0x80;

if(temp==0x80)return 1;

return 0;


}

*/
//---------read data from the lgd--------//
unsigned char read_from(void)
{unsigned char temp;

	while(st00_st01()==0);
	CE_PORT=0;
	CD_PORT=0;//data 
	RD_PORT=0;	
	//temp1=DATA_PORT;
	temp=DATA_PORT;	
	RD_PORT=1;
	CE_PORT=1;
	return temp;
}

//------- Write 2 Number and 1 CODE to LCM ---------//
void write_2_code(unsigned char a,unsigned char b,unsigned char c)
{
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=0 ;
    //data 	
    DATA_PORT=a ;
    WR_PORT=0 ;
    _nop_();
    WR_PORT=1 ;
    CE_PORT=1 ;
    
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=0 ;
    //data 
    DATA_PORT=b ;
    WR_PORT=0 ;
    _nop_();
    WR_PORT=1 ;
    CE_PORT=1 ;
    
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=1 ;
    //code 
    DATA_PORT=c ;
    WR_PORT=0 ;
    _nop_();
    WR_PORT=1 ;
    CE_PORT=1 ;
    
}
//---------write 1 data and 1 code  to the Lcm------//
void write_1_code(unsigned char a,unsigned char c)
{
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=0 ;
    //data 
    DATA_PORT=a ;
    WR_PORT=0 ;
    _nop_();
    WR_PORT=1 ;
    CE_PORT=1 ;
    
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=1 ;
    //code 
    DATA_PORT=c ;
    WR_PORT=0 ;
    _nop_();
    WR_PORT=1 ;
    CE_PORT=1 ;
    
}
//---------write 1 code to Lcm--------//
void write_code(unsigned char c)
{
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=1 ;
    //code 
    DATA_PORT=c ;
    WR_PORT=0 ;
    _nop_();
    WR_PORT=1 ;
    CE_PORT=1 ;
}


//-----------write data to lgd---------//
void write_to(unsigned char a)
{
    while(st00_st01()==0);
    CE_PORT=0 ;
    CD_PORT=0 ;
    //data 
    DATA_PORT=a ;
    WR_PORT=0 ;
    WR_PORT=1 ;
    CE_PORT=1 ;
}

//---------- START THE LGD-----------//
void lcm_start(void)
{
    //----setting the text head addr--------//
    write_2_code(0x00,0x00,0x21);
    //the light mark start
    write_2_code(0x00,0x00,0x40);
    //text start
    
    write_2_code(0x1e,0x00,0x41);
    //text with
    
    write_2_code(0x00,0x00,0x42);
    //graph start
    
    write_2_code(0x1e,0x00,0x43);
    //graph with
    
    write_code(0xa1);
    //the light mark look like
    
    write_code(0x80);
    // the text or graph
    
    write_code(0x98);
    //the show like
    
}

//--------------CLS THE LCM-----------------//
void cls_lcm(void)
{
    unsigned int i ;
    
    write_2_code(0x00,0x00,0x24);
    write_code(0xb0);
    for(i=0;i<5888;i++)
    {
        while(st03()==0);
        write_to(0x00);
        
    }
    write_code(0xb2);
}



void chinese_show(unsigned char lin,unsigned char column,unsigned int hzcode)
{
    unsigned char i ;
    unsigned int startaddr ;
    startaddr=(lin)*30+column ;
    for(i=0;i<16;i++)
    {
        write_2_code((unsigned char)(startaddr),(unsigned char)(startaddr>>8),0x24);
        write_1_code(tab2[hzcode][i*2],0xc0);
        write_1_code(tab2[hzcode][i*2+1],0xc4);
        startaddr=startaddr+30 ;
    }
    
}

void show_pixel(unsigned int x,unsigned int y,bit mode)
{
    unsigned int startaddr=0 ;
    unsigned char dat ;
    startaddr=x*30+y/8 ;
    dat=0xf0+7-y%8 ;
    if(mode)dat=dat|0x08 ;
    write_2_code((unsigned char)(startaddr),(unsigned char)(startaddr>>8),0x24);
    
    write_code(dat);
}

void show_line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit mode)
{
    unsigned char x,y ;
    double k,b ;
    if(abs(y1-y2)<=abs(x1-x2))
    {
        k=(float)(y2-y1)/(float)(x2-x1);
        b=y1-k*x1 ;
        if(x1<=x2)
        {
            for(x=x1;x<=x2;x++)
            {
                y=k*x+b ;
                show_pixel(x,y,mode);
            }
        }
        else 
        {
            
            for(x=x2;x<=x1;x++)
            {
                y=k*x+b ;
                show_pixel(x,y,mode);
            }
        }
        
        
    }
    else 
    {
        
        k=(float)(x2-x1)/(float)(y2-y1);
        b=x1-k*y1 ;
        if(y1<=y2)
        {
            for(y=y1;y<=y2;y++)
            {
                x=k*y+b ;
                show_pixel(x,y,mode);
            }
        }
        else 
        {
            
            for(y=y2;y<=y1;y++)
            {
                x=k*y+b ;
                show_pixel(x,y,mode);
            }
        }
    }
}

void circle(unsigned char x0,unsigned char y0,unsigned char Rx, bit s)
{
	unsigned int xx,rr,xt,yt,rs,row,col;
	yt=Rx;
	rr=Rx*Rx+1;			//补偿 1 修正方形
	rs=(yt+(yt>>1))>>1;		//(*0.75)分开1/8圆弧来画
	for (xt=0;xt<=rs;xt++)
	{
		xx=xt*xt;
		while ((yt*yt)>(rr-xx))yt--;
		row=x0+xt;		//第一象限
		col=y0-yt;
		show_pixel(row,col,s);
		row=x0-xt;		//第二象限
		show_pixel(row,col,s);
		col=y0+yt;		//第三象限
		show_pixel(row,col,s);
		row=x0+xt;		//第四象限
		show_pixel(row,col,s);

/***************45度镜象画另一半***************/

		row=x0+yt;		//第一象限
		col=y0-xt;
		show_pixel(row,col,s);
		row=x0-yt;		//第二象限
		show_pixel(row,col,s);
		col=y0+xt;		//第三象限
		show_pixel(row,col,s);
		row=x0+yt;		//第四象限
		show_pixel(row,col,s);
	}
}

//--------to draw the square in the lcm--------------//
void draw_Square(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit mode)
{
unsigned char ii,jj;
unsigned int startaddr ;
    startaddr=(y1)*30+x1 ;
for(jj=0;jj<abs(y2-y1);jj++)
	{
write_2_code((unsigned char)(startaddr),(unsigned char)(startaddr>>8),0x24);
for(ii=0;ii<abs(x2-x1);ii++)
		{
		if(mode)
	 write_1_code(0xff,0xc0);
	 else write_1_code(0x00,0xc0);
		}
startaddr+=30;
    }


}

//----------the function is -----------//
void draw_NO_Square(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit mode)
{
show_line(x1,y1,x2,y1,mode);
show_line(x2,y1,x2,y2,mode);
show_line(x1,y2,x2,y2,mode);
show_line(x1,y1,x1,y2,mode);
}
//-----------draw the ascii anti----//
void ASCII_Anti(unsigned char lin,unsigned char column)
{
unsigned char temp;
unsigned int startaddr;
unsigned char ii;
startaddr=lin*30+column;
for(ii=0;ii<16;ii++)
{
write_2_code((unsigned char)(startaddr),(unsigned char)(startaddr>>8),0x24);

write_code(0xc5);
temp=read_from();
temp=~temp;
write_1_code(temp,0xc0);

startaddr+=30;
}
}

//---------the function is chang the chinese to anti----------//
void chinese_anti(unsigned char lin,unsigned char column)
{
ASCII_Anti(lin,column);
ASCII_Anti(lin,column+1);
}


void login(void)
{
//unsigned char ii,jj;

draw_Square(10,30,30,100,1);
draw_Square(15,60,27,80,0);

}
//-----------text the function--------------------//
void text(void)
{
    show_line(60,20,60,210,1);
    
	chinese_show(8,0,17);
    chinese_show(8,2,18);
    chinese_show(8,4,19);
	
	chinese_show(40,2,0);
    chinese_show(40,4,1);
    chinese_show(40,6,2);
    chinese_show(40,8,3);
    chinese_show(40,10,4);
    
    
    chinese_show(40,12,10);
    chinese_show(40,14,11);
    chinese_show(40,16,12);
    chinese_show(40,18,13);
    chinese_show(40,20,14);
    chinese_show(40,22,15);
    chinese_show(40,24,16);
    
    chinese_show(96,18,5);
    chinese_show(96,20,6);
    chinese_show(96,22,7);
    chinese_show(96,24,8);
    chinese_show(96,26,9);
	circle(95,50,22,1);
	circle(85,45,7,1);
	circle(85,60,7,1);
	circle(110,55,4,1);
	draw_Square(5,10,10,20,0);
	draw_NO_Square(60,20,30,210,1);
chinese_anti(96,26);
login();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?