📄 mra8806.c
字号:
#include<mra8806.h>
extern uchar code gImage_pic1[];
sbit bWRZ=P3^4;
sbit bRDZ=P3^5;
sbit bCSZ=P3^7;
sbit RS=P1^0;
sbit RST=P1^1;
sbit DATA=P0;
void delay1ms(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void Delay2us(uchar Counter)
{
while(--Counter);
}
void delay100us(uchar Counter)
{
while(Counter--)
{ Delay2us(150);
}
}
unsigned char Read_Status(void)
{
unsigned char temp=0;
RS=1;
bCSZ=0;
bWRZ=1;
bRDZ=0;
temp=P0;
bRDZ=1;
bCSZ=1;
P0=0xff;
RS=0;
return (temp);
}
void Wr_Data(unsigned char Addr,unsigned char Data)
{
RS=1;
bCSZ=0;
bWRZ=0;
bRDZ=1;
P0=Addr;
bWRZ=1;
bCSZ=1;
RS=0;
bCSZ=0;
bWRZ=0;
P0=Data;
bWRZ=1;
bCSZ=1;
RS=1;
P0=0xff;
}
void Wrr_Addr(unsigned char cmd)
{
_nop_();
bCSZ = 0;
RS = 1;
bWRZ = 0;
P0 = cmd;
bWRZ = 1;
bCSZ = 1;
P0 = 0xff;
RS = 0;
}
void Wrr_Data(unsigned char Data)
{
_nop_();
bCSZ = 0;
RS = 0;
bWRZ = 0;
P0 = Data;
bWRZ = 1;
bCSZ = 1;
P0 = 0xff;
RS = 1;
}
unsigned char Read_Data(void)
{
uchar temp;
bWRZ = 1;
bCSZ = 0;
RS = 0;
bRDZ = 0;
temp = P0;
bRDZ = 1;
bCSZ = 1;
RS = 1;
return(temp);
}
void Rst()
{
RST=0;
delay1ms(30);
RST=1;
delay1ms(20);
}
void Lcd_On(void)
{
uchar temp;
Wrr_Addr(WLCR);
temp = Read_Data();
temp |= cSetb2;
Wrr_Addr(WLCR);
Wrr_Data(temp);
}
void Lcd_Graphic(void)
{
unsigned char temp;
temp=0;
Wrr_Addr(0);
temp = Read_Data();
temp &= 0xf7;
Wrr_Addr(0);
Wrr_Data(temp);
}
void Access_2Pages(void)
{
unsigned char temp;
temp=0;
Wrr_Addr(0x12);
temp=Read_Data();
temp|=0x02;
temp|=0x01;
Wrr_Addr(0x12);
Wrr_Data(temp);
}
void Set_Fill_PNTR_to_DDRAM(void)
{
unsigned temp;
temp=0;
Wrr_Addr(0xf0);
temp=Read_Data();
temp|=0x08;
Wr_Data(0xf0,temp);
do{
_nop_();
_nop_();
}while(Read_Status()&0x80);
}
void Lcd_Clear(void)
{
Lcd_Graphic();
//Access_2Pages();
Wr_Data(0xe0,0x00);
Set_Fill_PNTR_to_DDRAM();
}
void Access_Page1(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb1;
temp |= cSetb0;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Access_Page2(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb0;
temp |= cSetb1;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Only_Show_Page1(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp &= cClrb5;
temp |= cSetb4;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Only_Show_Page2(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp &= cClrb4;
temp |= cSetb5;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void Show_Two_Layer(void)
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp |= cSetb5;
temp |= cSetb4;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void LCD_Text(void)
{
uchar temp;
Wrr_Addr(WLCR);
temp = Read_Data();
temp |= cSetb3;
Wrr_Addr(WLCR);
Wrr_Data(temp);
}
void LCD_GotoXY(uchar x, uchar y)
{
Wrr_Addr(CURX);
Wrr_Data(x);
Wrr_Addr(CURY);
Wrr_Data(y);
}
void LCD_FontSize(uchar buf)//15为四倍字体,10为三倍字体,5为两倍字体
{
uchar temp;
buf = buf << 4;
temp = (buf & 0xF0) | (0x0F);
Wrr_Addr(FVHT);
Wrr_Data(temp);
}
void LCD_Inv(void)//写入数据取反显示
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp |= cSetb5;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_NoInv(void)
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp &= cClrb5;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_Bold(void)//显示粗体字
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp |= cSetb4;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_NoBold(void)
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp &= cClrb4;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void Gray_Mode(void)//灰度模式,不支持汉字
{
uchar temp;
Wrr_Addr(MAMR);
temp = Read_Data();
temp &= cClrb6;
temp &= cClrb5;
temp &= cClrb4;
Wrr_Addr(MAMR);
Wrr_Data(temp);
}
void COM_DIR_239_0(void)//扫描模式修改,从239行开始扫描
{
uchar temp;
Wrr_Addr(MISC);
temp = Read_Data();
temp |= cSetb0;
Wrr_Addr(MISC);
Wrr_Data(temp);
}
void LCD_Rotate90(void)//文字旋转90度
{
uchar temp;
Wrr_Addr(WCCR);
temp = Read_Data();
temp |= cSetb3;
Wrr_Addr(WCCR);
Wrr_Data(temp);
}
void LCD_LineDist_Adjust(uchar dis)//文字之间的行间距0-16
{
uchar temp;
Wrr_Addr(CHWI); // Line Distance
temp = Read_Data();
temp &= 0xf0;
temp |= (dis & 0x0f);
Wrr_Addr(CHWI); // Line Distance
Wrr_Data(temp);
}
unsigned char ADC_X1_MSB(void)
{
uchar temp;
Wrr_Addr(TPXR);
temp = Read_Data();
//delay1ms(2);
return temp;
}
unsigned char ADC_Y1_MSB(void)
{
uchar temp;
Wrr_Addr(TPYR);
temp = Read_Data();
//delay1ms(2);
return temp;
}
void Print_Hex(uchar buf)
{
uchar temp1,temp2;
temp1=buf;
temp1 = (temp1 >>4) & 0x0F;
if(temp1 < 0x0A)
{
temp1 |= 0x30;
}
else temp1 = temp1 + 0x37;
//LCD_Text();
//Access_Page1();
//LCD_GotoXY(0x21,0x10);
Wrr_Addr(0xb0);
Wrr_Data(temp1);
//delay1ms(1);
_nop_();
temp2=buf;
temp2 = temp2 & 0x0F;
if(temp2 < 0x0A)
{
temp2 |= 0x30;
}
else temp2 = temp2 + 0x37;
//Wrr_Addr(0xb0);
Wrr_Data(temp2);
_nop_();
}
void Dis_Ratate_90(void)//文字纵向显示
{
LCD_Text();
LCD_Rotate90();
//COM_DIR_239_0();
LCD_LineDist_Adjust(12);
LCD_GotoXY(0,48);
Wrr_Addr(0xb0);
/*for(i=0;i<29;i++)
{
Wrr_Data(sRAiO1[i]);
delay1ms(1);
}*///因为srai01在vuse.h中,所以屏蔽此处。
}
void test(void)
{
int i;
Lcd_Graphic();
Gray_Mode();
LCD_GotoXY(0x00,0x0);
Wrr_Addr(0xb0);
/*Mode2();
Mode3();
Mode4();*/
for(i=0;i<4800;i++)
{
Wrr_Data(0);
}
for(i=0;i<4800;i++)
{
Wrr_Data(0x55);
}
for(i=0;i<4800;i++)
{
Wrr_Data(0xaa);
}
for(i=0;i<4800;i++)
{
Wrr_Data(0xff);
}
}
/*====================================================
; 绘点子程序 ,att为1时为描点,为0时为消点
====================================================*/
void Dis_Point(unsigned int px, uchar py,uchar att)
{
uchar x_msb,value,ex_value;
//value = 0x80;
//Lcd_Graphic();
//Access_Page1();
//Only_Show_Page1();
x_msb = px>>3;//等于px除以8
//x_lsb = px & 0x07;//等于py对8求余数
//value = value>>x_lsb;
value = 1<<(7-px & 0x0007);
LCD_GotoXY(x_msb,py);
Wrr_Addr(0xb1);
ex_value = Read_Data();
if(att)
ex_value |= value;
else
//value = (~value);
ex_value &= ~value;
LCD_GotoXY(x_msb,py);
Wrr_Addr(0xb0);
Wrr_Data(ex_value);
}
/*void Dis_Black_Rec(uchar a,uchar b,uchar c,uchar d,uchar att)
{
uchar i,j,length,height;
length = c-a;
height = d-b;
Access_Page1();
Only_Show_Page1();
//LCD_Text();
Lcd_Graphic();
LCD_GotoXY(a,b);
for(i=0;i<height;i++)
{
LCD_GotoXY(a,(b+i));
Wrr_Addr(0xb0);
for(j=0;j<length;j++)
Wrr_Data(0xff);
}
}
void Dis_Black_Rec(uchar a,uchar b,uchar c,uchar d,uchar att)
{
uchar i,j,length,height;
length = c-a;
height = d-b;
Access_Page1();
Only_Show_Page1();
//LCD_Text();
Lcd_Graphic();
for(i=0;i<height;i++)
{
for(j=0;j<length;j++)
Dis_Point((a+i),(b+j),att);
}
}*/
void Dis_Blank_Rec(uchar a,uchar b,uchar c,uchar d)
{
uchar i,length,height;
length = c-a;
height = d-b;
//Access_Page1();
//Only_Show_Page1();
//LCD_Text();
Lcd_Graphic();
LCD_GotoXY(a,b);
Wrr_Addr(0xb0);
for(i=0;i<length;i++)
{
Wrr_Data(0xff);
}
LCD_GotoXY(a,(b+height));
Wrr_Addr(0xb0);
for(i=0;i<length;i++)
{
Wrr_Data(0xff);
}
for(i=1;i<height;i++)
{
LCD_GotoXY((c-1),(b+i));
Wrr_Addr(0xb0);
Wrr_Data(0x01);
}
for(i=1;i<height;i++)
{
LCD_GotoXY(a,(b+i));
Wrr_Addr(0xb0);
Wrr_Data(0x80);
}
}
/*void Dis_Blank_Rec(uchar a,uchar b,uchar c,uchar d,uchar att)
{
uchar i,j,length,height;
length = c-a;
height = d-b;
Access_Page1();
Only_Show_Page1();
//LCD_Text();
Lcd_Graphic();
for(i=0;i<height;i++)
{
for(j=0;j<length;j++)
{
Dis_Point((a+j),b,att);
Dis_Point(a,(b+i),att);
Dis_Point((c-1),(b+i),att);
Dis_Point((a+j),d,att);
}
}
}*/
/************************************************/
/*画圆。数学方程(X-Ox)^2+(Y-Oy)^2=Rx^2 */
/************************************************/
void Dis_Circle(unsigned int Ox,uchar Oy,uchar Rx,uchar att)
{
unsigned int xx,rr,xt,yt,rs,col,row;
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--;
col=Ox+xt; //第一象限
row=Oy-yt;
Dis_Point(col,row,att);
col=Ox-xt; //第二象限
Dis_Point(col,row,att);
row=Oy+yt; //第三象限
Dis_Point(col,row,att);
col=Ox+xt; //第四象限
Dis_Point(col,row,att);
/***************45度镜象画另一半***************/
col=Ox+yt; //第一象限
row=Oy-xt;
Dis_Point(col,row,1);
col=Ox-yt; //第二象限
Dis_Point(col,row,1);
row=Oy+xt; //第三象限
Dis_Point(col,row,att);
col=Ox+yt; //第四象限
Dis_Point(col,row,att);
}
}
/********************************************/
/*画线。任意方向的斜线,直线数学方程 aX+bY=1 */
/********************************************/
// 参数类型有待修改
void Dis_Linexy(unsigned int x0,uchar y0,unsigned int xt,uchar yt,uchar att)
{
int t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy;
unsigned int row,col;
Lcd_Graphic();
delta_x = xt-x0; //计算坐标增量
delta_y = yt-y0;
col = x0;
row = y0;
if(delta_x>0) incx=1; //设置单步方向
else
{
if( delta_x==0 ) incx=0; //垂直线
else {incx=-1;delta_x=-delta_x;}
}
if(delta_y>0) incy=1;
else
{
if( delta_y==0 ) incy=0; //水平线
else {incy=-1;delta_y=-delta_y;}
}
if( delta_x > delta_y ) distance=delta_x; //选取基本增量坐标轴
else distance=delta_y;
for( t=0;t <= distance+1; t++ )
{ //画线输出
Dis_Point((unsigned int)col,row,att); //画点
xerr += delta_x ;
yerr += delta_y ;
if( xerr > distance )
{
xerr-=distance;
col+=incx;
}
if( yerr > distance )
{
yerr-=distance;
row+=incy;
}
}
}
void Dis_Text(uchar px,uchar py,uchar count,uchar scale,uchar *p)
{
uchar i;
//Access_Page1();
//Only_Show_Page1();
LCD_Text();
LCD_FontSize(scale);
LCD_GotoXY(px,py);
Wrr_Addr(0xb0);
for(i=0;i<count;i++)
{
Wrr_Data(p[i]);
delay1ms(5);
}
/*LCD_GotoXY(0,16);
Wrr_Addr(0xb0);
for(i=0;i<40;i++)
{
Wrr_Data(sRAiO2[i]);
delay1ms(1);
}
LCD_Inv();
Wrr_Addr(0xb0);
for(i=0;i<21;i++)
{
Wrr_Data(sRAiO3[i]);
delay1ms(1);
}
LCD_NoInv();
LCD_GotoXY(0,64);
Wrr_Addr(0xb0);
for(i=0;i<40;i++)
{
Wrr_Data(sRAiO2[i]);
delay1ms(1);
}
LCD_FontSize(15);
LCD_GotoXY(0,80);
Wrr_Addr(0xb0);
for(i=0;i<12;i++)
{
Wrr_Data(sRAiO5[i]);
delay1ms(5);
}
LCD_FontSize(0);
LCD_GotoXY(0,160);
Wrr_Addr(0xb0);
for(i=0;i<40;i++)
{
Wrr_Data(i);
delay1ms(1);
}
LCD_Bold();
Wrr_Addr(0xb0);
for(i=40;i<80;i++)
{
Wrr_Data(i);
delay1ms(1);
}
/*LCD_NoBold();
Wrr_Addr(0xb0);
for(i=40;i<120;i++)
{
Wrr_Data(i);
delay1ms(1);
}*/
}
void Dis_DDRAM1_Pic(void)
{
int i;
Access_Page1();
//Only_Show_Page1();
Lcd_Graphic();
LCD_GotoXY(0,0);
Wrr_Addr(0xb0);
for(i=0;i<1120;i++)
Wrr_Data(gImage_pic1[i]);
do{
_nop_();
_nop_();
}while(Read_Status()&0x80);
}
void Dis_Pos_Pic(uchar px,uchar py,uint width,uchar height,uchar *p)
{
uchar i,j,count;
count = width>>3;
//Access_Page1();
//Only_Show_Page1();
Lcd_Graphic();
for(i=0;i<height;i++)
{
LCD_GotoXY(px,(py+i));
Wrr_Addr(0xb0);
for(j=0;j<count;j++)
//Wrr_Data(gImage_pic1[(i*count+j)]);
Wrr_Data(p[i*count+j]);
}
}
/*void Dis_DDRAM2_Pic(void)
{
int i;
Access_Page2();
//Only_Show_Page2();
Lcd_Graphic();
LCD_GotoXY(0,0);
Wrr_Addr(0xb0);
for(i=0;i<9600;i++)
Wrr_Data(gImage_pic2[i]);
do{
_nop_();
_nop_();
}while(Read_Status()&0x80);
}*/
void Initiate(void)
{
Wr_Data(0,0);
_nop_();
Wr_Data(1,4);
_nop_();
Wr_Data(3,0);
_nop_();
Wr_Data(0x0f,0);
_nop_();
Wr_Data(0x10,0);
_nop_();
Wr_Data(0x11,0);
_nop_();
Wr_Data(0x12,0x11);
_nop_();
Wr_Data(0x20,0x27);
_nop_();
Wr_Data(0x21,0x27);
_nop_();
Wr_Data(0x30,0xef);
_nop_();
Wr_Data(0x31,0xef);
_nop_();
Wr_Data(0x40,0);
_nop_();
Wr_Data(0x50,0);
_nop_();
Wr_Data(0x60,0);
_nop_();
Wr_Data(0x61,0);
_nop_();
Wr_Data(0x62,0);
_nop_();
Wr_Data(0x70,0);
_nop_();
Wr_Data(0x71,0);
_nop_();
Wr_Data(0x72,0);
_nop_();
Wr_Data(0x80,0);
_nop_();
Wr_Data(0x90,0);
_nop_();
Wr_Data(0xa0,0);
_nop_();
Wr_Data(0xa1,0);
_nop_();
Wr_Data(0xa2,0);
_nop_();
Wr_Data(0xa3,0);
_nop_();
Wr_Data(0xa4,0);
_nop_();
Wr_Data(0xc0,0);
_nop_();
Wr_Data(0xc1,0);
_nop_();
Wr_Data(0xc2,0);
_nop_();
Wr_Data(0xc3,0);
_nop_();
Wr_Data(0xc4,0);
_nop_();
Wr_Data(0xd0,0);
Wr_Data(0xd1,0);
_nop_();
Wr_Data(0xe0,0);
_nop_();
Wr_Data(0xf0,0);
_nop_();
Wr_Data(0xf1,0);
_nop_();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -