lcd.c

来自「这个是128×64的液晶屏的读写程序」· C语言 代码 · 共 102 行

C
102
字号
//******************************************************************************
// 128*64 LCD驱动代码                                                               
// 
// 2006-01-25
// www.CPLD-FPGA.NET
//******************************************************************************

#include "LCD_DEFINE.H"


void lcd_init(void)
{
  LCD_DATA_OUT = 0x00;
  
}

void write_command(unsigned char command)
{

  LCD_CS1 =1 ;
  LCD_CS2 =1 ;
  LCD_RW = 0 ;
  LCD_DI = 0 ;
  LCD_DATA_OUT = command;
  LCD_EN = 1 ;
  LCD_EN = 0 ;
}

void write_data( unsigned char LCDdata, unsigned char CS1, unsigned char CS2 )
{
	
  if(CS1) 
	LCD_CS1 =1 ;
  else 
  	LCD_CS1 =0;
	
  if(CS2) 
	LCD_CS2 =1;
  else 
	LCD_CS2 =0;
	
  LCD_DI = 1;
  LCD_RW = 0;
  LCD_DATA_OUT  = LCDdata;
  LCD_EN = 1;
  LCD_EN = 0;
}

void clear_lcd(void)
{
  unsigned char i,j;
  for(i=0;i<8;i++)
  {
   write_command(SET_X|i);
   write_command(SET_Y);
   for(j=0;j<128;j++)
   {
    if(j<=63) write_data(0,1,0);
    else write_data(0,0,1);
 //   _NOP_();
   }
  }
}


//*chr 显示数据的地址,nRow 在显示屏上第几行,nCol 在显示屏上第几列
//highth  字体的高度,wideth 字体的宽度
//128*64有8行,128列       
void display( unsigned char *chr, unsigned char nRow, unsigned char nCol,
                 unsigned char highth,unsigned char wideth )
         
{
  unsigned char i,tmpCol,tmpRow,h,m;
  unsigned int j;
  tmpRow = nRow;
  m=0;
  j=0;		//注意此变量的用法
  for(h=0;h<highth;h=h+8)
  {
    
    write_command(SET_X|tmpRow);
    tmpCol=nCol;
    for(i=0;i<wideth;i++)
    {
      if(tmpCol<64)
      {
		write_command(SET_Y|tmpCol);
		write_data(chr[i+j],1,0);}
      else 
      {
		write_command(SET_Y|(tmpCol-64));
		write_data(chr[i+j],0,1);
	  }
      	
	tmpCol++;
    }
    m++;
    j=m*wideth;
    tmpRow++;
  }
}

⌨️ 快捷键说明

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