?? avryejing.c
字號:
#include"mega16.h"
#include"delay.h"
#include"string.h"
#include "zimo.c"
#define Line_Len 30 //
#define Data_Addr PORTC //C口輸出
#define Date_dir DDRC //C口方向選擇
#define Date_in PINC //C口輸入
#define MyWR PORTA.0 //WR:寫選通信號,低電平有效,輸入信號。
#define MyRD PORTA.1 //RD:讀選通信號,低電平有效,輸入信號。
#define MyCE PORTB.0 //CE:輸出,顯示緩沖區(qū)片選信號,低電平有效。
#define MyCD PORTA.2 //C/D:通道選擇信號,1為指令通道,0為數(shù)據(jù)通道
#define MyWR_en DDRA.0
#define MyRD_en DDRA.1
#define MyCE_en DDRB.0
#define MyCD_en DDRA.2
/*******送數(shù)據(jù)********/
void Post_Data(unsigned char msg)
{Date_dir=0xff;
Data_Addr=0xff;
MyCE=0;
MyCD=0;
MyWR=0;
delay_us(10);
Data_Addr = msg;
MyWR=1;
MyCE=1;
}
//------------送一條指令函數(shù)-----------------
void Post_Com(unsigned char command)
{Date_dir=0xff;
MyCE=0;
MyCD=1;
MyWR=0;
Data_Addr=command;
MyWR=1;
MyCE=1;
}
//-------------接收一幀數(shù)據(jù)-------------------
unsigned char Recieve()
{unsigned char messege;
Date_dir=0xff;
Data_Addr=0xFF;
MyCE=0;
MyCD=1;
MyRD=0;
Date_dir=0;
messege=Date_in;
MyRD=1;
MyCE=1;
Date_dir=0xff;
return (messege);
}
//*************************************
//讀狀態(tài)函數(shù)
//*************************************
void Read_Sta(unsigned char mark)
{
bit exit=0;
unsigned char Sta;
while(1)
{
Sta=Recieve(); //取得lcd當前狀態(tài)
switch(mark) //得到需要的狀態(tài)
{
case 1:if((Sta&0x03)==0x03)exit=1;break; //分離狀態(tài)1,讀寫狀態(tài)
case 2:if(Sta&0x04)exit=1; break; //分離狀態(tài)2
case 3:if(Sta&0x10)exit=1; break; //分離狀態(tài)3
default:break;
}
if(exit)break; //確認退出
}
}
//*************************************
//通訊函數(shù)
//說明:參數(shù)mark:傳送的數(shù)據(jù),2為兩幀dat1和dat2都有效;1為一幀dat1有效;dat1為數(shù)據(jù)1, dat2為數(shù)據(jù)2,com為指令碼
//*************************************
void Send_lcd(unsigned char mark,unsigned char dat1,unsigned char dat2,unsigned char com)
{
if(mark) //判斷指令類型
{
Read_Sta(1);
Post_Data(dat1); //類型1和2 ,dat1均有效
if(mark==2)
{
Read_Sta(1);
Post_Data(dat2); //類型2時dat2有效
}
}
Read_Sta(1);
Post_Com(com); //送指令碼
}
//*************************************
//清顯示函數(shù)
//說明:此函數(shù)可將液晶屏內(nèi)從00單元開始8200單元結(jié)束的所有區(qū)域數(shù)據(jù)清零,但是不會對CGRAM漢字字模區(qū)清零
//************************************
void Clear()
{
unsigned int i;
//Send_lcd(2,0x00,0x00,0x21); //置光標首地址(0x00,0x00)
Send_lcd(2,0x00,0x00,0x24);
Send_lcd(0,0x00,0x00,0xb0); //設(shè)置自動寫方式
/*for(i=0;i<0x1b00;i++)
{Read_Sta(3); //判斷狀態(tài)三(自動寫標志位)
Post_Msg(0x00); //當前地址數(shù)據(jù)清零
}*/
for(i=0;i<5888;i++)
{Read_Sta(3);
Post_Data(0x00);
}
Send_lcd(0,0x00,0x00,0xb2); //自動寫入結(jié)束
}
void Reset_Cgram()
{
unsigned int i;
Send_lcd(2,0x03,0x00,0x22); //置CGRAM偏置地址為0x03(0011 100000 000)
Send_lcd(2,0x00,0x1c,0x24); //置CGRAM字模首地址為0x1c (001 1100 00000000)
Send_lcd(0,0x00,0x00,0xb0); //設(shè)置自動寫方式,(地址自動增一)
for(i=0;i<1024;i++) //將漢字點陣寫入對應(yīng)CGRAM區(qū)域
{
Read_Sta(3); //讀狀態(tài)三,寫標志判斷
//delay_us(100);
Post_Data(k[i]);
}
Send_lcd(0,0x00,0x00,0xb2); //自動寫入結(jié)束
}
//************************************
//顯示屏初始化函數(shù)
//************************************
void resetlcd()
{ MyWR_en=1;
MyRD_en=1;
MyCE_en=1;
MyCD_en=1;
Date_dir=0xff;
Data_Addr=0xff;
Clear();
Reset_Cgram();
Send_lcd(2,0x00,0x00,0x40); //文本區(qū)首地址(0x00,0x00)
Send_lcd(2,Line_Len,0x00,0x41); //文本區(qū)寬度(30字符)
Send_lcd(2,0x00,0x08,0x42); //圖形區(qū)首地址(0x00,0x08)
Send_lcd(2,Line_Len,0x00,0x43); //圖形區(qū)寬度(30字符位置)
Send_lcd(0,0x00,0x00,0xa0); //光標形狀態(tài)(一行高度)
Send_lcd(0,0x00,0x00,0x80); //點陣邏輯"或"合成
Send_lcd(0,0x00,0x00,0x9f); //開文本顯示區(qū),開圖形顯示區(qū),顯示光標,置光標閃爍
}
//************************************
//顯示單個英文字符函數(shù)
//說明:輸入?yún)?shù)x_h:字符行坐標,(0-15),y_l:字符列坐標(0-29),word為字符代碼(支持ASCII碼)
//************************************
void word(unsigned char x_h,unsigned char y_l,unsigned char word)
{ unsigned int sum;
sum=(unsigned int)(Line_Len)*(unsigned int)(x_h)+(unsigned int)(y_l);//計算當前字符位置以前的總點陣數(shù)量
Send_lcd(2,sum%256,sum/256,0x24); //轉(zhuǎn)換為實際行和列地址,并寫入LCD
Send_lcd(1,word,0x00,0xc0); //寫入LCD當前字符數(shù)據(jù)
Send_lcd(2,0,0,0x24); //光標回位
}
//************************************
//顯示英文字符串函數(shù)
//說明:輸入?yún)?shù)x_h:字符串行坐標(0-15),y_l:字符串起始列坐標(0-29),word_list:字符串指針,(提示:當本行寫滿時,會自動換行)
//************************************
void listword(unsigned char x_h,unsigned char y_l,unsigned char *word_list)
{
unsigned char length=0,i=0;
length=strlen(word_list);
for(i=0;i<length;i++)
{word(x_h,y_l,word_list[i]-32);
y_l++;
}
Send_lcd(2,0,0,0x24);
}
//顯示漢字函數(shù)
void chinese(unsigned char x_h,char y_l,unsigned char dat)
{
unsigned int sum;
dat=0x80+dat*4; //得到實際地址
sum=(unsigned int)(x_h)*(unsigned int)(Line_Len)+(unsigned int)y_l; //得到當前字符位置
y_l=sum%256; //得到顯示列數(shù)
x_h=sum/256; //得到顯示行數(shù)
Send_lcd(2,y_l,x_h,0x24); //置顯示地址
Send_lcd(1,dat,0x00,0xc0); //送顯示值--漢字左上部分
Send_lcd(1,dat+2,0x00,0xc0); //送顯示值--漢字右上部分
sum=sum+Line_Len; //修正下半部分字符位置
y_l=sum%256; //得到顯示列數(shù)
x_h=sum/256; //得到顯示行數(shù)
Send_lcd(2,y_l,x_h,0x24); //置顯示地址
Send_lcd(1,dat+1,0x00,0xc0); //送顯示值--漢字左下部分
Send_lcd(1,dat+3,0x00,0xc0); //送顯示值--漢字右下部分
Send_lcd(2,0,0,0x24);
}
//************************************
//畫點函數(shù)
//說明:該函數(shù)可以產(chǎn)行屏幕上的任意位置上的點,輸入?yún)?shù),X:行坐標(0-127)Y:列坐標(0-239)
// 1:畫實點,0:畫虛點
//************************************
void point(unsigned char X,unsigned char Y,unsigned char m)
{
unsigned int Sum;
Sum=(unsigned int)(X)*(unsigned int)(Line_Len)*8+(unsigned int)Y;//得到當單位置前的點陣和
Send_lcd(2,Sum/8,Sum/2048+0x08,0x24); //換算出實際行列坐標,并將操作地址寫入lcd
if(m) Send_lcd(0,0x00,0x00,(0x07-Y%8)|0xf8); //換算出當前位,將該位置1顯示
else Send_lcd(0,0x00,0x00,(0x07-Y%8)|0xf0);
}/* */
void cursor(unsigned char y,unsigned char x)
{Send_lcd(2,x,y,0x21);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
減小字號
Ctrl + -