標(biāo)題: 基于FPGA的LCD1602原理綜述 [打印本頁]
作者: mcmc1 時間: 2018-5-6 19:53
標(biāo)題: 基于FPGA的LCD1602原理綜述
LCD1602的簡單使用原理——跟大家分享我學(xué)習(xí)1602的總結(jié)與體會
我的總結(jié)主要分為這幾部分:
①LCD1602的硬件特性及引腳功能
②LCD1602的時序特性
③LCD1602的使用原理(包括帶字庫和不帶字庫的簡要使用方法,控制顯示指令)
④基于FPGA的LCD1602使用案例
Part 1. LCD1602的硬件特性及引腳功能
LCD1602顧名思義是一種02*16,即為兩行十六列的液晶顯示屏,液晶兩行,每行可以顯示16個字符,但是CGRAM及CGROM里面一共有160個字符,包括阿拉伯?dāng)?shù)字,英文字母大小寫,常用符號及日文。每個字符對應(yīng)于一個ASCII碼值,在液晶顯示屏上顯示對應(yīng)的字符時候,只需要將對應(yīng)的ASCII碼寫到DDRAM中就好,詳細(xì)的步驟會在下面細(xì)說。液晶板上排列著5*8的字符點(diǎn)陣,8行,每行5個點(diǎn)位,高電平1就是該點(diǎn)顯示,低電平0就是該點(diǎn)不顯示。
RS,R/W,E控制數(shù)據(jù)端口DB0~DB7,數(shù)據(jù)的命令的讀寫由控制端口控制,并通過數(shù)據(jù)端口傳輸。端口其他特性這里不再贅述,詳細(xì)見1602液晶手冊。O(∩_∩)O
二、硬件特性:
①CGRAM 和CGROM
CGRAM:character generator ram CGROM:character generator rom
CGRAM的地址空間:
CGRAM的地址是0x40~0x7F, 64個地址空間,每個地址雙字節(jié),一共128字節(jié),一個字符 是8個字節(jié),所以一共能顯示8個自定義字符(每個雙字節(jié)地址只有一個字節(jié)是被自定義字符數(shù)據(jù)寫入的,另外個字節(jié)無效,因?yàn)镃GARM的字符代碼的規(guī)定,詳細(xì)原因見下面)
字符對應(yīng)的區(qū)位碼如下圖所示:
CGRAM: 字符產(chǎn)生ram,用來存放用戶自定義的字符,如上圖的兩條(1)~(8),區(qū)位碼為0x00~0x0F.0x00~0x07對應(yīng)于(1)~(8);0x08~0x0F對應(yīng)于下一條(1)~(8),雖然看起來有16個地址,但是其實(shí)只要8個地址可用,CGRAM的“字符碼”規(guī)定0~2為地址,3位無效,4~7位全為0,因此CGRAM的字符碼等效為0000X111,X為無效位,最后三位的地址只要八個,所以實(shí)際能用的只有8個。
其他為CGROM中自帶的字符,區(qū)位碼從0x21~0x7F,以各自的ASCII碼作為區(qū)位碼表示的基本字符。
將自定義的字符字模數(shù)8*8據(jù)寫入,字符數(shù)據(jù)有八行,每行八位點(diǎn)陣。
②DDRAM
DDRAM:data display ram數(shù)據(jù)顯示存儲器
DDRAM的地址空間與屏幕的對應(yīng)關(guān)系如下圖:
DDRAM的地址空間一共有80字節(jié)
在1602中,我們只要前面16行就行,其地址和屏幕的對應(yīng)關(guān)系:
Part 2. LCD1602的時序特性
讀狀態(tài):RS=0 ,RW=1,E=1
讀數(shù)據(jù):RS=1,RW=1,E=1
寫命令:RS=0,RW=0,E=下降沿脈沖;DB0~DB7指令字
寫數(shù)據(jù):RS=1,RW=0,E=下降沿脈沖;DB0~DB7數(shù)據(jù)
在E=1的時候?qū)懭霐?shù)據(jù),在數(shù)據(jù)寫完之后,E來一個下降沿,把數(shù)據(jù)送到LCD。
Part4.LCD1602的指令功能
<1>cursor move to first digit
<2>地址計(jì)數(shù)器AC的值設(shè)置為0;
<1>把光標(biāo)撤回到顯示器的左上方
<2>把地址計(jì)數(shù)器Ac設(shè)置為0;
<3>保持DDRAM的值不變
- Entry Mode set輸入模式設(shè)置指令
Function:
I/D set cursor move direction H:increase L:decrease
寫入數(shù)據(jù)之后的光標(biāo)移動的方向H:右移L:左移
S specifies shift of display H:display is shifted L:display is not shifted
寫入一個數(shù)據(jù)之后顯示屏移動或者不移動
- Display On/off顯示開關(guān)控制指令
D:H:顯示開; L:顯示關(guān)
C:H:光標(biāo)開 L:光標(biāo)關(guān)
B:H: 光標(biāo)閃爍 L:光標(biāo)不閃爍
- Shift 設(shè)置顯示屏或者光標(biāo)移動的方向
S/C:顯示屏還是光標(biāo) H:顯示屏移動L:光標(biāo)移動
R/L:向左移動還是向右移動H:右移L;左移(光標(biāo)右移:AC值加1;光標(biāo)左移:AC值減1)
DL:data length L:數(shù)據(jù)總線為4位 H:數(shù)據(jù)總線為8位
N :number line L:1行 顯示 H:2行顯示
F : L:5×7點(diǎn)陣/每字符 H:5×10點(diǎn)陣/每字符
7、Set CGRAM Address
設(shè)置CGRAM的地址,我們將我們自定義的字模數(shù)據(jù)存入對應(yīng)的地址,從0x40~0x7F,128字節(jié),8個字符的字模數(shù)據(jù)可存入。
- Set DDRAM Address,(表格中寫錯了,是DDRAM)
與CGRAM一樣,在往DDRAM里面寫入想要顯示的字符的字符區(qū)位碼的之前需要將存儲字符區(qū)位碼的地址首先寫入。DDRAM的地址空間以上已述。(加地址的時候我們要加上0x80,因?yàn)閷懭氲刂返臅r候DB7必須為1)
- Read Busy Flag and the Address讀取忙碌標(biāo)志和地址計(jì)數(shù)器的值
BF:H:忙碌,表示無法結(jié)束單片機(jī)送來的數(shù)據(jù);L:準(zhǔn)備就緒,可以接受數(shù)據(jù)
當(dāng)內(nèi)部操作正在進(jìn)行的時候,讀取BF的值
AC:讀取地址計(jì)數(shù)器的值
- 數(shù)據(jù)寫入CGRAM和DDRAM
- 從CGRAM和DDRAM讀取數(shù)據(jù)
Part5.LCD1602的簡要原理
顯示字庫中本來就有的字符和顯示自定義的字符
步驟一:系統(tǒng)初始化和LCD初始化
步驟二:LCD液晶屏上面每個字符對應(yīng)于DDRAm的地址,你想要把字符寫進(jìn)屏幕哪個位置,就往DDRAM寫入該位置所對應(yīng)的地址。(對應(yīng)的地址在上述已說)
步驟三:字庫中本來已經(jīng)存在的字符各自有對應(yīng)的字符區(qū)位碼,其實(shí)就是每個字符對應(yīng)的ASCII碼(見字符表格)。你要顯示哪個字符,只要將該字符對應(yīng)的ASCII碼寫入DDRAM就搞定了,這個是很簡單的。
其實(shí)顯示自定義的字符和字庫字符差不多的,只需要將你自定義的字符用取模工具得到字模的數(shù)組數(shù)據(jù)之后。之后的步驟和顯示字庫字符是一樣一樣滴。
步驟一:系統(tǒng)初始化和LCD初始化
步驟二:搞清楚字符點(diǎn)陣的格式是5*8,通過取字模工具得出自定義字符的字模數(shù)據(jù),再寫入相應(yīng)的CGRAM地址,一個地址寫入一個一個字節(jié)數(shù)據(jù)(一個字節(jié)的8位,前3位為0,點(diǎn)陣的格式5*8)
步驟三:同顯示字庫中本來就有的字符一樣的做法
Part 6. 基于FPGA的LCD1602使用案例
以下的程序例子是基于FPGA的液晶1602時鐘,是利用自帶字庫的方式顯示實(shí)時時鐘,主要通過時鐘控制狀態(tài)機(jī)來實(shí)現(xiàn)1602的工作程序(尚未驗(yàn)證嘿嘿)
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_arith.all;
- use ieee.std_logic_unsigned.all;
- entity lcd is
- port(
- clk:in std_logic;
- rw:out std_logic;
- rs:out std_logic;
- lcd_rst:out std_logic;
- data:out std_logic_vector( 7 downto 0);
- en:out std_logic
- );
- end lcd;
- architecture lcd1602 of lcd is
- signal clk_1m:std_logic:='1';
- signal clk_1s:std_logic:='1';
- type state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10);--定義狀態(tài)類型case語句上有具體說明
- signal current_s:state:=s0;
- type data_buffer is array(0 to 9) of std_logic_vector(7 downto 0);---定義數(shù)組類型
- signal
- date_buf:data_buffer:=(x"30",x"31",x"3a",x"33",x"34",x"3a",x"36",x"37",x"2a",x"2a");
- signal shi,fen,miao:integer range 0 to 100:=0;
- signal shi1,fen1,miao1:integer range 0 to 100:=0;
- begin
- process(clk)---對CLK 50M進(jìn)行分頻系數(shù)為50的分頻clk_1m
- variable cnt:integer range 0 to 10000;---得到1M的時鐘
- begin
- if clk'event and clk='1' then
- if cnt=24 then
- clk_1m <= not clk_1m;cnt:=0;
- else cnt:=cnt+1;
- end if;
- end if;
- end process;
- process(clk)
- variable cnt:integer range 0 to 10000;
- variable cnt1:integer range 0 to 5000;
- begin
- if clk'event and clk='1' then
- if cnt=24900000 then ---cnt:0~24900000counter
- clk_1s <= not clk_1s;cnt:=0;------fenpin clk_1s
- elsif cnt1=2000 then cnt:=cnt+1;cnt1:=0;---cnt1: 0~2000 counter
- else cnt1:=cnt1+1;
- end if;
- end if;
- end process;
- process(clk_1s)
- begin
- if clk_1s'event and clk_1s='1' then
- if miao =59 then
- miao<=0;
- if fen=59 then
- fen<=0;
- if shi=23 then
- shi<=0;
- else shi<=shi+1;
- end if;
- else fen<=fen+1;
- end if;
- else miao<=miao+1;
- end if;
- end if;
- date_buf(0)<=conv_std_logic_vector (shi /10 ,8)+x"30";--強(qiáng)制轉(zhuǎn)換邏輯矢量,8bit
- date_buf(1)<=conv_std_logic_vector (shi mod 10,8)+x"30";
- date_buf(3)<=conv_std_logic_vector (fen /10,8)+x"30";
- date_buf(4)<=conv_std_logic_vector (fen mod 10,8)+x"30";
- date_buf(6)<=conv_std_logic_vector (miao /10,8)+x"30";
- date_buf(7)<=conv_std_logic_vector (miao mod 10 ,8)+x"30";
- end process;
- process(clk_1m,current_s,date_buf)
- variable i:integer range 0 to 11:=0;
- variable cnt1:integer range 0 to 100;
- variable cnt2:integer range 0 to 100;
- variable cnt3:integer range 0 to 100;
- variable cnt4:integer range 0 to 100;
- variable cnt5:integer range 0 to 100;
- variable cnt6:integer range 0 to 100;
- variable cnt7:integer range 0 to 100;
- variable cnt8:integer range 0 to 60000;
- begin
- current_s<=s0;
- if (clk_1m'event and clk_1m='1') then
- current_s <= current_s ;
- case current_s is
- when s0=>
- if cnt1 <5000 then
- lcd_rst<='0';cnt1:=cnt1+1;
- elsif cnt1<10000 then
- lcd_rst<='1';cnt1:=cnt1+1;
- elsif cnt1=10000 then lcd_rst<='1';current_s<=s1;cnt1:=0;
- end if;
-
- when s1=> cnt2:=cnt2+1;----設(shè)置功能指令字:8位數(shù)據(jù)總線,兩行顯示,5*7點(diǎn)陣
- if cnt2<10 then rw<='0';rs<='0';----command 0
- elsif cnt2<20 then data<=x"38";00111000
- elsif cnt2<30 then en<='1';
- elsif cnt2<70 then en<='0';
- elsif cnt2=100 then cnt2:=0;current_s<=s2;
- end if;
- when s2=> ----顯示開關(guān)控制指令:D顯示開,C光標(biāo)開,B光標(biāo)閃爍
- cnt3:=cnt3+1;
- if cnt3<10 then rw<='0';rs<='0';
- elsif cnt3<20 then data<=x"0f";----00001111
- elsif cnt3<30 then en<='1';
- elsif cnt3<70 then en<='0';
- elsif cnt3=100 then cnt3:=0;current_s<=s3;
- end if;
- when s3=> -----輸入模式設(shè)置指令,寫入一個字符后光標(biāo)右移,顯示屏不
- cnt4:=cnt4+1; -----移動
- if cnt4<10 then rw<='0';rs<='0';
- elsif cnt4<20 then data<=x"06";---00000110
- elsif cnt4<30 then en<='1';
- elsif cnt4<70 then en<='0';
- elsif cnt4=100 then cnt4:=0;current_s<=s5;
- end if;
-
- when s4=> -----displayclear 顯示清屏
- cnt5:=cnt5+1;
- if cnt5<10 then rw<='0';rs<='0';
- elsif cnt5<20 then data<=x"01";---00000001
- elsif cnt5<30 then en<='1';
- elsif cnt5<70 then en<='0';
- elsif cnt5=100 then cnt5:=0;current_s<=s5;
- end if;
-
- when s5=> -----寫DDRAM地址0X00+0X80
- cnt6:=cnt6+1;
- if cnt6<10 then rw<='0';rs<='0';
- elsif cnt6<20 then data<=x"80";---10000000
- elsif cnt6<30 then en<='1';
- elsif cnt6<70 then en<='0';
- elsif cnt6=100 then cnt6:=0;current_s<=s6;
- end if;
- when s6=>
- cnt7:=cnt7+1;
- if cnt7<10 then rw<='0';rs<='1';----WRITE DATA
- elsif cnt7<20 then data<=date_buf(i);--date_buf(i);時分秒的數(shù)據(jù)的ASCII碼
- elsif cnt7<30 then en<='1'; ---執(zhí)行時間為40us
- elsif cnt7<70 then en<='0';
- elsif cnt7=100 then
- if i=9 then cnt7:=0;current_s<=s7;i:=0;
- else i:=i+1;current_s<=s6;cnt7:=0;end if;
- end if;
-
- when s7=>if cnt8<8000 then cnt8:=cnt8+1;
- else cnt8:=0;current_s<=s5;----循環(huán)等待8000的計(jì)數(shù)器,回到S5,繼續(xù)寫入DDRAM地 ------址,進(jìn)而
- end if;-------------------------寫入數(shù)據(jù)
- when others=>null;
- end case;
- end if;
- end process;
- end lcd1602;
復(fù)制代碼
-
-
基于FPGA的LCD1602原理綜述.doc
2018-5-6 19:53 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
447.5 KB, 下載次數(shù): 9, 下載積分: 黑幣 -5
歡迎光臨 (http://www.zg4o1577.cn/bbs/) |
Powered by Discuz! X3.1 |
主站蜘蛛池模板:
国产一区二区三区在线
|
午夜影院中文字幕
|
久久午夜视频
|
国产成人精品久久二区二区
|
国产成人综合网
|
97久久久久久
|
亚洲成人一区二区
|
久久福利网站
|
产真a观专区
|
欧美精品一区在线
|
国产精品久久久一区二区三区
|
久久y
|
欧美一区精品
|
亚洲精品久久久久中文字幕欢迎你
|
国产亚韩
|
国产a视频
|
欧美黄在线观看
|
午夜视频免费在线观看
|
久热精品在线观看视频
|
日本午夜视频
|
亚洲精品毛片av
|
91精品久久久久
|
日韩有码一区
|
中文字幕日韩欧美
|
综合精品
|
91精品国产色综合久久
|
欧美福利精品
|
亚洲综合久久网
|
www免费视频
|
九九亚洲精品
|
日韩欧美中文在线
|
国产一区二
|
国产在线一区二区三区
|
欧美一级片在线观看
|
香蕉视频91|
日日摸日日碰夜夜爽2015电影
|
99久久成人
|
免费不卡一区
|
偷拍亚洲色图
|
激情婷婷成人
|
亚洲国产成人精品女人久久久野战
|