FPGA驱动LCD1602实现万年历Word格式文档下载.docx
《FPGA驱动LCD1602实现万年历Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《FPGA驱动LCD1602实现万年历Word格式文档下载.docx(13页珍藏版)》请在冰豆网上搜索。
![FPGA驱动LCD1602实现万年历Word格式文档下载.docx](https://file1.bdocx.com/fileroot1/2023-1/22/6ae70480-6c68-4dd6-b999-c6ef5b89d438/6ae70480-6c68-4dd6-b999-c6ef5b89d4381.gif)
reg[31:
0]count;
always@(posedgeclk)
begin
count<
=count+1;
if(count==500000)
=0;
key1_reg1<
=key1;
key2_reg1<
=key2;
key3_reg1<
=key3;
end
key1_reg2<
=key1_reg1;
key2_reg2<
=key2_reg1;
key3_reg2<
=key3_reg1;
key1_out<
=key1_reg2&
(!
key1_reg1);
key2_out<
=key2_reg2&
key2_reg1);
key3_out<
=key3_reg2&
key3_reg1);
endmodule
底层模块:
moduledisp
regrs,en_sel;
reg[7:
reg[14:
0]year;
0]shi,fen,miao,month,dat;
0]count,count1;
//LCDCLK分频计数器
reglcd_clk;
//2行32个数据寄存器
0]one_1,one_2,one_3,one_4,one_5,one_6,one_7,one_8,one_9,one_10,one_11,one_12,one_13,one_14,one_15,one_16;
0]two_1,two_2,two_3,two_4,two_5,two_6,two_7,two_8,two_9,two_10,two_11,two_12,two_13,two_14,two_15,two_16;
0]next;
parameter
state0
=8'
h00,
//设置8位格式,2行,5*7
8'
h38;
state1
h01,
//整体显示,关光标,不闪烁
h0C
闪烁8'
h0e
state2
h02,
//设定输入方式,增量不移位
h06
state3
h03,
//清除显示
h01
state4
h04,
//显示第一行的指令
80H
state5
h05,
//显示第二行的指令
80H+40H
scan
h06,
nul
h07;
data0
h10,
//2行32个数据状态
data1
h11,
data2
h12,
data3
h13,
data4
h14,
data5
h15,
data6
h16,
data7
h17,
data8
h18,
data9
h19,
data10
h20,
data11
h21,
data12
h22,
data13
h23,
data14
h24,
data15
h25,
data16
h26,
data17
h27,
data18
h28,
data19
h29,
data20
h30,
data21
h31,
data22
h32,
data23
h33,
data24
h34,
data25
h35,
data26
h36,
data27
h37,
data28
h38,
data29
h39,
data30
h40,
data31
h41;
initial
//第一行显示年-月-日
星期
//MonTueWed
ThurFriSatSun
one_1<
="
"
;
one_2<
one_3<
one_4<
one_5<
-"
one_6<
one_7<
one_8<
one_9<
one_10<
one_11<
one_12<
one_13<
one_14<
one_15<
one_16<
//第二行显示Clock:
00-00-00
two_1<
C"
two_2<
l"
two_3<
o"
two_4<
c"
two_5<
k"
two_6<
:
"
two_7<
two_8<
two_9<
two_10<
two_11<
two_12<
two_13<
two_14<
two_15<
two_16<
shi<
d0;
fen<
miao<
//======================产生LCD时序脉冲===========================
always@(posedgeclk)
//获得LCD时钟
if(count==32'
d50000)
=32'
b0;
lcd_clk<
=~lcd_clk;
//=====================产生闪烁扫描时钟===========================
0]count2;
reg
scan_flag;
always@(posedgeclkornegedgerst)
//获得校准时间选中闪烁状态
if(!
rst)
scan_flag<
=1'
else
count2<
=count2+1;
if(count2==32'
d10000000)
=~scan_flag;
//====================产生按键标志位=================================
reg[3:
0]flag;
always@(posedgeclkornegedgerst)
flag<
=4'
if(key1)
=flag+1'
b1;
if(flag==4'
b1000)
b0000;
//===================计时以及校准=======================================
reg[3:
0]week;
reg[7:
0]dat_flag;
always@(posedgeclkornegedgerst)
//时钟计数器
begin
//初始化显示第一行2012-05-19Sat
第二行:
Clock:
month<
d5;
dat<
d19;
year<
=16'
d2012;
week<
count1<
two_7<
=
(shi/8'
d10)+8'
b00110000;
two_8<
(shi%8'
=(fen/8'
=(fen%8'
=(miao/8'
=(miao%8'
=(year/16'
d1000)+8'
one_2<
=((year%16'
d1000)/16'
d100)+8'
one_3<
d100)/8'
one_4<
=(year%8'
one_6<
=(month/8'
one_7<
=(month%8'
=(dat/8'
=(dat%8'
end
//判断是否为31天的月份
if(month==8'
d1||month==8'
d3||month==8'
d5||month==8'
d7||month==8'
d8||month==8'
d10||month==8'
d12)
dat_flag<
d31;
//判断是否为30天的月份
elseif(month==8'
d4||month==8'
d6||month==8'
d9||month==8'
d11)
d30;
//判断是否为闰年和平年
d2)
if(year%4==0&
&
year%100!
=0||year%400==0)
=28;
elsedat_flag<
=27;
case(week)
//星期
ThuFriSatSun
4'
b0000
//1
M"
n"
b0001
//2
T"
u"
e"
b0010
//3
W"
d"
b0011
//4
h"
b0100
//5
F"
r"
i"
b0101
//6
S"
a"
t"
b0110
//7
endcase
case(flag)
en_sel<
=count1+1'
if(count1==32'
d49999999)
=miao+1'
if(miao==8'
d59)
=fen+1'
if(fen==8'
=shi+1'
if(shi==8'
d23)
=dat+1'
=week+1'
if(week==4'
b0110)
if(dat==dat_flag)
d1;
=month+1'
=year+1'
if(year==16'
d9999)
//可以计1万年
//shi<
=shi;
=fen;
=miao;
=year;
=month;
=dat;
=week;
//调年
case(scan_flag)
1'
b0:
d20;
b1:
if(key2)
//加数
if(key3)
//减数
=year-1'
d0)
d9999;
//调月
=month-1'
d12;
//调日
=dat-1'
if(dat==8'
=dat_flag;
//调星期