📄 osd.c
字号:
//character color,normal mode and extended graphics mode
uchar X_position,Y_position;
#define Y_to_Y_space 0x10 //主屏行间距设定,最大值为15
#define C_COLOR_BLACK 0x00 //color mode
#define C_COLOR_BLUE 0x01
#define C_COLOR_RED 0x02
#define C_COLOR_MAGENTA 0x03
#define C_COLOR_GREEN 0x04
#define C_COLOR_CYAN 0x05
#define C_COLOR_YELLOW 0x06
#define C_COLOR_WHITE 0x07
/*
#define C_COLOR_GRAY0 0x00 //Monochrome mode,black
#define C_COLOR_GRAY1 0x10
#define C_COLOR_GRAY2 0x20
#define C_COLOR_GRAY3 0x30
#define C_COLOR_GRAY4 0x40
#define C_COLOR_GRAY5 0x50
#define C_COLOR_GRAY6 0x60
#define C_COLOR_GRAY7 0x70 //white
//background color,normal mode
#define B_COLOR_BLACK 0x00 //color mode
#define B_COLOR_BLUE 0x01
#define B_COLOR_RED 0x02
#define B_COLOR_MAGENTA 0x03
#define B_COLOR_GREEN 0x04
#define B_COLOR_CYAN 0x05
#define B_COLOR_YELLOW 0x06
#define B_COLOR_WHITE 0x07
#define B_COLOR_GRAY0 0x00 //Monochrome mode,black
#define B_COLOR_GRAY1 0x01
#define B_COLOR_GRAY2 0x02
#define B_COLOR_GRAY3 0x03
#define B_COLOR_GRAY4 0x04
#define B_COLOR_GRAY5 0x05
#define B_COLOR_GRAY6 0x06
#define B_COLOR_GRAY7 0x07 //white
#define Standard 0x00 //font size set
#define Double_W 0x01 //双倍宽
#define D_W_D_H 0x02 //双倍宽双倍高
#define DD_W_D_H 0x03 //四倍宽双倍高
#define D_H 0x07 //双倍高
*/
//Synchronization control
#define SYN_INTERNAL 0x00
#define SYN_EXTERNAL 0x04
//#define DEMO_SUM 0x07
//sbit CS = P1^4; //demo port
//sbit CLK = P1^5;
//sbit SIN = P1^6;
sbit CS=P1^0; //My board
sbit CLK=P1^1;
sbit SIN=P1^2;
//sbit EXT = P3^3;
//sbit INT = P3^5;
//sbit MODE = P3^2;
sbit ACC_0=ACC^0;
void Delay_ms(uint ms);
void MB90092_WriteByte(uchar _data);
void MB90092_ClearXY(uchar x,uchar y);
void MB90092_ClearRow(uchar y);
void MB90092_ClearScreen();
void MB90092_DisColor(uchar y);
void MB90092_DisChar(uchar x,uchar y,int addr,uchar mul,uchar bc,uchar cc,uchar ff);
void MainScreen_Init(uchar bc);
uchar synchronization=SYN_EXTERNAL; //,demo_choice=0;
/*********************************************************************************************************
** 函数名称: Delay_ms
** 功能描述: 延时ms毫秒
********************************************************************************************************/
void Delay_ms (uint ms)
{
uint i,j,k;
for(k=0; k<ms; k++)
for(i=48; i>0; i--)
for(j=10; j>0; j--);
}
/*********************************************************************************************************
** 函数名称: MB90092_WriteByte
** 功能描述: 向MB90092 写一个字节数据
********************************************************************************************************/
void MB90092_WriteByte(uchar _data)
{
char i;
ACC=_data;
CS=0;
for(i=8;i>0;i--)
{
CLK=0;
SIN=ACC_0;
_nop_();
ACC>>=1;
_nop_();
CLK=1;
}
CS=1;
}
/*********************************************************************************************************
** 函数名称: MB90092_ClearXY
** 功能描述: 清掉屏幕上面坐标(x,y)处的字符,y=0x00~0x0B and x=0x00~0x17 for main screen
********************************************************************************************************/
void MB90092_ClearXY(uchar x,uchar y)
{
uchar byte1,byte2;
if (x>0x17||y>0x0B) return; //invalid col number or row number
byte1=((y>>2)&0x3)+0x80;
byte2=((y<<5)&0x60)+x;
MB90092_WriteByte(byte1); //command 0,设置写入地址,行和列
MB90092_WriteByte(byte2);
MB90092_WriteByte(0x88); //command1-1,定义字符颜色,背景颜色
MB90092_WriteByte(0x00);
MB90092_WriteByte(0x90|(0xff>>7)); //command2-1,写入一个空格字符,地址62为空格符点阵
MB90092_WriteByte(0xff%128);
}
/*********************************************************************************************************
** 函数名称: MB90092_ClearRow
** 功能描述: 清掉屏幕上面的第y行字符,y=0x00~0x0B for main screen
********************************************************************************************************/
void MB90092_ClearRow(uchar y)
{
uchar x;
if (y>0x0B) return; //invlid row number
for (x=0;x<0x18;x++)
MB90092_ClearXY(x,y);
}
/*********************************************************************************************************
** 函数名称: MB90092_ClearScreen
** 功能描述: 清屏
********************************************************************************************************/
void MB90092_ClearScreen()
{
uchar i;
for (i=0;i<0x0C;i++)
MB90092_ClearRow(i);
}
/*********************************************************************************************************
** 函数名称: MB90092_DisColor
** 功能描述: MB90092颜色初始化
********************************************************************************************************/
void MB90092_DisColor(uchar y)
{
uchar temp1,temp2;
temp1=((y>>2)&0x3)+0x84;
temp2=((y<<5)&0x60)+1;
MB90092_WriteByte(temp1); //command 0,设置写入地址,行和列
MB90092_WriteByte(temp2);
MB90092_WriteByte(0x88); //ff控制是否特显
MB90092_WriteByte(0x09); //command1-1,设置字符颜色,背景颜色
MB90092_WriteByte(0x90); //command2-1,设置字符点阵在外rom的地址
MB90092_WriteByte(0x39);
}
/*********************************************************************************************************
** 函数名称: MB90092_DisChar
** 功能描述: 在屏幕坐标(x,y)处显示一个字符,该字符的点阵存储地址为addr,为一24x32的矩形区域
** 参 数: x,y为屏幕坐标,addr为字符点阵在外rom的存储地址,mul为字符尺寸,bc为字符背景颜色,
cc为字符颜色,ff控制是否特显.
********************************************************************************************************/
void MB90092_DisChar(uchar x,uchar y,int addr,uchar mul,uchar bc,uchar cc,uchar ff)
{
uchar temp1,temp2,color;
// if (x>0x17||y>0x0B) return; //invalid col number or row number
temp1=y;
temp1=((temp1>>2)&0x3)+0x80;
temp2=y;
temp2=((temp2<<5)&0x60)+x;
MB90092_WriteByte(temp1); //command 0,设置写入地址,行和列
MB90092_WriteByte(temp2);
MB90092_WriteByte(0xB0|mul); //command 6,mul->字符尺寸控制(datasheel82),设置一整行
MB90092_WriteByte(0x20|y);
if (synchronization==SYN_EXTERNAL){
cc=7;
bc=0;
}
color=((cc<<4)&0x70)|bc;
MB90092_WriteByte(0x88|ff); //ff控制是否特显
MB90092_WriteByte(color); //command1-1,设置字符颜色,背景颜色
MB90092_WriteByte(0x90|(addr>>7)); //command2-1,设置字符点阵在外rom的地址
MB90092_WriteByte(addr%128);
}
void MainScreen_Init(uchar bc)
{
uchar i;
// uchar temp_d1,temp_d2;
CLK=1; //sclk_H
Delay_ms(10);
CS=0;
Delay_ms(10); //程序开始时,要输入CS四次去清除上电复位,然后所作的设置才是有效的。
CS=1;
Delay_ms(10);
CS=0;
Delay_ms(10);
CS=1;
Delay_ms(10);
CS=0;
Delay_ms(10);
CS=1;
Delay_ms(10);
CS=0;
Delay_ms(10);
CS=1;
Delay_ms(10);
MB90092_WriteByte(0xA0); //------command 4---------内同步
MB90092_WriteByte(0x00);
MB90092_WriteByte(0xAA); //command 5
MB90092_WriteByte(Y_to_Y_space); //垂直间距设定,KID=0;APC与颜色有关;GYZ=0;W3--W0为行间距;10101 KID APC GYZ0 BH2 BH1 BH0 W3 W2 W1 W0
MB90092_WriteByte(0xB9); //command 7
MB90092_WriteByte(Y_position); //垂直开始位置设定
MB90092_WriteByte(0xC0); //command 8
MB90092_WriteByte(X_position); //水平开始位置设定
//-------
MB90092_WriteByte(0x9c); //fill
MB90092_WriteByte(0x00);
//-------
MB90092_WriteByte(0xC8); //command 9,GRM位"0"设置普通模式
MB90092_WriteByte(0x00);
MB90092_WriteByte(0xD1); //command 10,设置闪烁,字符背景,字符单色/彩色,背景单色/彩色
MB90092_WriteByte(0x38|bc);
MB90092_WriteByte(0xA2|synchronization);//command 4,内/外同步选择
MB90092_WriteByte(0x2B);
for (i=0;i<0x0B;i++)
MB90092_DisColor(i);
MB90092_ClearScreen();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -