诺基亚3310液晶显示模块资料及的应用.docx
《诺基亚3310液晶显示模块资料及的应用.docx》由会员分享,可在线阅读,更多相关《诺基亚3310液晶显示模块资料及的应用.docx(21页珍藏版)》请在冰点文库上搜索。
诺基亚3310液晶显示模块资料及的应用
诺基亚3310液晶显示模块资料及的应用
Nokia3310手机的点阵LCD模块不仅小巧、省电、驱动容易,而且价钱也便宜。
因此,最近网上常见到不少朋友都在用单片机来驱动该模块,制做出很多作品。
实验目标
在LCD上显示和移动汉字;
在LCD上显示英文字符串;
在LCD上显示位图。
实验电路图及工作原理
由于3310LCD的工作电压范围是2.7-3.3V,因此实验中使用一个3.3V的稳压二极管D1将5V电源稳压为3.3V左右,为MCU和LCD供电。
MCU和LCD之间使用SPI接口传输数据。
LCD模块的引脚排列:
从模块的背面看,管脚排列顺序从左至右分别为1至8脚。
如下图所示:
∙
注意:
∙LCD模块的引脚即使用导线直接焊接上,也要用东西将金属引脚压下去,否则还是不能接触到内部电路
实验源程序
主程序:
文件名是3310LCDTest.c
#include
#include
#include"lcd.h"
#include"bmp.h"
/*******************************************/
voidmain(void)
{
OSCCAL=0x99;//8M系统内部时钟校准
//设置MCU的I/O口
DDRB|=LCD_RST|LCD_DC|LCD_CE|SPI_MOSI|SPI_CLK|0X02;
SPSR|=BIT(SPI2X);//设置SPI时钟倍速
SPCR|=BIT(SPE)|BIT(MSTR);//使能SPI接口,主机模式,4M时钟
LCD_init();//初始化LCD模块
LCD_write_String(1,5,"");//显示英文字符串”“
LCD_draw_map(0,2,AVR_bmp,40,24);//显示“AVR”位图
LCD_draw_map(44,3,china_bmp,36,15);//显示”实验室“位图
PORTB|=0x02;//LED亮
while
(1)
{
LCD_move_chi(0,0,25);//汉字移动显示
}
}
LCD3310驱动程序:
文件名3310LCD.c
#include
#include
#include"lcd.h"
#include"6x8.h"
#include"chinese.h"
/*---------------------------------------
LCD_init:
3310LCD初始化
编写日期:
2004-8-10
最后修改日期:
2004-8-10
----------------------------*/
voidLCD_init(void)
{
PORTB&=~LCD_RST;//产生一个让LCD复位的低电平脉冲
delay_1us();
PORTB|=LCD_RST;
PORTB&=~LCD_CE;//关闭LCD
delay_1us();
PORTB|=LCD_CE;//使能LCD
delay_1us();
LCD_write_byte(0x21,0);//使用扩展命令设置LCD模式
LCD_write_byte(0xc8,0);//设置偏置电压
LCD_write_byte(0x06,0);//温度校正
LCD_write_byte(0x13,0);//1:
48
LCD_write_byte(0x20,0);//使用基本命令
LCD_clear();//清屏
LCD_write_byte(0x0c,0);//设定显示模式,正常显示
PORTB&=~LCD_CE;//关闭LCD
}
/*-----------------------------------------------------------------------
LCD_clear:
LCD清屏函数
编写日期:
2004-8-10
最后修改日期:
2004-8-10
-----------------------------------------------------------------------*/
voidLCD_clear(void)
{
unsignedinti;
LCD_write_byte(0x0c,0);
LCD_write_byte(0x80,0);
for(i=0;i<504;i++)
LCD_write_byte(0,1);
}
/*-----------------------------------------------------------------------
LCD_set_XY:
设置LCD坐标函数
输入参数:
X:
0-83
Y:
0-5
编写日期:
2004-8-10
最后修改日期:
2004-8-10
-----------------------------------------------------------------------*/
voidLCD_set_XY(unsignedcharX,unsignedcharY)
{
LCD_write_byte(0x40|Y,0);//column
LCD_write_byte(0x80|X,0);//row
}
/*-----------------------------------------------------------------------
LCD_write_char:
显示英文字符
输入参数:
c:
显示的字符;
编写日期:
2004-8-10
最后修改日期:
2004-8-10
-----------------------------------------------------------------------*/
voidLCD_write_char(unsignedcharc)
{
unsignedcharline;
c-=32;
for(line=0;line<6;line++)
LCD_write_byte(font6x8[c][line],1);
}
/*-----------------------------------------------------------------------
LCD_write_char:
英文字符串显示函数
输入参数:
*s:
英文字符串指针;
X、Y:
显示字符串的位置
-----------------------------------------------------------------------*/
voidLCD_write_String(unsignedcharX,unsignedcharY,char*s)
{
LCD_set_XY(X,Y);
while(*s)
{
LCD_write_char(*s);
s++;
}
}
/*-----------------------------------------------------------------------
LCD_write_chi:
在LCD上显示汉字
输入参数:
X、Y:
显示汉字的起始X、Y坐标;
ch_with:
汉字点阵的宽度
num:
显示汉字的个数;
line:
汉字点阵数组中的起始行数
row:
汉字显示的行间距
编写日期:
2004-8-11
最后修改日期:
2004-8-12
-----------------------------------------------------------------------*/
voidLCD_write_chi(unsignedcharX,unsignedcharY,
unsignedcharch_with,unsignedcharnum,
unsignedcharline,unsignedcharrow)
{
unsignedchari,n;
LCD_set_XY(X,Y);//设置初始位置
for(i=0;i{
for(n=0;n{
if(n==ch_with)//写汉字的下半部分
{
if(i==0)LCD_set_XY(X,Y+1);
else
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
LCD_write_byte(china_char[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
/*-----------------------------------------------------------------------
LCD_write_chi:
汉字移动
输入参数:
X、Y:
显示汉字的起始X、Y坐标;
T:
移动速度;
编写日期:
2004-8-13
最后修改日期:
2004-8-13
-----------------------------------------------------------------------*/
voidLCD_move_chi(unsignedcharX,unsignedcharY,unsignedcharT)
{
unsignedchari,n,j=0;
unsignedcharbuffer_h[84]={0};
unsignedcharbuffer_l[84]={0};
for(i=0;i<156;i++)
{
buffer_h[83]=china_char[i/12][j];
buffer_l[83]=china_char[i/12][j+12];
j++;
if(j==12)j=0;
for(n=0;n<83;n++)
{
buffer_h[n]=buffer_h[n+1];
buffer_l[n]=buffer_l[n+1];
}
LCD_set_XY(X,Y);
for(n=0;n<83;n++)
{
LCD_write_byte(buffer_h[n],1);
}
LCD_set_XY(X,Y+1);
for(n=0;n<83;n++)
{
LCD_write_byte(buffer_l[n],1);
}
delay_nms(T);
}
}
/*-----------------------------------------------------------------------
LCD_draw_map:
位图绘制函数
输入参数:
X、Y:
位图绘制的起始X、Y坐标;
*map:
位图点阵数据;
Pix_x:
位图像素(长)
Pix_y:
位图像素(宽)
编写日期:
2004-8-13
最后修改日期:
2004-8-13
-----------------------------------------------------------------------*/
voidLCD_draw_map(unsignedcharX,unsignedcharY,unsignedchar*map,
unsignedcharPix_x,unsignedcharPix_y)
{
unsignedinti,n;
unsignedcharrow;
if(Pix_y%8==0)row=Pix_y/8;//计算位图所占行数
else
row=Pix_y/8+1;
for(n=0;n{
LCD_set_XY(X,Y);
for(i=0;i{
LCD_write_byte(map[i+n*Pix_x],1);
}
Y++;//换行
}
}
/*-----------------------------------------------------------------------
LCD_write_byte:
使用SPI接口写数据到LCD
输入参数:
data:
写入的数据;
command:
写数据/命令选择;
编写日期:
2004-8-10
最后修改日期:
2004-8-13
-----------------------------------------------------------------------*/
voidLCD_write_byte(unsignedchardata,unsignedcharcommand)
{
PORTB&=~LCD_CE;//使能LCD
if(command==0)
PORTB&=~LCD_DC;//传送命令
else
PORTB|=LCD_DC;//传送数据
SPDR=data;//传送数据到SPI寄存器
while((SPSR&0x80)==0);//等待数据传送完毕
PORTB|=LCD_CE;//关闭LCD
}
o延时程序:
文件名delay.c
/*-----------------------------------------------------------------------
延时函数
系统时钟:
8M
-----------------------------------------------------------------------*/
voiddelay_1us(void)//1us延时函数
{
asm("nop");
}
voiddelay_nus(unsignedintn)//Nus延时函数
{
unsignedinti=0;
for(i=0;idelay_1us();
}
voiddelay_1ms(void)//1ms延时函数
{
unsignedinti;
for(i=0;i<1140;i++);
}
voiddelay_nms(unsignedintn)//Nms延时函数
{
unsignedinti=0;
for(i=0;idelay_1ms();
}
olcd.h头文件
//Mega48/8portBpinoutforLCD.
#defineLCD_DC0x01//PB0
#defineLCD_CE0x04//PB2
#defineSPI_MOSI0x08//PB3
#defineLCD_RST0x10//PB4
#defineSPI_CLK0x20//PB5
voidLCD_init(void);
voidLCD_clear(void);
voidLCD_write_String(unsignedcharX,unsignedcharY,char*s);
voidLCD_write_chi(unsignedcharX,unsignedcharY,
unsignedcharch_with,unsignedcharnum,
unsignedcharline,unsignedcharrow);
voidLCD_move_chi(unsignedcharX,unsignedcharY,unsignedcharT);
voidLCD_write_char(unsignedcharc);
voidLCD_draw_map(unsignedcharX,unsignedcharY,unsignedchar*map,
unsignedcharPix_x,unsignedcharPix_y);
voidLCD_write_byte(unsignedchardata,unsignedchardc);
voiddelay_1us(void);
voiddelay_nus(unsignedintn);
voiddelay_1ms(void);
voiddelay_nms(unsignedintn);
o点阵数据文件
chinese.h文件:
/*------------------------------------------------------------------------------
;源文件/文字:
欢迎光临电子爱好者俱乐部!
;宽×高(像素):
12×13
;字模格式/大小:
单色点阵液晶字模,纵向取模,字节倒序/24字节
;数据转换日期:
2004-8-1214:
22:
30
------------------------------------------------------------------------------*/
constunsignedcharchina_char[][24]=
{
{
0x14,0x24,0xC4,0x3C,0x04,0x30,0x0E,0xE8,0x08,0x28,0x18,0x00,0x04,0x03,
0x00,0x09,0x0A,0x04,0x03,0x00,0x03,0x04,0x08,0x00
},//汉字“欢”
{
0x10,0xF2,0x04,0x00,0xFC,0x84,0x82,0xFC,0x04,0x04,0xFC,0x00,0x0C,0x03,
0x04,0x04,0x09,0x08,0x08,0x0B,0x08,0x09,0x09,0x00
},//汉字“迎”
{
0x20,0x24,0x28,0xF0,0x20,0x3E,0xE0,0x30,0x28,0x24,0x20,0x00,0x08,0x08,
0x04,0x03,0x00,0x00,0x07,0x08,0x08,0x08,0x0E,0x00
},//汉字“光”
{
0xF8,0x00,0xFE,0x00,0x20,0x98,0x8E,0x98,0xA8,0x88,0x88,0x00,0x03,0x00,
0x0F,0x00,0x00,0x0F,0x04,0x07,0x04,0x04,0x0F,0x00
},//汉字“临”
{
0x00,0xF8,0x28,0x28,0x28,0xFE,0x28,0x28,0x28,0xFC,0x08,0x00,0x00,0x03,
0x01,0x01,0x01,0x07,0x09,0x09,0x09,0x09,0x0C,0x00
},//汉字“电”
{
0x40,0x42,0x42,0x42,0x42,0xF2,0x52,0x4A,0x46,0x62,0x40,0x00,0x00,0x00,
0x00,0x08,0x08,0x0F,0x00,0x00,0x00,0x00,0x00,0x00
},//汉字“子”
{
0x30,0x54,0x54,0x5C,0xF4,0x5C,0x52,0x5A,0x56,0x52,0x30,0x00,0x08,0x08,
0x04,0x0A,0x0B,0x05,0x05,0x0B,0x09,0x08,0x08,0x00
},//汉字“爱”
{
0x88,0x78,0x0E,0x88,0x78,0x42,0x42,0xF2,0x4A,0x46,0x40,0x00,0x09,0x05,
0x02,0x03,0x04,0x00,0x08,0x0F,0x00,0x00,0x00,0x00
},//汉字“好”
{
0x20,0x24,0x24,0xA4,0xFE,0xA4,0xB4,0xAC,0xA4,0x32,0x20,0x00,0x02,0x02,
0x01,0x0F,0x0A,0x0A,0x0A,0x0A,0x0F,0x00,0x00,0x00
},//汉字“者”
{
0x20,0xF8,0x06,0x00,0xFE,0x52,0x52,0x52,0x52,0xFE,0x00,0x00,0x00,0x0F,
0x01,0x09,0x05,0x03,0x01,0x01,0x03,0x05,0x09,0x00
},//汉字“俱”
{
0x00,0x60,0x5C,0xC4,0x44,0x44,0xFA,0xC2,0x42,0x60,0x40,0x00,0x04,0x02,
0x01,0x00,0x08,0x08,0x0F,0x00,0x01,0x02,0x04,0x00
},//汉字“乐”
{
0x24,0xAC,0xB4,0xA6,0xB4,0xAC,0x24,0xFC,0x04,0x74,0x8C,0x00,0x00,0x0F,
0x04,0x04,0x04,0x0F,0x00,0x0F,0x02,0x04,0x03,0x00
},//汉字“部”
{
0x00,0x38,0xFC,0xFC,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
},//汉字“!
”
};
6x8.h文件:
//6x8font
//1pixelspaceatleftandbottom
//index=ASCII-32
constunsignedcharfont6x8[][6]=
{
{0x00,0x00,0x00,0x00,0x00,0x00},//sp
{0x00,0x00,0x00,0x2f,0x00,0x00},//!
{0x00,0x00,0x07,0x00,0x07,0x00},//"
{0x00,0x14,0x7f,0x14,0x7f,0x14},//#
{0x00,0x24,0x2a,0x7f,0x2a,0x12},//$
{0x00,0x62,0x64,0x08,0x13,0x23},//%
{0x00,0x36,0x49,0x55,0x22,0x50},//&
{0x00,0x00,0x05,0x03,0x00,0x00},//'
{0x00,0x00,0x1c,0x22,0x41,0x00},//(
{0x00,0x00,0x41,0x22,0x1c,0x00},//)
{0x00,0x14,0x08,0x3E,0x08,0x14},//*
{0x00,0x08,0x08,0x3E,0x08,0x08},//+
{0x00,0x00,0x00,0xA0,0x60,0x00},//,
{
|