📄 mobi2006lcd.c
字号:
#include <config.h>
sbit LCDSI=P3^6; //LCD CONTROL
sbit LCDSCL= P3^7;
sbit LCDA= P1^5;
sbit LCDRES= P1^6;
sbit LCDCS =P1^7;
//***************************************************************************************************************
void ClearScreen()
{
uint8 i,j;
for(i=0;i<63;i++)
{
SetXY(i,0);
for(j=0;j<132;j++)
SendByte(DATA,0x00);
}
}
/*
***INPUT:flag:0--command 1---data ;dd:a byte
*/
void SendByte(uint8 flag,uint8 dd)
{
uint8 i=0;
LCDCS=0;
if(flag)
LCDA=1; //send data flag
else
LCDA=0; //send command flag
for(i=0;i<8;i++)
{
LCDSCL=0;
if(dd&0x80)
LCDSI=1;
else
LCDSI=0;
_nop_();
_nop_();
_nop_();
LCDSCL=1;
dd<<=1;
}
LCDCS=1;
}
void delay(uint8 n)
{
uint8 i,j;
for(i=n;i>0;i--)
for(j=255;j>0;j--);
}
void InitLCD()
{
uint16 LCD_Temp;
delay(255);
//LCDCS=0;
LCDRES=0;
_nop_();
_nop_();
_nop_();
LCDRES=1;
SendByte(COMMAND , 0xE2); //NOP :command for non-operation mode
SendByte(COMMAND , 0xA2); //lcd bixa set
SendByte(COMMAND , 0xa1); //ACD select:forward direction
// SendByte(COMMAND , 0xa7); //display inverted
SendByte(COMMAND , 0xC1); //set scan direction for COM segment :forward
SendByte(COMMAND , 0x2f); //power control set
for(LCD_Temp = 0;LCD_Temp<1000;LCD_Temp++);
SendByte(COMMAND , 0x23); //set Vlc1 output voltage to electronic volume register
SendByte(COMMAND , 0x81); //electronic volume mode set
SendByte(COMMAND , 0x3F); //electronic volume register set
SendByte(COMMAND , 0x2f); //power control set
for(LCD_Temp = 0;LCD_Temp<1000;LCD_Temp++);
SendByte(COMMAND , 0x40); //display start line set
SendByte(COMMAND , 0xAF); //display ON
SendByte(COMMAND , 0x00); //column low address set*/
/*
SendCommand(0xA2); //LCD bia set:1/9
SendCommand(0xb0); //ACD select:forward direction
SendCommand(0xa4); //display mode set:normal display mode
SendCommand(0x28); //power control set
SendCommand(0x20); //set on-chip resistor for Vlc1
SendCommand(0x81); //electronic volumn set
SendCommand(0x20);
SendCommand(0x80); //common output status select:normal(forward)
delay(255);
SendCommand(0xb0); //set page address
SendCommand(0x10); //set column address(high byte)
SendCommand(0x00); //set column address(low byte)
SendCommand(0xa5); //display on
SendByte(COMMAND,0xE2);
SendByte(COMMAND,0xA2);
SendByte(COMMAND,0xb0);
SendByte(COMMAND,0xc0);
SendByte(COMMAND,0x2f);
for(LCD_Temp = 0;LCD_Temp<1000;LCD_Temp++);
SendByte(COMMAND,0x23);
SendByte(COMMAND,0x81);
SendByte(COMMAND,0x3f);
SendByte(COMMAND,0x2f);
for(LCD_Temp = 0;LCD_Temp<1000;LCD_Temp++);
SendByte(COMMAND, 0x80);
SendByte(COMMAND, 0xa6);
SendByte(COMMAND, 0xb0);
SendByte(COMMAND,0x10);
SendByte(COMMAND,0x00);
SendByte(COMMAND,0xa5);
*/
}
/* Function: draw dot on LCD
***Input:range of x is:0---63;range of y is :0---127
***Output:void
*/
void SetXY(uint8 x,uint8 y)
{
LCDCS=0;
SendByte(COMMAND,(x/8)|0xB0); //page address set
SendByte(COMMAND,0x10|((y&0xf0)>>4)); //column address set
SendByte(COMMAND,y&0x0f);
LCDCS=1;
}
/* Function: draw dot on LCD
***Input:range of x is:0---63;range of y is :0---127
***Output:void
*/
void DrawDot(uint8 x,uint8 y)
{
uint8 tmp;
SetXY(x, y);
switch(x&7) //x&7==x%8
{
case 1:
tmp=0x01;
break;
case 2:
tmp=0x02;
break;
case 3:
tmp=0x04;
break;
case 4:
tmp=0x08;
break;
case 5:
tmp=0x10;
break;
case 6:
tmp=0x20;
break;
case 7:
tmp=0x48;
break;
default:
tmp=0x80;
break;
}
SendByte(DATA,tmp);
}
/* Function: draw Line on LCD
***Input:range of x1 and x2 is:0---63;range of y1 and y2 is :0---127
***Output:void
*/
void DrawLine(uint8 x1,uint8 y1,uint8 x2,uint8 y2)
{
uint8 i;
if(x1==x2) //draw horizontal line
for(i=y1;i<=y2;i++)
DrawDot(x1, i);
if(y1==y2) //draw vertical line
for(i=x1;i<=x2;i++)
DrawDot(i,y1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -