avr單片機+12864液晶動畫顯示
下面將源代碼貼上:
本文引用地址:http://m.butianyuan.cn/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_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;i
}
// 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);//擴充功能設(shè)定
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);//擴充功能設(shè)定
LCD_Write_Com(0x30);//返回基本功能
}
評論