諾基亞3310液晶顯示模塊資料及的應(yīng)用_第1頁
諾基亞3310液晶顯示模塊資料及的應(yīng)用_第2頁
諾基亞3310液晶顯示模塊資料及的應(yīng)用_第3頁
諾基亞3310液晶顯示模塊資料及的應(yīng)用_第4頁
諾基亞3310液晶顯示模塊資料及的應(yīng)用_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、諾基亞3310液晶顯示模塊資料及的應(yīng)用Nokia 3310手機(jī)的點(diǎn)陣LCD模塊不僅小巧、省電、驅(qū)動容易,而且價錢也便宜。因此,最近網(wǎng)上常見到不少朋友都在用單片機(jī)來驅(qū)動該模塊,制做出很多作品。實(shí)驗(yàn)?zāi)繕?biāo)在LCD上顯示和移動漢字;在LCD上顯示英文字符串;在LCD上顯示位圖。實(shí)驗(yàn)電路圖及工作原理由于3310LCD的工作電壓范圍是2.73.3V,因此實(shí)驗(yàn)中使用一個3.3V的穩(wěn)壓二極管D1將5V電源穩(wěn)壓為3.3V左右,為MCU和LCD供電。MCU和LCD之間使用SPI接口傳輸數(shù)據(jù)。LCD模塊的引腳排列:從模塊的背面看,管腳排列順序從左至右分別為1至8腳。如下圖所示:·注意: · LC

2、D模塊的引腳即使用導(dǎo)線直接焊接上,也要用東西將金屬引腳壓下去,否則還是不能接觸到內(nèi)部電路實(shí)驗(yàn)源程序主程序:文件名是3310LCDTest.c #include <iom48v.h>#include <macros.h>#include "lcd.h"#include "bmp.h"/*/void main(void) OSCCAL=0x99;/ 8M系統(tǒng)內(nèi)部時鐘校準(zhǔn)/設(shè)置MCU的I/O口DDRB |= LCD_RST | LCD_DC | LCD_CE | SPI_MOSI | SPI_CLK| 0X02;SPSR |= BIT(

3、SPI2X);/ 設(shè)置SPI時鐘倍速SPCR |= BIT(SPE)|BIT(MSTR);/ 使能SPI接口,主機(jī)模式,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); /顯示”實(shí)驗(yàn)室“位圖 PORTB |= 0x02; /LED亮while(1)LCD_move_chi(0, 0, 25); /漢字移動顯示 LCD3310驅(qū)動程序:文件名33

4、10LCD.c#include <iom48v.h>#include <macros.h>#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;/ 產(chǎn)生一個讓LCD復(fù)位的低電平脈沖delay_1us();PORTB |= LCD_RST;PORTB &= LCD

5、_CE ;/ 關(guān)閉LCDdelay_1us();PORTB |= LCD_CE;/ 使能LCDdelay_1us();LCD_write_byte(0x21, 0);/ 使用擴(kuò)展命令設(shè)置LCD模式LCD_write_byte(0xc8, 0);/ 設(shè)置偏置電壓LCD_write_byte(0x06, 0);/ 溫度校正LCD_write_byte(0x13, 0);/ 1:48LCD_write_byte(0x20, 0);/ 使用基本命令LCD_clear();/ 清屏LCD_write_byte(0x0c, 0);/ 設(shè)定顯示模式,正常顯示PORTB &= LCD_CE ;/ 關(guān)閉

6、LCD/*-LCD_clear: LCD清屏函數(shù)編寫日期: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; i<504; i+)LCD_write_byte(0, 1);/*-LCD_set_XY: 設(shè)置LCD坐標(biāo)函數(shù)輸入?yún)?shù):X:083Y:05編寫日期:2004-8-10 最后修改日期:2004-8-10 -*/void LCD_set_XY(unsigned char X, unsigned

7、 char Y)LCD_write_byte(0x40 | Y, 0);/ columnLCD_write_byte(0x80 | X, 0);/ row/*-LCD_write_char: 顯示英文字符輸入?yún)?shù):c:顯示的字符;編寫日期:2004-8-10 最后修改日期:2004-8-10 -*/void LCD_write_char(unsigned char c)unsigned char line;c -= 32;for (line=0; line<6; line+)LCD_write_byte(font6x8cline, 1);/*-LCD_write_char: 英文字符串顯

8、示函數(shù)輸入?yún)?shù):*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上顯示漢字輸入?yún)?shù):X、Y:顯示漢字的起始X、Y坐標(biāo);ch_with :漢字點(diǎn)陣的寬度num:顯示漢字的個數(shù);line:漢字點(diǎn)陣數(shù)組中的起始行數(shù)row:漢字顯示的行間距編寫日期:2004-8-11 最后修改日期:2004-8-12 -*/void LCD_writ

