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

📄 ouravrocm240128.c

📁 6963的液晶驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
  for(j=0;j<1000;j++)
  ;
}
/*------------写命令或数据到LCD--------------*/
void wr_od (uchar dat,uchar comm)       //写一个数据和一个命令
{
  wr_data(dat);
  wr_comm(comm);
}
void wr_td (uchar datl,uchar dath,uchar comm)  //写两个数据和一个命令
{
  wr_data(datl);
  wr_data(dath);
  wr_comm(comm);
}
void wr_xd(uint dat,uchar comm)       //写一个16进制数据和一个命令
{
  uchar datl,dath;
  datl=dat;
  dath=dat>>8;
  wr_data(datl);
  wr_data(dath);
  wr_comm(comm);
}
void wr_auto (uchar dat)               //自动写数据
{
  chk_busy (1);
  PORTB&=~BIT(4);                  
  PORTB|=BIT(PORTB6);       
  PORTA=dat;
  PORTB&=~BIT(7);             
  PORTB|=BIT(7);              
}

void wr_comm(uchar comm)       //写命令
{
  chk_busy (0);
  PORTB|=BIT(4);
  PORTB|=BIT(6);
  PORTA=comm;
  PORTB &= ~BIT(7);
  PORTB|=BIT(7);
}
void wr_data(uchar dat)       //写数据
{
  chk_busy (0);
  PORTB &= ~BIT(4);
  PORTB|=BIT(6);
  PORTA=dat;
   PORTB &= ~BIT(7);
  PORTB|=BIT(7);
}
void chk_busy (uchar autowr)    //测状态
{
  uchar PPA;
  PORTA=0xff;
  DDRA=0X00;
  PORTB|=BIT(4);
  PORTB|=BIT(7);
  PORTB &= ~BIT(6);
  PPA=PINA;
  if(autowr)
    {
	while(PPA&0X08==0X00)
	;
	}
  else
    {
	while((PPA&0X01==0X00)|(PPA&0X02==0X00))
     ;
	 }
    PORTB|=BIT(6);
	DDRA=0Xff;
}
/*------------------初始化-----------------*/
void init_lcd (void)
{
  DDRA|=0XFF;    //A为输出
  DDRB|=0XFF;    //PB4-PB7为输出
  DDRC|=0XFF;    //PC5为输出
  PORTC &= ~BIT(5);
  PORTC|=BIT(5);       
  PORTB &= ~BIT(5);
  PORTB|=BIT(7);
  PORTB|=BIT(6);
  wr_xd(addr_w,0x40);                   //文本显示区首地址
  wr_xd(addr_t,0x42);              //图形显示区首地址
  wr_td(width,0x00,0x41);               //文本显示区宽度
  wr_td(width,0x00,0x43);               //图形显示区宽度
  wr_comm(0x81);                        //逻辑"异或"
  wr_td(0x02,0x00,0x22);                //CGRAM偏置地址设置
  wr_comm(0x9c);                        //启用文本显示,启用图形显示
}
/*--------------清RAM------------------*/
void clrram (void)
{
  uchar i,j;
  wr_xd(addr_w,0x24);
  wr_comm(0xb0);
  for(j=0;j<144;j++)
  {
    for(i=0;i<width;i++)
      wr_auto(0x00);
  }
  wr_comm(0xb2);
}
/*--------------显示点阵------------------*/
void disp_dz(uchar data1,uchar data2)
{
  uchar i,j;
  wr_xd(addr_t,0x24);
  wr_comm(0xb0);
  for(j=0;j<32;j++)
  {
    for(i=0;i<width*2;i++)
      wr_auto(data1);
    for(i=0;i<width*2;i++)
      wr_auto(data2);
  }
  wr_comm(0xb2);
}
/*--------------在addr处显示8xl*yl的图形--------------*/
void disp_img(unsigned int addr,unsigned int xl,unsigned int yl,const unsigned char *img)
{
  uint i,j;
  for(j=0;j<yl;j++)
  {
    for(i=0;i<xl;i++)
    {
      wr_xd(addr+j*width+i,0x24);
      wr_od(img[j*xl+i],0xc0);
    }
  }
}
/*----------在addr处显示row_yl行(每行row_xl个)8xl*yl的文字----------*/
void disp_hanzi(uint addr,uchar xl,uchar yl,uchar row_xl,uchar row_yl,const unsigned char *chn)
{
  uint i,j,k,m;
  for(m=0;m<row_yl;m++)
  {
    for(k=0;k<row_xl;k++)
    {
      for(j=0;j<yl;j++)
      {
        for(i=0;i<xl;i++)
        {
          wr_xd(addr+m*yl*width+k*xl+j*width+i,0x24);
          wr_od(chn[(m*row_xl*xl*yl)+(k*xl*yl)+(j*xl)+i],0xc0);
        }
      }
    }
  }
}
/*--------------显示字符------------------*/
void disp_eng(unsigned char *eng)
{
  uint i,j;
  wr_xd(addr_w,0x24);
  wr_comm(0xb0);
  for(j=0;j<9;j++)
  {
    for(i=0;i<width;i++)
      wr_auto(eng[j*width+i]);
  }
  wr_comm(0xb2);
}
/*------------------主程序--------------------*/
void main ()
{
  init_lcd();
  while (1)
 {	 clrram();
	 disp_hanzi(0x03e0,4,32,4,1,tabAVR1);  //显示汉字   "欢迎光临"
     delay1(800);	
	 clrram();
	 disp_img(0x01e0,30,56,tabAVR2);	 //显示含有"我们的AVR"的图片    
	 delay1(800);
  } 
}

⌨️ 快捷键说明

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