此程序控制LCD12864液晶屏,IC为KS0108或兼容型号
图形文件获取方法:
在字模提取V21软件中 ,导入一幅128*64黑白图像.
* 参数设置:
* 参数设置->其它选项,选择纵向取模,勾上字节倒序,保留逗号,
* 取模方式为C51。
将生成的数组通过keilc等C编译软件,在编译软件中新建一工程,写入源程序如下:
unsigned char code tab[]=
{
//图像数据
}
编译此工程将得到hex文件.在QII中使用lpm_rom宏功能模块中调用此hex文件.
*
*******************************************************************************/
module newlcd(clock,rst_n,rs,rw,en,data,lcd_cs)
// I/O口声明
input clock //系统时钟
input rst_n //复位信号
output[1:0] lcd_cs //
outputrs //1:数据模式;0:指令模式
outputrw //1:读 *** 作;0:写 *** 作
outputen //使能信号,写 *** 作时在下降沿将数并答亩据举肢送出;读 *** 作时保持高电平
output[7:0] data//绝森LCD数据总线
// I/O寄存器
reg rs
reg en
reg[1:0] lcd_cs
reg[7:0] data
//内部寄存器
reg[3:0] state //状态机
reg[3:0] next_state
reg[20:0] div_cnt //分频计数器
reg[9:0] cnt //写 *** 作计数器
reg cnt_rst //写 *** 作计数器复位信号
wire[7:0] showdata //要显示的数据
reg[1:0] cs_r
reg [2:0] page_addr
reg [5:0] row_addr
//内部网线
wire clk_div//分频时钟
wire clk_divs
wire page_done //写一行数据完成标志位
wire frame_done //写一屏数据完成标志位
wire left_done
//状态机参数
parameter idle =4'b0000,
setbase_1=4'b0001,
setbase_2=4'b0011,
setmode_1=4'b0010,
setmode_2=4'b0110,
SETpage_addr_1=4'b0111,
SETpage_addr_2=4'b0101,
SETrow_addr_1 =4'b1101,
SETrow_addr_2 =4'b1111,
write_right_1 =4'b1110,
write_right_2 =4'b1010,
write_nextpage_1 =4'b1011,
write_nextpage_2 =4'b1001,
wr_data_1 =4'b0100,
wr_data_2 =4'b1100
// set_1=4'b1000
//******************************代码开始*********************************
assign rw = 1'b0 //对LCD始终为写 *** 作
//时钟分频
always@(posedge clock or negedge rst_n)
begin
if(!rst_n)
div_cnt <= 0
else
div_cnt <= div_cnt+1'b1
end
assign clk_div = (div_cnt[15:0] == 20'h7fff)
//状态机转向
always@(posedge clock or negedge rst_n)
begin
if(! rst_n)
state <= idle
else if(clk_div)
state <= next_state
end
//************************状态机逻辑*********************************
always@(state or page_done or left_done or frame_done or cnt or showdata or page_addr or row_addr or cs_r)
begin
rs <= 1'b0
en <= 1'b0
lcd_cs <= cs_r
cnt_rst <= 1'b0
data <= 8'h0
case(state)
idle:
begin
next_state <= setbase_1
cnt_rst <= 1'b1
end
//**************************初始化LCD********************************
setbase_1: //基本指令 *** 作
begin
lcd_cs <= 2'b11
next_state <= setbase_2
data <= 8'hc0
en <= 1'b1
end
setbase_2:
begin
lcd_cs <= 2'b11
next_state <= setmode_1
data <= 8'hc0
end
//******************************************************************
setmode_1:
begin
lcd_cs <= 2'b11
next_state <= setmode_2
data <= 8'h3f
en <=1'b1
end
setmode_2:
begin
next_state <= SETpage_addr_1
data <= 8'h3f
end
//******************************************************************
SETpage_addr_1: //设置页地址
begin
next_state <= SETpage_addr_2
data <=
en <= 1'b1
end
SETpage_addr_2:
begin
next_state <= SETrow_addr_1
data <=
end
SETrow_addr_1: //设置列地址
begin
next_state <= SETrow_addr_2
data <=
en <= 1'b1
end
SETrow_addr_2:
begin
next_state <= wr_data_1
data <=
end
//******************************************************************
/*
write_right_1: //写完左半屏64个,换为右半屏显示
begin
next_state <=write_right_2
row_addr <= 0
end
write_right_2:
begin
next_state <= SETpage_addr_1
end
//******************************************************************
write_nextpage_1: //写完全一行128个
begin
next_state <=write_nextpage_2
row_addr <= 0
end
write_nextpage_2:
begin
next_state <= SETpage_addr_1
end
*/
//******************************************************************
wr_data_1: //写数据到图形显示区
begin
next_state <= wr_data_2
rs <= 1'b1
en <= 1'b1
data <= showdata
end
wr_data_2:
begin
rs <= 1'b1
data <= showdata
if(left_done) //写完左半屏数据64个
begin
if(page_done) //写完一页数据128个
begin
if(frame_done) //写完一屏数据(8页)
next_state <= idle
else
// next_state <= write_nextpage_1
next_state <= SETpage_addr_1
end
else
// next_state <= write_right_1
next_state <= SETpage_addr_1
end
else
next_state <= wr_data_1
end
default: next_state <= idle
endcase
end
//********************************************************************
always@(posedge clock)
begin
if(clk_div)
begin
if(cnt_rst)
begin
cnt <= 0
end
else if(state == wr_data_2)
begin
cnt <= cnt+1'b1
end
end
end
//****************************************************
always@(posedge clock or negedge rst_n)
if(!rst_n)
begin
cs_r <= 2'b01
page_addr <= 0
end
else
if(clk_div &&(state == wr_data_2))
if(page_done)//
begin
cs_r <= 2'b01
page_addr <= page_addr + 1'b1//一页写完时写下一页
end
else
if(left_done)
begin
cs_r <= 2'b10
end
//*********************************************************************
//********************************************************************
assign left_done = (cnt[5:0] == 6'd63) //写完左半屏数据64个
assign page_done = (cnt[6:0] == 7'd127) //写完一页数据128个
assign frame_done = (cnt[9:4] == 7'h3f) //写完一屏数据
//***********************************************************************
//*******************************************************************
//调用ROM(图片数据)
rom rom(.address(cnt+'d8),.clock(clock),.q(showdata))
endmodule
开发板例程 自己看吧
我可以帮助你,你先设置我最佳答案后,我百度Hii教你。
`timescale 1ns / 1ps///////////////////////////////////////////////////////////////搏返///////////////////
// Company:anlogic
/兄宏/ Engineer: liguang
//
// Create Date:11:07:14 02/17/2014
// Design Name:
// Module Name:lcd1602
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
///////基尘饥///////////////////////////////////////////////////////////////////////////
module lcd1602(sys_clk,
sys_rstn ,
lcd_rs ,
lcd_rw ,
lcd_en ,
lcd_data
)
//输入输出信号定义
input sys_clk//系统时钟输入
input sys_rstn //系统复位信号,低电平有效
output lcd_rs //lcd的寄存器选择输出信号
output lcd_rw //lcd的读、写 *** 作选择输出信号
output lcd_en //lcd使能信号
output [7:0] lcd_data //lcd的数据总线(不进行读 *** 作,故为输出)
//寄存器定义
reglcd_rs
regclk_div
reg [17:0] delay_cnt
reg [7:0] lcd_data
reg [4:0] char_cnt
reg [7:0] data_disp
reg [9:0] state
parameteridle = 10'b000000000, //初始状态,下一个状态为CLEAR
clear = 10'b000000001, //清屏
set_function = 10'b000000010, //功能设置:8位数据接口/2行显示/5*8点阵字符
switch_mode = 10'b000000100, //显示开关控制:开显示,光标和闪烁关闭
set_mode = 10'b000001000, //输入方式设置:数据读写 *** 作后,地址自动加一/画面不动
shift= 10'b000010000, //光标、画面位移设置:光标向左平移一个字符位(光标显示是关闭的,所以实际上设置是看不出效果的)
set_ddram1 = 10'b000100000, //设置DDRAM的地址:第一行起始为0x00(注意输出时DB7一定要为1)
set_ddram2 = 10'b001000000, //设置DDRAM的地址:第二行为0x40(注意输出时DB7一定要为1)
write_ram1 = 10'b010000000, //数据写入DDRAM相应的地址
write_ram2 = 10'b100000000 //数据写入DDRAM相应的地址
assign lcd_rw = 1'b0 //没有读 *** 作,R/W信号始终为低电平
assign lcd_en = clk_div//E信号出现高电平以及下降沿的时刻与LCD时钟相同
//时钟分频
always@(posedge sys_clk or negedge sys_rstn)
begin
if(!sys_rstn)
begin
delay_cnt<=18'd0
clk_div<=1'b0
end
else if(delay_cnt==18'd249999)
begin
delay_cnt<=18'd0
clk_div<=~clk_div
end
else
begin
delay_cnt<=delay_cnt+1'b1
clk_div<=clk_div
end
end
always@(posedge clk_div or negedge sys_rstn) //State Machine
begin
if(!sys_rstn)
begin
state <= idle
lcd_data <= 8'b0
char_cnt <= 5'd0
lcd_rs<=1'b0
end
else
begin
case(state)
idle: begin //初始状态
state <= clear
lcd_data <= 8'b0
end
clear: begin //清屏
state <= set_function
lcd_rs<=1'b0
lcd_data <= 8'b00000001
end
set_function: //功能设置(38H):8位数据接口/2行显示/5*8点阵字符
begin
state <= switch_mode
lcd_rs<=1'b0
lcd_data <= 8'b00111000
end
switch_mode: //显示开关控制(0CH):开显示,光标和闪烁关闭
begin
state <= set_mode
lcd_rs<=1'b0
lcd_data <= 8'b00001110
end
set_mode:begin //输入方式设置(06H):数据读写 *** 作后,地址自动加一/画面不动
state <= shift
lcd_rs<=1'b0
lcd_data <= 8'b00000110
end
shift: begin //光标、画面位移设置(10H):光标向左平移一个字符位(光标显示是关闭的,所以实际上设置是看不出效果的)
state <= set_ddram1
lcd_rs<=1'b0
lcd_data <= 8'b0001_0000
end
set_ddram1: //设置DDRAM的地址:第一行起始为00H(注意输出时DB7一定要为1)
begin
state <= write_ram1
lcd_rs<=1'b0
lcd_data <= 8'b1000_0011//Line1
end
set_ddram2: //设置DDRAM的地址:第二行为40H(注意输出时DB7一定要为1)
begin
state <= write_ram2
lcd_rs<=1'b0
lcd_data <= 8'b1100_0000//Line2
end
write_ram1:
begin
if(char_cnt <=5'd10)
begin
char_cnt <= char_cnt + 1'b1
lcd_rs<=1'b1
lcd_data <= data_disp
state <= write_ram1
end
else
begin
state <= set_ddram2
end
end
write_ram2:
begin
if(char_cnt <=5'd26)
begin
char_cnt <= char_cnt + 1'b1
lcd_rs<=1'b1
lcd_data <= data_disp
state <= write_ram2
end
else
begin
char_cnt <=5'd0
state <= shift
end
end
default: state <= idle
endcase
end
end
always @(char_cnt) //输出的字符
begin
case (char_cnt)
5'd0: data_disp = "W"
5'd1: data_disp = "e"
5'd2: data_disp = "l"
5'd3: data_disp = "c"
5'd4: data_disp = "o"
5'd5: data_disp = "m"
5'd6: data_disp = "e"
5'd7: data_disp = " "
5'd8: data_disp = "t"
5'd9: data_disp = "o"
5'd10: data_disp = " "
5'd11: data_disp = "A"
5'd12: data_disp = "n"
5'd13: data_disp = "l"
5'd14: data_disp = "o"
5'd15: data_disp = "g"
5'd16: data_disp = "i"
5'd17: data_disp = "c"
5'd18: data_disp = " "
5'd19: data_disp = "2"
5'd20: data_disp = "0"
5'd21: data_disp = "1"
5'd22: data_disp = "4"
5'd23: data_disp = "0"
5'd24: data_disp = "3"
5'd25: data_disp = "1"
5'd26: data_disp = "3"
default : data_disp =" "
endcase
end
endmodule
你只要把最后一个CASE语句里面welcome to anlogic 改掉就行了。(anlogic FPGA)
你好仔缺斗!首先先确定DS90CR工作正常。然后再验扮塌证FPGA的程序。你提供的信息太少了,可以的话念磨,在FPGA里用chipscope抓下输出波形贴上来看下。当然,最好的是直接用示波器看了。
如果对你有帮助,望采纳。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)