9、e_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);/設(shè)置初始位置for (i=0;i<num;)for (n=0; n<ch_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

10、);LCD_write_byte(china_charline+in,1);i+;LCD_set_XY(X+(ch_with+row)*i),Y);/*-LCD_write_chi: 漢字移動輸入?yún)?shù):X、Y:顯示漢字的起始X、Y坐標(biāo);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_l8

11、4=0;for (i=0; i<156; i+)buffer_h83 = china_chari/12j;buffer_l83 = china_chari/12j+12;j+;if (j=12) j=0;for (n=0; n<83; n+) buffer_hn=buffer_hn+1;buffer_ln=buffer_ln+1; LCD_set_XY(X,Y);for (n=0; n<83; n+) LCD_write_byte(buffer_hn,1); LCD_set_XY(X,Y+1); for (n=0; n<83; n+) LCD_write_byte(bu

12、ffer_ln,1); delay_nms(T);/*-LCD_draw_map: 位圖繪制函數(shù)輸入?yún)?shù):X、Y:位圖繪制的起始X、Y坐標(biāo);*map:位圖點(diǎn)陣數(shù)據(jù);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)

13、 row=Pix_y/8;/計算位圖所占行數(shù)elserow=Pix_y/8+1;for (n=0;n<row;n+)LCD_set_XY(X,Y);for(i=0; i<Pix_x; i+)LCD_write_byte(mapi+n*Pix_x, 1);Y+;/換行/*-LCD_write_byte: 使用SPI接口寫數(shù)據(jù)到LCD輸入?yún)?shù):data:寫入的數(shù)據(jù);command :寫數(shù)據(jù)/命令選擇;編寫日期:2004-8-10 最后修改日期:2004-8-13 -*/void LCD_write_byte(unsigned char data, unsigned char comma

14、nd)PORTB &= LCD_CE ;/ 使能LCDif (command = 0)PORTB &= LCD_DC ;/ 傳送命令elsePORTB |= LCD_DC ;/ 傳送數(shù)據(jù)SPDR = data;/ 傳送數(shù)據(jù)到SPI寄存器while (SPSR & 0x80) = 0);/ 等待數(shù)據(jù)傳送完畢PORTB |= LCD_CE ;/ 關(guān)閉LCDo 延時程序:文件名delay.c /*-延時函數(shù)系統(tǒng)時鐘:8M-*/void delay_1us(void)/1us延時函數(shù)asm("nop");void delay_nus(unsigned int

15、 n)/N us延時函數(shù)unsigned int i=0;for (i=0;i<n;i+)delay_1us();void delay_1ms(void)/1ms延時函數(shù)unsigned int i;for (i=0;i<1140;i+);void delay_nms(unsigned int n)/N ms延時函數(shù)unsigned int i=0;for (i=0;i<n;i+)delay_1ms();o lcd.h頭文件 /Mega48/8port B pinout for LCD.#define LCD_DC0x01/PB0#define LCD_CE0x04/PB2#

16、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 ro

17、w);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);vo

18、id delay_nus(unsigned int n);void delay_1ms(void);void delay_nms(unsigned int n);o 點(diǎn)陣數(shù)據(jù)文件 chinese.h文件:/*-;源文件 / 文字 : 歡迎光臨電子愛好者俱樂部!;寬×高(像素): 12×13;字模格式/大小 : 單色點(diǎn)陣液晶字模,縱向取模,字節(jié)倒序/24字節(jié);數(shù)據(jù)轉(zhuǎn)換日期: 2004-8-12 14:22:30-*/const unsigned char china_char24=0x14,0x24,0xC4,0x3C,0x04,0x30,0x0E,0xE8,0x08,0x2

19、8,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,0

20、x08,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,0x4

21、2,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,0

22、x05,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

23、,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,0

24、x00,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,

25、 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,

26、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

27、, 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,

28、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, 0x14, 0x14, 0x14, 0x14, 0x14 ,/ = 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 ,/ > 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 ,/

29、? 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, 0x

30、49, 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

31、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, 0x

32、40, 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 ,/ 0x0

33、0, 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, 0x5

34、4, 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 0

35、x00, 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, 0x4

36、4, 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論