⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c_lcm.h

📁 08山东电子电子竞赛智能小车程序基于PIC+红外+电子罗盘ourdev551262 包含源码
💻 H
字号:

#define  LCM_SID HardL_LCD_19
#define  LCM_SCK HardL_LCD_18
#define  LCM_RST HardL_LCD_17

#define comm  0
#define dat   1

unsigned char LcmCurrX=0;


/*-------------------LCD写数据或指令-------------------
Data=1 数据
Data=0 指令
content       要写的内容
--------------------------------------------------------*/
void LCD_Write(unsigned char Data,unsigned char content)
{
unsigned char a,i,j;
a=content;
//delay_us(500);
output_low(LCM_SCK);
output_high(LCM_SID);;
//同步
for(i=0;i<5;i++)
{
    output_high(LCM_SCK);
    output_low(LCM_SCK);
}
//RW=0写
output_low(LCM_SID);
output_high(LCM_SCK);
output_low(LCM_SCK);
//Rs=1数据 RS=0指令
if(Data)
    output_high(LCM_SID);   //data
  else
    output_low(LCM_SID);   //command

  output_high(LCM_SCK);
  output_low(LCM_SCK);
  output_low(LCM_SID);
  output_high(LCM_SCK);
  output_low(LCM_SCK);

//分为两字节写一个内容
for(j=0;j<2;j++)
{
    for(i=0;i<4;i++)
    {
      output_bit(LCM_SID, shift_left(&content,1,0));
      output_high(LCM_SCK);
      output_low(LCM_SCK);
    }
    output_low(LCM_SID);
    for(i=0;i<4;i++)
    {
      output_high(LCM_SCK);
      output_low(LCM_SCK);
    }
  }

}

/*---------------设置字符显示位置----------------*/
void LCD_setpos(unsigned char x,unsigned char y)// 0<=x<=7,0<=y<=3
{
unsigned char tmp;
if(y>3)y=0;
if(x>7)x=0;

LcmCurrX=x*2+y*16;

if(y==0) tmp=0x80+x;
if(y==1) tmp=0x90+x;
if(y==2) tmp=0x88+x;
if(y==3) tmp=0x98+x;
LCD_Write (comm,tmp);
//delay_ms(1);
delay_us(70);
}

/*---------------清屏---------------*/
void LCD_disp_CLS ()
{	
   LCD_Write (comm,0x30);
   LCD_Write (comm,0x01);
   delay_ms(20);
}

/*---------------显示ROM字符串----------------*/
void  LCDprintR(unsigned char  *addr,unsigned char X,unsigned char Y)
{
unsigned char data;

LCD_setpos(x,y);

while(read_program_eeprom(addr)!=0)
{   data=read_program_eeprom(addr);
    addr++;
	LcmCurrX++;
	LCD_Write (dat,data);
    if (LcmCurrX==16) LCD_setpos(0,1);
    if (LcmCurrX==32) LCD_setpos(0,2);
    if (LcmCurrX==48) LCD_setpos(0,3);
    if (LcmCurrX==64) LCD_setpos(0,0);
}
delay_ms(1);
}
/*--------------显示RAM字符串----------------*/
void LCDprintf(unsigned char *PrintData,unsigned char X,unsigned char Y)
{
unsigned char data;
LCD_setpos(x,y);
	while(*PrintData!=0)
	{ 
    data=*PrintData;
    PrintData++;
	LcmCurrX++;
	LCD_Write (dat,data);
    if (LcmCurrX==16) LCD_setpos(0,1);
    if (LcmCurrX==32) LCD_setpos(0,2);
    if (LcmCurrX==48) LCD_setpos(0,3);
    if (LcmCurrX==64) LCD_setpos(0,0);

	}

}


/*---------------显示1个RAM汉字或字符----------------*/
void LCD_disp_Putchar(unsigned char data)
{
LCD_Write (dat,data);
}

/*---------------LCD显示16位数字----------------*/
void LCD_disp_valueInt16(unsigned long value)
{	
	long count,val,temp;
	int j;
	val=value;
	temp=1;
	count=0;
	while((val/=10)!=0)
		{
			count++;
			temp*=10;
		}
	for(j=0;j<=count;j++)
	{
		val=value/temp;
		value%=temp;
		temp/=10;
 		LCD_Write (dat,'0'+val);
	}
}


/*---------------时钟显示8位数字----------------*/
void LCD_disp_timenum(unsigned char value)
{
unsigned char i,j;
i=value/10;
j=value%10;
LCD_Write (dat,'0'+i);
LCD_Write (dat,'0'+j);
}

/*---------------LCD初始化--------------------*/
void init_LCD()
{
  output_low(LCM_RST);
  delay_ms(1);
  output_high(LCM_RST);
  LCD_Write (comm,0x30);  /*30---基本指令动作*/   
  LCD_Write (comm,0x01);  /*清屏,地址指针指向00H*/
  delay_us(100);
  LCD_Write (comm,0x06);  /*光标的移动方向*/
  LCD_Write(comm,0x0c);  /*开显示,关游标*/
  LCD_disp_CLS ();
}



//显示8位数据
void LCD_disp_valueInt8(unsigned char value)
{
unsigned char i,j,k;
i=value/100;
k=value%100;
j=k/10;
k=k%10;

if(i!=0)
{
LCD_Write (dat,'0'+i);
LCD_Write (dat,'0'+j);
}else if(j!=0)
{
LCD_Write (dat,'0'+j);
}
LCD_Write (dat,'0'+k);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -