📄 mdt.c
字号:
void Clear_Screen(unsigned char bg_data)
{
unsigned char i=0,j=0;
while(i<16){
Write_S6b0741_Reg(SET_PAGE+i);
Write_S6b0741_Reg(SET_COLUMN_MSB);
Write_S6b0741_Reg(SET_COLUMN_LSB);
while(j<0x80) { //0x80:128,每页写128个字节
Write_S6b0741_Data(bg_data);
j++;
}
i++;j=0;
}
return;
}
//============================================================
// S6B0741初始化
//============================================================
void S6b0741_Init()
{
Delay(60000);
Delay(60000);
//===============================================
//用户应用设置 User Application Setup
//===============================================
//============================================================
// ICON显示开关
//============================================================
Write_S6b0741_Reg(ICON_OFF);
//============================================================
//设置液晶显示DUTY值
//set display duty ratio 1/128
//============================================================
Write_S6b0741_Reg(SET_DUTY);
Write_S6b0741_Reg(0x80); //0x10-.0x80 map 1/16-.1/128(without icon)
//============================================================
// 设置液晶交流驱动信号周期
//============================================================
Write_S6b0741_Reg(SET_NLINE_INV);
Write_S6b0741_Reg(0); //ac(M) 0x01-.0x1f match the 3-.33 lines; 0 match the frame.
//============================================================
// 设置列驱动方向
//set ADC normal mode 0-.127(relationship with Column and seg)
//============================================================
Write_S6b0741_Reg(ADC_NORMAL);
//============================================================
// 设置行驱动方向
//set com direction SHL Reverse_Flag mode 127-.0(com scan direction)
//============================================================
Write_S6b0741_Reg(SHL_NORMAL);
//============================================================
// 设置扫描起始行
//set init com0
//============================================================
Write_S6b0741_Reg(SET_COM0);
Write_S6b0741_Reg(0x00+4);
//============================================================
// 设置显示存储器起始行
//set init lines
//============================================================
Write_S6b0741_Reg(SET_START_LINE);
Write_S6b0741_Reg(0x00);
//===============================================
//液晶操作电压设置 Set the LCD Operation Voltage
//===============================================
// 启动液晶驱动器内部振荡器
//start the built-in OSCILLATOR
//============================================================
Write_S6b0741_Reg(OSC_ON);
//============================================================
// 设置倍压电路倍数
//set dc-dc step up 5 times; (0 - 3 match the 3 - 6 times.)
//============================================================
Write_S6b0741_Reg(SET_DC_STEP+1);
//============================================================
// 设置内部分压电路电阻比
//select regulator resistor 1+(Rb/Ra)=7.2 R2,R1,R0=1;
//0 - 7 match the 2.3; 3.0; 3.7; 4.4; 5.1; 5.8; 6.5; 7.2
//============================================================
Write_S6b0741_Reg(SEL_REG_RESISTOR+7);
//============================================================
// 设置内部电压调整刻度
//set electronic volumn 56? (14.5v); 0 - 63 level.(1+Rb/Ra=7.2)
//refer to the 1+Rb/Ra.
//============================================================
Write_S6b0741_Reg(SET_VOL);
Write_S6b0741_Reg(0x34);
//============================================================
// 设置液晶驱动偏压比
//select LCD bias 1/12.5 ~= 1/12 (0-.7 match the 1/5 - 1/12)
//============================================================
Write_S6b0741_Reg(SET_BIAS+7);
//============================================================
// 设置灰度实现方式:4帧+15级PWM
//set FRC and PWM mode: 4FRC; 15PWM
//============================================================
Write_S6b0741_Reg(SET_FRC_PWM+3);
//============================================================
//============================================================
// 灰度模式白点对应代码:00
//============================================================
//Set white mode,1st/2nd frame, pulse width 1st=2nd=0;
Write_S6b0741_Reg(SET_W_12);
Write_S6b0741_Reg(0x00);
//============================================================
//Set white mode,3rd/4th frame, pulse width 3rd=4th=0;
Write_S6b0741_Reg(SET_W_34);
Write_S6b0741_Reg(0x00);
//============================================================
//============================================================
// 灰度模式低灰度点对应代码:00x55
//Set light gray mode,1st/2nd frame, pulse width 1st=2nd=0x55;
//============================================================
Write_S6b0741_Reg(SET_LG_12);
Write_S6b0741_Reg(0x55);
//Set light gray mode,3rd/4th frame, pulse width 3rd=4th=0x55;
Write_S6b0741_Reg(SET_LG_34);
Write_S6b0741_Reg(0x55);
// 灰度模式高灰度点对应代码:00xaa
//Set dark gray mode,1st/2nd frame, pulse width 1st=2nd=0xaa;
Write_S6b0741_Reg(SET_DG_12);
Write_S6b0741_Reg(0xaa);
//Set dark gray mode,3rd/4th frame, pulse width 3rd=4th=0xaa;
Write_S6b0741_Reg(SET_DG_34);
Write_S6b0741_Reg(0xaa);
// 灰度模式黑点对应代码:0xff
//Set black mode,1st/2nd frame, pulse width 1st=2nd=0xff;
Write_S6b0741_Reg(SET_B_12);
Write_S6b0741_Reg(0xff);
//Set black mode,3rd/4th frame, pulse width 3rd=4th=0xff;
Write_S6b0741_Reg(SET_B_34);
Write_S6b0741_Reg(0xff);
//============================================================
//==========================================================
//开通电压转换器 Turn On the Voltage Convertor
//==========================================================
//power control
// 内部电源转换电路开
Write_S6b0741_Reg(POWER_CONTROL+4); //VC ON
Delay(5);
// 内部电压调节开
Write_S6b0741_Reg(POWER_CONTROL+6); //VR ON
Delay(5);
// 内部电源反馈开
Write_S6b0741_Reg(POWER_CONTROL+7); //VF ON
Delay(5);
}
//============================================================
//============================================================
// 连续写N个显示数据到显示缓存区(SRAM)
//============================================================
void Buff_Write(unsigned char *disp_data, unsigned char n)
{
unsigned int i=0;
while(i<n){
Buff_Page[TPAGE].Column[i+Y_Offset]=disp_data[i];
++i;
}
return;
}
//============================================================
// 连续读N个显示缓存区数据
//============================================================
void Buff_Read(unsigned char *disp_data,unsigned char n)
{
unsigned int i=0;
while(i<n){
disp_data[i]=Buff_Page[TPAGE].Column[i+Y_Offset];
++i;
}
return;
}
//============================================================
// 读取单字节Flash数据(字库)并返回
//============================================================
unsigned char Read_Flash(unsigned int adr)
{
unsigned char in_data;
pt_code=adr;
in_data=*pt_code;
if(Bg_Gray) in_data=~in_data;
return in_data;
}
//============================================================
// 读取汉字点阵数据
//============================================================
void Read_Hz_Data(unsigned char *hzcode)
{
unsigned char i=0;
unsigned long int offset;
unsigned int page_addr;
if(hzcode[0]>=0xb0) hzcode[0]-=6;
hzcode[0]-=0xa1; hzcode[1]-=0xa1;
offset=hzcode[0]*94+hzcode[1];
offset=24*offset+0x500;
for(i=0;i<24;++i){
if((offset>>15)&0x01) ADDR15=1;else ADDR15=0;
if((offset>>16)&0x01) ADDR16=1;else ADDR16=0;
if((offset>>17)&0x01) ADDR17=1;else ADDR17=0;
page_addr=0x8000+(offset&0x07fff);
Matrix_Data[i]=Read_Flash((unsigned int)page_addr);
++offset;
}
return;
}
//============================================================
// 读取ASCII点阵数据
//============================================================
void Read_Ascii_Data(unsigned char asccode)
{
unsigned char i=0;
unsigned int offset;
unsigned int page_addr;
asccode-=0x20;
offset=12*asccode;
ADDR16=0;
ADDR17=0;
for(i=0;i<12;++i){
if((offset>>15)&0x01) ADDR15=1;else ADDR15=0;
page_addr=0x8000+(offset&0x07fff);
Matrix_Data[i]=Read_Flash(page_addr);
++offset;
}
return;
}
//============================================================
// 依据坐标偏移量装载ASCII数据
//============================================================
void Load_Symbol(unsigned char *symbol)
{
unsigned char i=0;
while(i<12){
Matrix_Data[i]=symbol[i*2];
Matrix_Data[i+12]=symbol[i*2+1];
i++;
}
return;
}
//============================================================
// 依据坐标偏移量装载ASCII数据
//============================================================
void Load_Ascii()
{
unsigned int shift;
unsigned char i=0;
while(i<12){
shift=Matrix_Data[i];
shift=shift<<X_Offset;
Matrix_Data[i]=(unsigned char)shift;
shift=shift>>8;
Matrix_Data[i+12]=(unsigned char)shift;
++i;
}
return;
}
//============================================================
// 依据坐标偏移量装载汉字数据
//============================================================
void Load_Hz()
{
unsigned long int shift;
unsigned char i=0;
while(i<12){
shift=Matrix_Data[i+12];
shift=shift<<8;
shift|=Matrix_Data[i];
shift=shift<<X_Offset;
Matrix_Data[i]=(unsigned char)shift;
shift=shift>>8;
Matrix_Data[i+12]=(unsigned char)shift;
shift=shift>>8;
Matrix_Data[i+24] =(unsigned char)shift;
++i;
}
return;
}
//============================================================
// 设置字符坐标
//============================================================
void Set_XY(unsigned char x, unsigned char y)
{
if(x<20) Asc_X=x;
if(y<100) Asc_Y=y;
X_Offset=(Asc_X*6)%8;
Y_Offset=Asc_Y*12+Line_Tab;
TPAGE=Asc_X*6/8;
return;
}
//============================================================
// X坐标加1
//============================================================
void Next_X()
{
if(Asc_X<20) ++Asc_X;
Set_XY(Asc_X,Asc_Y);
return;
}
//============================================================
// Y坐标加1
//============================================================
void Next_Line()
{
if(Asc_Y<100) {++Asc_Y; Asc_X=0;}
Set_XY(Asc_X,Asc_Y);
return;
}
//============================================================
// X方向以字节方式(页)加1
//============================================================
void Next_Page()
{
if(TPAGE<15) ++TPAGE;
return;
}
//============================================================
// 在存储区指定位置写入ASCII显示数据
//============================================================
void V_Write_Ascii()
{
unsigned char i=0;
unsigned char tmp[12];
if(Enter_En==1)
if(Asc_X>19){Asc_X=0;++Asc_Y; ++Total_Line;}
Load_Ascii();
Set_XY(Asc_X,Asc_Y);
Buff_Read(tmp,12);
for(i=0;i<12;++i){
tmp[i]&=0xff>>(8-X_Offset);
Matrix_Data[i]+=tmp[i];
}
Set_XY(Asc_X,Asc_Y);
Buff_Write(Matrix_Data,12);
Set_XY(Asc_X,Asc_Y);
Next_Page();
Buff_Write(Matrix_Data+12,12);
Next_X();
return;
}
//============================================================
// 在存储区指定位置写入汉字显示数据
//============================================================
void V_Write_HZ()
{
unsigned char i=0;
unsigned char tmp[12];
if(Enter_En==1)
if(Asc_X>18){Asc_X=0; ++Asc_Y; ++Total_Line;}
Load_Hz();
Set_XY(Asc_X,Asc_Y);
Buff_Read(tmp,12);
for(i=0;i<12;++i){
tmp[i]&=0xff>>(8-X_Offset);
Matrix_Data[i]+=tmp[i];
}
Set_XY(Asc_X,Asc_Y);
Buff_Write(Matrix_Data,12);
Next_Page();
Buff_Write(Matrix_Data+12,12);
Next_Page();
Buff_Write(Matrix_Data+24,12);
Next_X();
Next_X();
return;
}
//============================================================
// 在存储区指定位置写入字符串显示数据
//============================================================
void Print_String(unsigned char *str,unsigned char n)
{
unsigned char i=0;
unsigned char code_data[2];
while(i<n){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -