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

📄 lcd1011.c

📁 c系列液晶驱动
💻 C
字号:
#include <iom8v.h>
#include <macros.h>

#define uint  unsigned int
#define uchar unsigned char
#define comm  0
#define dat   1

#define csh  PORTC|=BIT(PC1)
#define csl  PORTC&=~BIT(PC1)
#define stdh  PORTC|=BIT(PC2)
#define stdl  PORTC&=~BIT(PC2)
#define sclkh  PORTC|=BIT(PC3)
#define sclkl  PORTC&=~BIT(PC3)
#define ledh  PORTC|=BIT(PC4)
#define ledl  PORTC&=~BIT(PC4)


void wr_lcd (uchar dat_comm,uchar content);
void delay (uint us);

uchar const tab1[]={
"本系列中文模块内"
"任意位置反白显示"
"置二级字库,可在"
"使用更方便更灵活"
};

void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x7F; //m103 output only
 DDRC  = 0x7F;
 PORTD = 0x00;
 DDRD  = 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}
/*------------------初始化-----------------*/
void init_lcd (void)
{
  //rst=1;
  //psb=0;
  wr_lcd (comm,0x30);  /*30---基本指令动作*/   
  wr_lcd (comm,0x01);  /*清屏,地址指针指向00H*/
  delay (100);
  wr_lcd (comm,0x06);  /*光标的移动方向 AC加1,光标右移*/
  wr_lcd (comm,0x0c);  /*开显示,关游标 整体显示,光标显示且反白山说*/
}
/*---------------显示汉字或字符----------------*/
void chn_disp (uchar const *chn)
{
  uchar i,j;
  wr_lcd (comm,0x30);
  wr_lcd (comm,0x80);
  for (j=0;j<4;j++)
  {
    for (i=0;i<16;i++)
    wr_lcd (dat,chn[j*16+i]);
  }
}


/*--------------清DDRAM------------------*/
void clrram (void)
{
  wr_lcd (comm,0x30);
  wr_lcd (comm,0x01);
  delay (180);
}
/*---------------------------------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
  uchar a,i,j;
  delay (50);
  a=content;
  csh;
  sclkl;
  stdh;
  for(i=0;i<5;i++)
  {
    sclkh;
    sclkl;
  }
  stdl;
  sclkh;
  sclkl;
  if(dat_comm)
    stdh;   //data
  else
    stdl;   //command
  
  sclkh;
  sclkl;
  stdl;
  sclkh;
  sclkl;
  for(j=0;j<2;j++)
  {
    for(i=0;i<4;i++)
    {
	  if(a&0x80==0x80)
	  stdh;
	  else
	  stdl;
      a=a<<1;
      //std=CY;
      sclkh;
      sclkl;
    }
    stdl;
    for(i=0;i<4;i++)
    {
      sclkh;
      sclkl;
    }
  }
}
/*-----------------------------------*/
void delay (uint us)   //delay time
{
  while(us--);
}
void delay1 (uint ms)
{
  uint i,j;
  for(i=0;i<ms;i++)
  for(j=0;j<15;j++)
  delay(1);
}
/*------------------主程序--------------------*/
void main ()
{
  //SP=0x5f;
  init_lcd ();
  init_devices();
  while (1)
  {
	chn_disp (tab1);
	ledh; 
    delay1 (8000);
	ledl;
  }
}

⌨️ 快捷键说明

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