<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > avr單片機+12864液晶動畫顯示

          avr單片機+12864液晶動畫顯示

          作者: 時間:2016-11-29 來源:網(wǎng)絡 收藏
          折騰了3天12864液晶,終于有了進展。自己用所學知識完成了一些特殊功能?,F(xiàn)在,12864可以完成在指定位置寫入文字,繪制128*64的圖形,繪制Wide*Height的圖形(寬度必須為8的倍數(shù),因為行的數(shù)據(jù)形式為字節(jié))等。

           下面將源代碼貼上:

          本文引用地址:http://www.ex-cimer.com/article/201611/323499.htm

          /*
          * _12864.c
          *
          * Created: 2011/7/30 23:16:04
          * Author: YIN
          */

          #include
          #include
          // #include "QQ.h"
          // #include "chiken.h"
          #include "TSJ.h"
          #define uint unsigned int
          #define uchar unsigned char
          #define LCD_RS_0 PORTB&=(~(1<#define LCD_RS_1 PORTB|=(1<#define LCD_RW_0 PORTB&=(~(1<#define LCD_RW_1 PORTB|=(1<#define LCD_EN_0 PORTB&=(~(1<#define LCD_EN_1 PORTB|=(1<#define LCD_PSB PORTB|=(1<#define LCD_DATA_PORT PORTA
          #define LCD_DATA_DIR DDRA
          #define LCD_CONTROL_DIR DDRB
          ;uchar Busy_Flag=1;
          /*點陣漢字坐標代碼,便于根據(jù)漢字坐標求出地址*/
          uchar Char_Location[4][8]=
          {
          {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87},//第一行漢字位置
          {0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97},//第二行漢字位置
          {0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f},//第三行漢字位置
          {0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f},//第四行漢字位置
          };

          uchar X_Pos[]={0,1,2,3,4,5,4,3,2,1,0};//圖像顯示的坐標,該坐標基于LCD液晶的圖形顯示說明部分
          uchar Y_Pos[]={0,15,5,16,3,20,5,24,8,15,7};

          void delay0()//短暫延時
          {
          uint i;
          i=7;
          while(i--);
          }

          void DelayMS(uint MS)//延時毫秒(自己估算的,不準確)
          {
          uint i,j;
          for (i=0;ifor (j=1100;j>0;j--);
          }
          // uint LCD_Busy()//忙標志判斷,如果lcd速度較快可不用判忙
          // {
          // LCD_DATA_DIR=0x00;
          // LCD_EN_1;
          // LCD_RS_0;
          // LCD_RW_1;
          // Busy_Flag=PINA&0x80;
          // LCD_EN_0;
          // return Busy_Flag;
          // }

          void LCD_Write_Dat(uchar Data)//寫入數(shù)據(jù)
          {
          // while(LCD_Busy());
          LCD_DATA_DIR=0xff;
          LCD_RS_1;
          LCD_RW_0;
          LCD_EN_1;
          LCD_DATA_PORT=Data;
          LCD_EN_0;
          delay0();
          }

          void LCD_Write_Com(uchar Com)//向12864寫入命令
          {
          // while(LCD_Busy());
          LCD_DATA_DIR=0xff;
          LCD_RS_0;
          LCD_RW_0;
          LCD_EN_1;
          LCD_DATA_PORT=Com;
          LCD_EN_0;
          delay0();
          }

          void LCD_Write_Chinese(uchar x,uchar y,char *Chn) //從指定行、列開始寫入文字
          {
          LCD_Write_Com(Char_Location[x-1][y-1]);//寫入首地址
          DelayMS(1);
          while(*Chn>0)
          {
          LCD_Write_Dat(*Chn);//寫入文字
          Chn++;
          }
          }


          void DisplayImage(uchar *PIC) //繪制128*64的圖片
          {
          uint x=0,j=0,i=0,y=0;
          uint tmp0=0;
          LCD_Write_Com(0x34);
          for(i=0;i<2;i++)//分兩屏,上半屏和下半屏,每次寫入一個半屏,2次完成整屏
          {
          for(y=0;y<32;y++) //32行,因此,y地址為0-31
          {
          LCD_Write_Com(0x80+y);//寫入y地址
          LCD_Write_Com(0x80+x);//x地址,x地址會自動加1,因此只給出初始地址
          for(j=0;j<16;j++)
          LCD_Write_Dat(~pgm_read_byte(&PIC[tmp0+j])); //讀取數(shù)據(jù)寫入LCD
          tmp0+=16;//tmp0自動加16,下次操作時讀取下一行的數(shù)據(jù)
          }
          x=8;
          }
          LCD_Write_Com(0x36);//擴充功能設定
          LCD_Write_Com(0x30);//返回基本功能
          }

          void Draw_Pic(uchar Wide,uchar Height,uchar PX,uchar PY,uchar *PIC) //繪制Wide*Height的圖片,寬度只能是8的倍數(shù),否則出錯
          {
          unsigned char j=0,y=0,flag=0,Height1=0;
          unsigned int tmp0=0;
          Height1=Height;
          if(Height>32)
          {
          flag=1;
          Height1=32;
          }
          LCD_Write_Com(0x34);
          for(y=PY;y{
          LCD_Write_Com((0x80+y));//y地址
          LCD_Write_Com((0x80+PX));//x地址,x地址會自動加1,因此只給出初始地址
          for(j=0;j<(Wide/8);j++)
          LCD_Write_Dat(~pgm_read_byte(&PIC[tmp0+j])); //讀取數(shù)據(jù)寫入LCD
          tmp0+=(Wide/8);
          }
          if (flag=1)
          {
          for(y=0;y<(Height-32+PY);y++) //32行,因此,y地址為0-31
          {
          LCD_Write_Com((0x80+y));//y地址
          LCD_Write_Com((0x88+PX));//x地址,x地址會自動加1,因此只給出初始地址
          for(j=0;j<(Wide/8);j++)
          LCD_Write_Dat(~pgm_read_byte(&PIC[tmp0+j])); //讀取數(shù)據(jù)寫入LCD
          tmp0+=(Wide/8);
          }
          flag=0;
          }
          LCD_Write_Com(0x36);//擴充功能設定
          LCD_Write_Com(0x30);//返回基本功能
          }


          上一頁 1 2 3 下一頁

          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();