📄 mbb.c
字号:
0x11,0x20,0x12,0x24,0x12,0x24,0x14,0x1C,0x10,0x00,0x28,0x00,0x47,0xFE,0x00,0x00,
};
/*-- 文字: 毫 --*/
unsigned char code char_haoo[] ={
0x01,0x00,0x7F,0xFE,0x00,0x00,0x0F,0xF0,0x08,0x10,0x0F,0xF0,0x00,0x00,0x7F,0xFE,
0x40,0x04,0x0F,0xE0,0x01,0x00,0x1F,0xF0,0x01,0x00,0x3F,0xFA,0x01,0x02,0x00,0xFE,
};
/*-- 文字: 米 --*/
unsigned char code char_mi[] ={
0x01,0x00,0x21,0x08,0x11,0x08,0x09,0x10,0x09,0x20,0xFF,0xFE,0x05,0x80,0x05,0x40,
0x09,0x40,0x09,0x20,0x11,0x20,0x11,0x18,0x21,0x0E,0x41,0x04,0x81,0x00,0x01,0x00,
};
void delay0() //延时约 ? mS
{
register unsigned char i,j;
for(i=0;i<0x64;i++)
{
for(j=0;j<0xff;j++);
}
}
void delay1() //延时约 ? mS
{
register unsigned char i,j;
for(i=0;i<0x19;i++)
{
for(j=0;j<0xff;j++);
}
}
void delay2() //延时约 ? mS
{
register unsigned char h,i,j;
for(h=0;h<0x14;h++)
{
for(i=0;i<0xff;i++)
{
for(j=0;j<0xff;j++);
}
}
}
void delay3() //延时约 ? mS
{
register unsigned char i;
for(i=0;i<0x96;i++);
}
void delay4() //延时约 ? mS
{
register unsigned char i,j,k;
for(i=0;i<0x02;i++)
{
for(j=0;j<0xff;j++)
{
for(k=0;k<0xff;k++);
}
}
}
//向LCD内部控制器发命令
void LCD_order(unsigned char Order_Code)
{
CW_ADD = Order_Code;
}
//向LCD内部控制器写入数据
void LCD_write(unsigned char Data_Code)
{
DW_ADD = Data_Code;
}
//读当前光标处字符码
unsigned char LCD_read()
{
char Data_code;
Data_code = DR_ADD;
return(Data_code);
}
//屏幕的开与关
void Screen_switch(unsigned char mode_code,unsigned char control_code)
{
//mode_code -为开或关的命令码(0x59 或 0x58)
//control_code -控制方式码
LCD_order(mode_code);
LCD_write(control_code);
}
//系统初始化
void Init_system()
{
unsigned char i;
LCD_order(0x40);
for(i=0;i<8;i++)
{
LCD_write(System_set[i]);
}
LCD_order(0x44);
for(i=0;i<10;i++)
{
LCD_write(Scroll_set[i]);
}
LCD_order(0x5a);
LCD_write(0x00);
LCD_order(0x5b);
LCD_write(0x0f);
Screen_switch(0x59,0x00);
}
//锁定光标位置
void Locate_cursor(unsigned char high_bit,unsigned char low_bit)
{
LCD_order(0x46);
LCD_write(low_bit);
LCD_write(high_bit);
}
//清全屏幕
void LCD_cls()
{
unsigned char i,j;
LCD_order(0x4c);
Locate_cursor(0x00,0x00);
LCD_order(0x42);
for(i=0;i<240;i++)
{
for(j=0;j<40;j++) LCD_write(0x00);
}
}
//图形模式下屏幕锁定光标
void Graph_locate(unsigned int row,unsigned char column)
{
//row-行(以像素为单位) column-列(以字节为单位)
unsigned int address;
unsigned char high_bit,low_bit;
address = ((row - 1) * 40) + (column - 1);
high_bit = (address >> 8) & 0xff;
low_bit = address & 0xff;
Locate_cursor(high_bit,low_bit);
}
//图形模式下在指定行指定列显示指定大小的图形
void Picture_display(unsigned int row,unsigned char column,
unsigned char *picture_code,unsigned int width,
unsigned int high,unsigned char mode)
{
//row-行(以像素为单位) column-列(以字节为单位) *picture_code-图形数组
//width-图形宽度(以像素为单位) high-图形高度(以像素为单位)
//mode-显示模式:1-正常 2-反白
unsigned char i,j,d_code;
LCD_order(0x4c);
width = width / 8;
for(i=0;i<high;i++)
{
Graph_locate(row,column);
LCD_order(0x42);
for(j=0;j<width;j++)
{
d_code = *picture_code;
if(mode==2) d_code = ~d_code;
LCD_write(d_code);
picture_code++;
}
row++;
}
}
// 图形模式下在指定行指定列填充一定的矩形区域
void Fill_area(unsigned char row,unsigned char column,unsigned char width,
unsigned char high,unsigned char mode_code)
{
// row-行(以像素为单位) column-列(以字节为单位)
// width-区域宽度(以字节为单位) high-区域高度(以像素为单位)
// mode_code-填充方式码
unsigned char i,j;
LCD_order(0x4c);
for(i=0;i<high;i++)
{
Graph_locate(row,column);
LCD_order(0x42);
for(j=0;j<width;j++) LCD_write(mode_code);
row++;
}
}
char caculate(unsigned int Data,int mod,unsigned int row,unsigned char column,char a)
{
unsigned char s[6];
unsigned char i,j;
unsigned char *picture_code[9];
i=0;
j=0;
do
{
mod=mod/10;
s[i]=Data/mod;
Data=Data%mod;
i=i+1;
}while(mod>10);
s[i]=Data;
j=i;
for(i=0;i<=j;i++)
{
switch(s[i])
{
case 0:
if((s[0]==0)&(i==0))
picture_code[i]=char_blank;
else
{
if((s[0]==0)&(s[1]==0)&(i==1))
picture_code[i]=char_blank;
else
{
if((s[0]==0)&(s[1]==0)&(s[2]==0)&(i==2))
picture_code[i]=char_blank;
else
{
if((s[0]==0)&(s[1]==0)&(s[2]==0)&(s[3]==0)&(i==3))
picture_code[i]=char_blank;
else
{
if((s[0]==0)&(s[1]==0)&(s[2]==0)&(s[3]==0)&(s[4]==0)&(i==4))
picture_code[i]=char_blank;
else
{
if((s[0]==0)&(s[1]==0)&(s[2]==0)&(s[3]==0)&(s[4]==0)&(s[5]==0)&(i==5))
picture_code[i]=char_blank;
else
picture_code[i]=char_0;
}
}
}
}
}
break;
case 1:
picture_code[i]=char_1;
break;
case 2:
picture_code[i]=char_2;
break;
case 3:
picture_code[i]=char_3;
break;
case 4:
picture_code[i]=char_4;
break;
case 5:
picture_code[i]=char_5;
break;
case 6:
picture_code[i]=char_6;
break;
case 7:
picture_code[i]=char_7;
break;
case 8:
picture_code[i]=char_8;
break;
case 9:
picture_code[i]=char_9;
break;
default:
break;
}
}
Picture_display(row,column+0,picture_code[0],8,16,1);
Picture_display(row,column+1,picture_code[1],8,16,1);
Picture_display(row,column+2,picture_code[2],8,16,1);
Picture_display(row,column+3,char_point,8,16,1);
Picture_display(row,column+4,picture_code[3],8,16,1);
Picture_display(row,column+5,char_degree,8,16,1);
Picture_display(row,column+6,char_bA,8,16,1);
//Picture_display(row,column+6,char_bB,8,16,1);
}
void Delay()
{
;
}
/*发送起始条件*/
void Start(void) /*起始条件*/
{
Sda=1;
Scl=1;
Delay();
Delay();
Sda=0;
Delay();
Delay();
}
void Stop(void) /*停止条件*/
{
Sda=0;
Scl=1;
Delay();
Delay();
Sda=1;
Delay();
Delay();
}
void Ack(void) /*应答位*/
{
Sda=0;
Delay();
Delay();
Scl=1;
Delay();
Delay();
Scl=0;
}
void NoAck(void) /*反向应答位*/
{
Sda=1;
Delay();
Delay();
Scl=1;
Delay();
Delay();
Scl=0;
}
//发送数据子程序,Data为要求发送的数据
void Send(unsigned char Data)
{
unsigned char BitCounter=8; //位数控制
unsigned char temp; //中间变量控制
do
{
temp=Data;
Scl=0;
Delay();
Delay();
if((temp&0x80)==0x80)// 如果最高位是1
Sda=1;
else
Sda=0;
Scl=1;
temp=Data<<1; //RLC
Data=temp;
BitCounter--;
}while(BitCounter);
Scl=0;
}
//读一个字节的数据,并返回该字节值
unsigned char Read(void)
{
unsigned char temp=0;
unsigned char temp1=0;
unsigned char BitCounter=8;
Sda=1;
do
{
Scl=0;
Delay();
Delay();
Delay();
Delay();
Scl=1;
Delay();
Delay();
Delay();
Delay();
if(Sda) //如果Sda=1;
temp=temp|0x01; //temp的最低位置1
else
temp=temp&0xfe; //否则temp的最低位清0
if(BitCounter-1)
{
temp1=temp<<1;
temp=temp1;
}
BitCounter--;
}while(BitCounter);
return(temp);
}
//发送行数据
void SendLINE(unsigned char Data)
{
Start();
Send(0x44);
Ack();
Send(Data);
Ack();
Stop();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -