资源描述:
《VHDL12864显示采样电压》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//12864显示“采样电压”及keyin输入数字量的后转化为数字:如(“11111”为5.0V)//本例程只是提供一个思路libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_unsigned.all;entitylcd12864isport(clk,reset:instd_logic;en,rw,rs:OUTstd_logic;data:outstd_logic_vector(7downto0
2、);keyin:instd_logic_vector(4downto0));endentitylcd12864;architecturebehavoflcd12864istypestatesis(st0,st1,st2,st3,st4,st5,st6);typeram1isarray(0to9)ofstd_logic_vector(7downto0);typeram2isarray(0to7)ofstd_logic_vector(7downto0);constantcgram1:ram1:=(x"30",x"3
3、1",x"32",x"33",x"34",x"35",x"36",x"37",x"38",x"39");--0123456789的ASCII码constantcyda:ram2:=(x"b2",x"c9",x"d1",x"f9",x"b5",x"e7",x"d1",x"b9");//“采样电压”可查看12864字符手册signalcurrent_state:states;signallcd_clk,clk_out:std_logic;signalshi_clk,yifen_clk,shifen_clk,yimi
4、ao_clk,shimiao_clk:std_logic;signalad:integer;beginprocess(CLK)variablen1:integerrange0to100000;--将输入时钟分频为250hz,4msbeginifrising_edge(Clk)thenifn1<100000thenn1:=n1+1;elsen1:=0;Clk_Out<=notClk_Out;endif;endif;endprocess;en<=clk_out;lcd_clk<=clk_out;RW<='0';pr
5、ocess(clk)beginifclk'eventandclk='1'thenad<=conv_integer(keyin);endif;endprocess;process(LCD_Clk,Reset,Current_State)variablecn2:integerrange0to10;variablemiaoge,miaoshi,fenge,fenshi,shi1,shi2:integerrange0to9;beginifReset='0'thenCurrent_State<=st0;RS<='0';e
6、lsifrising_edge(LCD_Clk)thenCurrent_State<=Current_State;RS<='0';shi2:=(ad-1)/6;shi1:=(ad-1)mod6;caseCurrent_Stateiswhenst0=>--基本指令集动作Data<="00110000";Current_State<=st1;whenst1=>--整体显示设置:光标off反光off:0x0cData<="00001100";Current_State<=st2;--endif;whenst2=>--
7、清除显示,并且认定地址指针为00h:0x01Data<="00000001";Current_State<=st3;whenst3=>--指定游标的移动方向及指定显示的移位:06Data<="00000110";Current_State<=st4;whenst4=>--地址设定从第一行的第一个字开始显示到第五个字地址设定ifcn2<6thencn2:=cn2+1;elsecn2:=0;endif;ifcn2=0thendata<="10001000";--0x80elsifcn2=1thendata<="10
8、001001";--0x81elsifcn2=2thendata<="10000000";--0x82elsifcn2=3thendata<="10000001";--0x83elsifcn2=4thendata<="10000010";--0x83elsifcn2=5thendata<="10000011";--0x83elsifcn2=6thendata<="10001010";-