void point(uchar x,uchar y)
{
uchar y1,hang,lie,msb_data,lsb_data,temp=0x01
if(y1!=y)
{
msb_data=0
lsb_data=0
}
y1=y
if(y<32)
{
hang=0x80+y
lie=0x80
}
if(y>31)
{
hang=0x80+y-32
lie=0x88
}
if(y>63)//return
{
lcm_com(0x80)
_nop_()
hanzi("温度超出显示范围")
while(1)
flash()
}
lie=lie+x/16
if(x%16==0)
{
msb_data=0
lsb_data=0
}
if(x%16<8)
{
msb_data=msb_data|(temp<<(7-x%16))
lsb_data=0x00|lsb_data
}//保留以前的数据,把第x个点亮
if(x%16==8)
{
msb_data=msb_data|0x00
lsb_data=lsb_data|0x80
}
if(x%16>8)大于24小于32
{
msb_data=msb_data|0x00
lsb_data=lsb_data|(temp<<(15-x%16))
}
lcm_com(0x34)//扩充指令集
lcm_com(hang)
lcm_com(lie)
lcm_dat(msb_data)
lcm_dat(lsb_data)
lcm_com(0x36)//绘图显示开
}
//与硬件有关的定义:数据口用的是P3口,控制口用的是P2口,//如果不同,可以更改以下定义。
#include "msp430x44x.h"
#define LCD_CON_DIRP2DIR
#define LCD_CON_OUTP2OUT
#define LCD_DI BIT0
#define LCD_RW BIT1
#define LCD_EN BIT2
#define LCD_CS1BIT3
#define LCD_CS2BIT6
#define LCD_RSTBIT7
#define LCD_DATA_DIR P3DIR
#define LCD_DATA_INP3IN
#define LCD_DATA_OUT P3OUT
#define LCD_DATA_BIT0 BIT0
#define LCD_DATA_BIT1 BIT1
#define LCD_DATA_BIT2 BIT2
#define LCD_DATA_BIT3 BIT3
#define LCD_DATA_BIT4 BIT4
#define LCD_DATA_BIT5 BIT5
#define LCD_DATA_BIT6 BIT6
#define LCD_DATA_BIT7 BIT7
//*****************************************************************
//以下为LCD的命令字
#define DISPLAY_ON0x3F //显示屏开命令字
#define DISPLAY_OFF 0x3E //显示屏关命令字
#define SET_SHOW 0xC0 //设定显示起始行命令字
#define SET_X 0xB8 //设定显示行命令字
#define SET_Y 0x40 //设定显示列命令字
--------------------------------------------------------------------------------------------------------
#include "LCD_DEFINE.H"
void lcd_init(void)
{
LCD_DATA_OUT = 0x00
LCD_DATA_DIR = 0xFF
LCD_CON_OUT = LCD_CS1+LCD_CS2+LCD_RST
LCD_CON_DIR |= LCD_DI+LCD_RW+LCD_EN+LCD_CS1+LCD_CS2+LCD_RST
LCD_CON_OUT &= ~LCD_RST
_NOP()
_NOP()
LCD_CON_OUT |= LCD_EN
_NOP()
_NOP()
LCD_CON_OUT &= ~LCD_EN
_NOP()
_NOP()
LCD_CON_OUT |= LCD_RST
_NOP()
_NOP()
}
void write_command(unsigned char command)
{
LCD_DATA_DIR = 0xFF
LCD_CON_OUT |= LCD_CS1 + LCD_CS2
LCD_CON_OUT &= ~(LCD_RW + LCD_DI)
LCD_DATA_OUT = command
LCD_CON_OUT |= LCD_EN
LCD_CON_OUT &= ~LCD_EN
}
void write_data( unsigned char data, unsigned char CS1, unsigned char CS2 )
{
LCD_DATA_DIR = 0xFF
if(CS1) LCD_CON_OUT |= LCD_CS1
else LCD_CON_OUT &=~LCD_CS1
if(CS2) LCD_CON_OUT |= LCD_CS2
else LCD_CON_OUT &=~LCD_CS2
LCD_CON_OUT |= LCD_DI
LCD_CON_OUT &=~LCD_RW
LCD_DATA_OUT = data
LCD_CON_OUT |= LCD_EN
LCD_CON_OUT &=~LCD_EN
}
void clear_lcd(void)
{
unsigned char i,j
for(i=0i<8i++)
{
write_command(SET_X|i)
write_command(SET_Y)
for(j=0j<128j++)
{
if(j<=63)write_data(0,1,0)
else write_data(0,0,1)
_NOP()
}
}
}
void display( unsigned char *chr, unsigned char nRow, unsigned char nCol,
unsigned char highth,unsigned char wideth )
//*chr 显示数据的地址,nRow 在显示屏上第几行,nCol 在显示屏上第几列
//highth 字体的高度,wideth 字体的宽度
//128*64有8行,128列
{
unsigned char i,tmpCol,tmpRow,h,m
unsigned int j
tmpRow = nRow
m=0
for(h=0h<highthh=h+8)
{
write_command(SET_X|tmpRow)
tmpCol=nCol
for(i=0i<widethi++)
{
if(tmpCol<64)
{write_command(SET_Y|tmpCol)write_data(chr[i+j],1,0)}
else
{write_command(SET_Y|(tmpCol-64))write_data(chr[i+j],0,1)}
tmpCol++
}
m++
j=m*wideth
tmpRow++
}
}
/*LCD12864显示程序此程序控制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教你。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)