诺基亚3310液晶显示模块资料及的应用.doc_第1页
诺基亚3310液晶显示模块资料及的应用.doc_第2页
诺基亚3310液晶显示模块资料及的应用.doc_第3页
诺基亚3310液晶显示模块资料及的应用.doc_第4页
诺基亚3310液晶显示模块资料及的应用.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

诺基亚3310液晶显示模块资料及的应用Nokia 3310手机的点阵LCD模块不仅小巧、省电、驱动容易,而且价钱也便宜。因此,最近网上常见到不少朋友都在用单片机来驱动该模块,制做出很多作品。实验目标在LCD上显示和移动汉字;在LCD上显示英文字符串;在LCD上显示位图。实验电路图及工作原理由于3310LCD的工作电压范围是2.73.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/*/void main(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 -*/void LCD_init(void)PORTB &= LCD_RST;/ 产生一个让LCD复位的低电平脉冲delay_1us();PORTB |= LCD_RST;PORTB &= LCD_CE ;/ 关闭LCDdelay_1us();PORTB |= LCD_CE;/ 使能LCDdelay_1us();LCD_write_byte(0x21, 0);/ 使用扩展命令设置LCD模式LCD_write_byte(0xc8, 0);/ 设置偏置电压LCD_write_byte(0x06, 0);/ 温度校正LCD_write_byte(0x13, 0);/ 1:48LCD_write_byte(0x20, 0);/ 使用基本命令LCD_clear();/ 清屏LCD_write_byte(0x0c, 0);/ 设定显示模式,正常显示PORTB &= LCD_CE ;/ 关闭LCD/*-LCD_clear: LCD清屏函数编写日期:2004-8-10 最后修改日期:2004-8-10 -*/void LCD_clear(void)unsigned int i;LCD_write_byte(0x0c, 0);LCD_write_byte(0x80, 0);for (i=0; i504; i+)LCD_write_byte(0, 1);/*-LCD_set_XY: 设置LCD坐标函数输入参数:X:083Y:05编写日期:2004-8-10 最后修改日期:2004-8-10 -*/void LCD_set_XY(unsigned char X, unsigned char Y)LCD_write_byte(0x40 | Y, 0);/ columnLCD_write_byte(0x80 | X, 0);/ row/*-LCD_write_char: 显示英文字符输入参数:c:显示的字符;编写日期:2004-8-10 最后修改日期:2004-8-10 -*/void LCD_write_char(unsigned char c)unsigned char line;c -= 32;for (line=0; line6; line+)LCD_write_byte(font6x8cline, 1);/*-LCD_write_char: 英文字符串显示函数输入参数:*s:英文字符串指针;X、Y: 显示字符串的位置-*/void LCD_write_String(unsigned char X,unsigned char Y,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 -*/void LCD_write_chi(unsigned char X, unsigned char Y, unsigned char ch_with,unsigned char num,unsigned char line,unsigned char row)unsigned char i,n;LCD_set_XY(X,Y);/设置初始位置for (i=0;inum;)for (n=0; nch_with*2; n+)/写一个汉字 if (n=ch_with)/写汉字的下半部分if (i=0) LCD_set_XY(X,Y+1);elseLCD_set_XY(X+(ch_with+row)*i),Y+1);LCD_write_byte(china_charline+in,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 -*/void LCD_move_chi(unsigned char X, unsigned char Y, unsigned char T)unsigned char i,n,j=0;unsigned char buffer_h84=0;unsigned char buffer_l84=0;for (i=0; i156; i+)buffer_h83 = china_chari/12j;buffer_l83 = china_chari/12j+12;j+;if (j=12) j=0;for (n=0; n83; n+) buffer_hn=buffer_hn+1;buffer_ln=buffer_ln+1; LCD_set_XY(X,Y);for (n=0; n83; n+) LCD_write_byte(buffer_hn,1); LCD_set_XY(X,Y+1); for (n=0; n83; n+) LCD_write_byte(buffer_ln,1); delay_nms(T);/*-LCD_draw_map: 位图绘制函数输入参数:X、Y:位图绘制的起始X、Y坐标;*map:位图点阵数据;Pix_x:位图像素(长)Pix_y:位图像素(宽)编写日期:2004-8-13最后修改日期:2004-8-13 -*/void LCD_draw_map(unsigned char X,unsigned char Y,unsigned char *map,unsigned char Pix_x,unsigned char Pix_y)unsigned int i,n;unsigned char row;if (Pix_y%8=0) row=Pix_y/8;/计算位图所占行数elserow=Pix_y/8+1;for (n=0;nrow;n+)LCD_set_XY(X,Y);for(i=0; iPix_x; i+)LCD_write_byte(mapi+n*Pix_x, 1);Y+;/换行/*-LCD_write_byte: 使用SPI接口写数据到LCD输入参数:data:写入的数据;command :写数据/命令选择;编写日期:2004-8-10 最后修改日期:2004-8-13 -*/void LCD_write_byte(unsigned char data, unsigned char command)PORTB &= LCD_CE ;/ 使能LCDif (command = 0)PORTB &= LCD_DC ;/ 传送命令elsePORTB |= LCD_DC ;/ 传送数据SPDR = data;/ 传送数据到SPI寄存器while (SPSR & 0x80) = 0);/ 等待数据传送完毕PORTB |= LCD_CE ;/ 关闭LCDo 延时程序:文件名delay.c /*-延时函数系统时钟:8M-*/void delay_1us(void)/1us延时函数asm(nop);void delay_nus(unsigned int n)/N us延时函数unsigned int i=0;for (i=0;in;i+)delay_1us();void delay_1ms(void)/1ms延时函数unsigned int i;for (i=0;i1140;i+);void delay_nms(unsigned int n)/N ms延时函数unsigned int i=0;for (i=0;in;i+)delay_1ms();o lcd.h头文件 /Mega48/8port B pinout for LCD.#define LCD_DC0x01/PB0#define LCD_CE0x04/PB2#define SPI_MOSI0x08/PB3#define LCD_RST0x10/PB4#define SPI_CLK0x20/PB5void LCD_init(void);void LCD_clear(void);void LCD_write_String(unsigned char X,unsigned char Y,char *s);void LCD_write_chi(unsigned char X, unsigned char Y,unsigned char ch_with,unsigned char num,unsigned char line,unsigned char row);void LCD_move_chi(unsigned char X, unsigned char Y, unsigned char T);void LCD_write_char(unsigned char c);void LCD_draw_map(unsigned char X,unsigned char Y,unsigned char *map,unsigned char Pix_x,unsigned char Pix_y);void LCD_write_byte(unsigned char data, unsigned char dc);void delay_1us(void);void delay_nus(unsigned int n);void delay_1ms(void);void delay_nms(unsigned int n);o 点阵数据文件 chinese.h文件:/*-;源文件 / 文字 : 欢迎光临电子爱好者俱乐部!;宽高(像素): 1213;字模格式/大小 : 单色点阵液晶字模,纵向取模,字节倒序/24字节;数据转换日期: 2004-8-12 14:22:30-*/const unsigned char china_char24=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文件:/ 6 x 8 font/ 1 pixel space at left and bottom/ index = ASCII - 32const unsigned char font6x86 = 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 ,/ , 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 ,/ - 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 ,/ . 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 ,/ / 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E ,/ 0 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 ,/ 1 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 ,/ 2 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 ,/ 3 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 ,/ 4 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 ,/ 5 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 ,/ 6 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 ,/ 7 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 ,/ 8 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E ,/ 9 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 ,/ : 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 ,/ ; 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 ,/ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 ,/ ? 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E ,/ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C ,/ A 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 ,/ B 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 ,/ C 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C ,/ D 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 ,/ E 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 ,/ F 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A ,/ G 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F ,/ H 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 ,/ I 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 ,/ J 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 ,/ K 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 ,/ L 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F ,/ M 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F ,/ N 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E ,/ O 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 ,/ P 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E ,/ Q 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 ,/ R 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 ,/ S 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 ,/ T 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F ,/ U 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F ,/ V 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F ,/ W 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 ,/ X 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 ,/ Y 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 ,/ Z 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 ,/ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 ,/ 55 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 ,/ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 ,/ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 ,/ _ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 ,/ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 ,/ a 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 ,/ b 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 ,/ c 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F ,/ d 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 ,/ e 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 ,/ f 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C ,/ g 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 ,/ h 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 ,/ i 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 ,/ j 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 ,/ k 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 ,/ l 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 ,/ m 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 ,/ n 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 ,/ o 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 ,/ p 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC ,/ q 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 ,/ r 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 ,/ s 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 ,/ t 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C ,/ u 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C ,/ v 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C ,/ w 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 ,/ x 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C ,/ y 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 ,/ z 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 / horiz lines;bmp.h文件/*-;源文件 / 文字 :

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论