?? lcd13164.h~
字號:
/**********************************************
** 文件名 :LCD13164.H **
**********************************************/
#ifndef _LCD13164_INCLUDED_
#define _LCD13164_INCLUDED_
#include <mega32.h>
#include "red.h"
#include "font.h"
#include "fat.h"
#include "cd3315.h"
#include "vs1003.h"
//正點原子@scut 08/09/11
//針對自己手頭一批便宜的液晶(10塊一個^_^) 131*64
//代碼很好寫,僅供參考
//-----------------LCD端口定義----------------
#define LCD_SDA PORTC.7 //數據端口
#define LCD_SCK PORTC.6 //時鐘端口
#define LCD_RS PORTC.4 //數據/命令選擇端口
#define LCD_RST PORTC.3 //硬復位
#define LCD_CS PORTC.5 //片選端口
#define LCD_LED PORTC.2 //LCD背光
bit invt=0;//不反向;
bit En_backlight=0;
uchar lasttime=0;//持續時間計數器
//--------------- 串行模式發送數據----------------
//發送一個byte數據到lcd
void Send_Data(unsigned char datain)
{
unsigned char i;
for(i=0;i<8;i++)
{
LCD_SCK=0;
if((datain&0x80)==0)LCD_SDA=0;
else LCD_SDA=1;
LCD_SCK=1;
datain<<=1;
}
}
//------------------串行模式寫數據----------------
//寫數據,串行模式
void Write_data(unsigned char data)
{
LCD_RS=1;//寫數據
LCD_CS=0;//選中
Send_Data(data);//發送數據
LCD_CS=1;//釋放總線
}
//------------------串行模式寫命令----------------
//寫命令,串行模式
void Write_comd(unsigned char comd)
{
LCD_RS=0;//寫命令
LCD_CS=0;//選中
Send_Data(comd);//發送命令
LCD_CS=1;//釋放總線
}
//----------------------設置列--------------------
//設置列:0~131
void Set_column(unsigned char column)
{
column+=1;//偏移一個點
Write_comd(column&0x0f); //發送低四位
Write_comd((column>>4)|0x10);//發送高四位
}
//----------------------設置頁--------------------
//設置頁0~7
void Set_page(unsigned char page)
{
Write_comd((page&0x0f)|0xb0);
}
//清屏
void Cleardisplay(uchar row)
{
unsigned char j;
if(row<4)
{
Set_page(2*row);
Set_column(0x00);
for(j=0;j<132;j++)Write_data(0x00);
Set_page(2*row+1);
Set_column(0x00);
for(j=0;j<132;j++)Write_data(0x00);
}else
{
for(j=0;j<4;j++)Cleardisplay(j);
}
}
//在指定位置顯示一個字符
//x,0~3
//y,0~131
//chr,要顯示的字符
void Show_char(unsigned char x,unsigned char y,unsigned char chr)
{
unsigned char t;
Set_page(2*x);//定位行(頁0~7)
Set_column(y);//定位列
for(t=0;t<12;t++)
{
if(t==6) //顯示下一半
{
Set_page(2*x+1);
Set_column(y);
}
Write_data(asc2[chr-32][t]);
}
}
//顯示12*12的icon
//Ico:見 FONT 定義
void Show_icon(unsigned char x,unsigned char y,unsigned char Ico)
{
unsigned char t;
Set_page(2*x);//定位行(頁0~7)
Set_column(y);//定位列
for(t=0;t<24;t++)
{
if(t==12) //顯示下一半
{
Set_page(2*x+1);
Set_column(y);
}
if(invt)Write_data(~icon[Ico][t]);
else Write_data(icon[Ico][t]);
}
}
//在指定地址開始顯示一個漢字
void Show_font(unsigned char x,unsigned char y,unsigned char *chr)
{
unsigned char t;
Set_page(2*x);//定位行(頁0~7)
Set_column(y);//定位列
for(t=0;t<24;t++)
{
if(t==12) //顯示下一半
{
Set_page(2*x+1);
Set_column(y);
}
Write_data(chr[t]);
}
}
//顯示一副圖片
void draw_picture(flash uchar *p)
{
uint t1,t2;
for(t1=0;t1<8;t1++)
{
Set_page(t1);
Set_column(0);
for(t2=0;t2<131;t2++)Write_data(p[t2+t1*131]);
}
}
/*-----------------------------------------------------------------------
LCD_write_String: 在LCD上顯示漢字或英文字符
輸入參數:x、y:顯示漢字的起始X、Y坐標;
enchg:1,支持換行.0,不換行
-----------------------------------------------------------------------*/
uchar LCD_write_String(uchar x, uchar y,uchar *p,uchar enchg)
{
bit bHz=0; //字符或者中文
unsigned char mat[24]; //保存12X12點陳內容
while(*p!=0)
{
if(!bHz)
{
if(*p>0x80)bHz=1;//中文
else //字符
{
if(y>125&&enchg){x++;y=0;}//一行已滿,換行
if(enchg>1&&x>2)return;//只顯示中間兩行 //歌詞顯示的時候用
if(x>3)return;//越界返回
if(*p==13)//換行符號
{
x++;y=0;
p++;//跳過
}
else Show_char(x,y,* p);
p++;
y+=6;
}
}else
{
if(y>119&&enchg){x++;y=0;}//換行
if(enchg>1&&x>2)return;//只顯示中間兩行 //歌詞顯示的時候用
if(x>3)return;//越界返回
bHz=0;//有漢字庫
Get_HzMat(p,mat);//得到點陣數據
Show_font(x,y,mat);
p+=2;
y+=12;
}
} //end while
return 0;//讀取完畢
}
//在指的地址顯示一個字符串
//支持 flash 型數據
void LCD_write_cstr(uchar x, uchar y,flash uchar *str)
{
Set_page(2*x);//定位行(從0~7)
Set_column(y);//定位列
while(*str!='\0')
{
Show_char(x,y,*str);//寫一個字符
str++;
y+=6;
if(y>123)//自動換行
{
x++;y=0;
Set_page(2*x);//定位行(從0~7)
Set_column(y);//定位列
}
if(x>3){Cleardisplay(4);x=0;}//整行清除
}
}
//在指定位置顯示一個數字
//x,0~3
//y,0~131
//str,要顯示的數字
void Show_num(unsigned char x,unsigned char y,unsigned char num)
{
Show_char(x,y,(num/10)%10+'0');//顯示十位
Show_char(x,y+6,num%10+'0'); //顯示個位
}
//在指定位置顯示一個小字符0~9:kbps/
//x,0~7
//y,0~131
//str,要顯示的數字 位置
void show_minichar(unsigned char x,unsigned char y,unsigned num)
{
unsigned char t;
Set_page(x);//定位行(從0~7)
Set_column(y);//定位列
for(t=0;t<5;t++)Write_data(miniasc2[num][t]);
Write_data(0x00);//插入空隙
}
//在指定位置顯示一個小數字
void Show_mininum(unsigned char x,unsigned char y,unsigned char num)
{
show_minichar(x,y,(num/10)%10);//顯示十位
show_minichar(x,y+6,num%10); //顯示個位
}
//以下LCD代碼為游戲服務
//刷新數據,把lcdram的數據寫入LCD里面
void lcd_refresh(void)
{
uchar x,y,;uint temp;
for(y=0;y<8;y++)
{
Set_page(7-y);Set_column(0);
for(x=0;x<96;x++)
{
temp=(uint)y*96+x;
if(temp<512)Write_data(BUFFER[temp]);
else Write_data(pbuffer[temp-512]);
}
}
}
//x:0~7,y:0~96
//讀出lcdram的數據
uchar lcd_read(uchar x,uchar y)
{
uint temp=0;
temp=(uint)y*96+x;
if(temp<512)return BUFFER[temp];
else return pbuffer[temp-512];
}
//x:0~7,y:0~96
//寫入lcdram的數據
void lcd_write(uchar x,uchar y,uchar data)
{
uint temp=0;
temp=(uint)y*96+x;
if(temp<512)BUFFER[temp]=data;
else pbuffer[temp-512]=data;
}
//在 96*64的范圍內任意點畫點
//val:1,填充1;val:填充0;
void WritePixel(uchar x,uchar y,uchar val)
{
uchar lcdram=0,temp=0x01;
lcdram=lcd_read(x,y/8);
temp<<=7-y%8;
if(val)lcdram|=temp;//填充1
else //填充0
{
temp=~temp;
lcdram&=temp;
}
lcd_write(x,y/8,lcdram);
}
//讀取指定位置的一點
//x:0~23;y:0~16
uchar ReadPixel(uchar x,uchar y)
{
uchar lcdram=0;
x=x*4;y=y*4;
lcdram=lcd_read(x,y/8);//讀出點位置
lcdram>>=7-y%8;
if(lcdram&0x01)return 1;
else return 0;
}
//在 24*16的范圍內任意點畫點(每點4*4大小)
//畫一個小方塊
void Big_pinxl(uchar x,uchar y,uchar val)
{
uchar t1,t2;
for(t1=0;t1<4;t1++)
for(t2=0;t2<4;t2++)WritePixel(4*x+t1,4*y+t2,val);//畫點
}
//清除lcdsram
void clearlcdram(void)
{
uint t;
for(t=0;t<1024;t++)
{
if(t<512)BUFFER[t]=0x00;
else pbuffer[t-512]=0x00;
}
}
//保存文件時顯示的界面
//不帶清屏!!!
void save_show(void)
{
LCD_write_cstr(2,35,"Saveing.");
delay_ms(800);
LCD_write_cstr(2,35,"Saveing..");
delay_ms(800);
LCD_write_cstr(2,35,"Saveing...");
delay_ms(800);
LCD_write_cstr(2,35,"Saveing....");
delay_ms(800);
}
//音樂模式下的界面顯示
//顯示MP3的基本信息
void MP3_msg(uchar pause)
{
uchar t;
Show_num(0,12,voltemp[0]);//顯示音量
Show_num(0,40,voltemp[1]+7);//顯示低音
Show_num(0,68,voltemp[2]+7);//顯示高音
Show_char(0,96,dspram+'0');//顯示dsp1
if(SINGLE)Show_icon(0,105,10);//單曲循環
else Show_icon(0,105,9);//順序播放
if(LYRIC)Show_icon(0,120,11);//顯示LRC圖標
else Show_icon(0,120,14);//不顯示圖標
//顯示暫停與否的圖標
Show_icon(3,0,12+pause);//顯示播放暫停
//顯示超重低音圖標
Set_page(7);//定位行(頁0~7)
Set_column(100);//定位列
if(voltemp[3]==0)for(t=0;t<24;t++)Write_data(bass[t]);//顯示圖標
else for(t=0;t<24;t++)Write_data(0x00); //不顯示圖標
}
//音樂模式下的界面顯示
//顯示MP3播放時的界面
unsigned int file_bps=0;//比特率
unsigned int off_time=0;//偏移時間
void Play_GUI(void)
{
uchar t;
Cleardisplay(4); //清屏
invt=0; //防止反相顯示
off_time=0;//清除偏移時間寄存器
file_bps=0;//清除比特率寄存器
for(t=0;t<4;t++)Show_icon(0,28*t,5+t);
Set_page(6);//定位行(頁0~7)
Set_column(12);//定位列
Write_data(0xFC);
for(t=0;t<78;t++)Write_data(0x84);//顯示進度調
Write_data(0xFC);
Set_column(111);//顯示Kbps符號
for(t=0;t<20;t++)Write_data(kbps[t]);
}
//音樂模式下的進度條顯示
//MP3播放時的進度條顯示
void Pro_msg(unsigned long npos,uchar mnum)
{
uint temptime=0;
uchar t;
if(file_bps>0)temptime=npos/(file_bps*125);//獲得當前的時間
if(temptime!=off_time)//秒鐘變化了,更新數據
{
off_time=temptime;
//顯示當前運行時間
Show_mininum(7,20,off_time/60);//顯示分鐘
show_minichar(7,32,10);//顯示冒號
Show_mininum(7,38,off_time%60);//顯示秒鐘
}
npos=npos*80;//放大一百倍
mnum=npos/m_c[mnum].FileLen;//獲得當前的位置百分比
if(mnum>80)return;//越界處理
Set_page(6);//定位行(頁0~7)
Set_column(12);//定位列
for(t=0;t<mnum;t++)Write_data(0xFC);
}
//設置模式下的界面顯示
//顯示vs1003的gui圖標
void Vs1003_GUI(void)
{
Cleardisplay(4); //清屏
invt=0; //防止反相顯示
LCD_write_cstr(0,35,"VS1003 Set");
//音量界面
LCD_write_cstr(1,35,"Volume:");
//高頻界面
LCD_write_cstr(2,0,"H Freq:");
LCD_write_cstr(2,54,"Khz");
LCD_write_cstr(2,78,"Treb:");
//低音界面
LCD_write_cstr(3,0,"L Freq:");
LCD_write_cstr(3,54,"0hz");
LCD_write_cstr(3,78,"Bass:");
}
//設置模式下的信息顯示
void Vs1003_msg()
{
//顯示音量大小
Show_char(1,77,vs1003ram[4]/100+'0');
Show_num(1,83,vs1003ram[4]);
//高頻界面
Show_num(2,42,vs1003ram[1]);//高頻大小
Show_num(2,108,vs1003ram[0]);//設定dB
//低音界面
Show_num(3,42,vs1003ram[3]);//低頻大小
Show_num(3,108,vs1003ram[2]);//設定dB
}
//收音機頻率顯示
void Show_Freq(unsigned char x,unsigned char y,unsigned int num)
{
Show_char(x,y,(num/1000)%10+'0');
Show_char(x,y+6,(num/100)%10+'0');
Show_char(x,y+12,(num/10)%10+'0');
Show_char(x,y+18,'.');
Show_char(x,y+24,num%10+'0');
Show_char(x,y+30,'M');
}
//---------------------LCD初始化-----------------------
void LCD_init()
{
DDRC|=0XFC; //PORTC.2~7輸出
LCD_SDA=0; //初始化為0
LCD_SCK=0;
LCD_RS=0;
LCD_RST=1;
LCD_CS=1;
LCD_LED=0; //關閉背光
LCD_RST=0; //硬復位
delay_ms(10);
LCD_RST=1;
Write_comd(0xae); //0B10101110,最后一位為0 關閉顯示
Write_comd(0xa1); //ADC select,remap 131-->0,設定行對應起始位置
Write_comd(0xc8); //com select,remap 63-->0 ,設定列對應起始位置
Write_comd(0xa2); //lcd bias select 1/9 BIAS,設置偏壓,不用管,默認1/9
Write_comd(0x2f); //power control(VB,VR,VF=1,1,1),電壓控制,不用管
Write_comd(0x22); //Set Regulator rsistor ratio ,粗調對比度 0~7.作用不大
Write_comd(0x81); //Contrast Control Register ,細調對比度
Write_comd(0x18); //對比度值:0~63,總共64級,值越小,越暗
delay_ms(7); //延時
Write_comd(0xaf); //0B10101111,最后一位為1 開啟顯示
Cleardisplay(4); //清屏
//Write_comd(0xad);//TURN ON THE STATIC INDICATOR MODE
//Write_comd(0x02);//是否要發送第二級命令
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -