Nokia5110液晶屏是諾基亞5110手機的拆機屏,該手機于1998年上市,現在早已停產,液晶屏就被拆機賣了。裸屏價格5元左右,加PCB板和背光的價格在15元左右。5110的優點是:性價比高,給英文屏的價格買中文屏!性能優于 優于1602,12864液晶。1602價格10左右,不能顯示中文,而且只有兩排顯示!12864價格昂貴了,價格一般在60元以上。1602,12864液晶是單片機開發的常規正統的LCD顯示器。但是,5110液晶屏完全可以取代它們了。
5110全屏能顯示6行字母或數字,一行能顯示14個字母或數字。全屏可顯示3行漢字,一行能容納7個漢字!從這個參數看來,性價比上就優于1602,12864液晶。5110液晶屏現在在市面上的庫存應該有數十萬片以上,一般只有單片機開發的人才用得上這種屏。所以,在短時間看來,還是不用擔心庫存問題!
//液晶屏驅動測試代碼
#include <reg51.h>
/*
程序默認IO連接方式:
sce-P0^0; res-P0^1; dc-P0^2; sdin-P1^5; sclk-P1^7;
*/
sbit sce = P0^0; //片選
sbit res = P0^1; //復位,0復位
sbit dc = P0^2; //1寫數據,0寫指令
sbit sdin = P1^5; //數據
sbit sclk = P1^7; //時鐘
//6*16字符
unsigned char code shuzi[]={
/*-- 文字: G --*/
/*-- 宋體9; 此字體下對應的點陣為:寬x高=6x12 --*/
/*-- 高度不是8的倍數,現調整為:寬度x高度=6x16 --*/
0xF0,0x08,0x04,0x44,0xCC,0x40,0x00,0x01,0x02,0x02,0x01,0x00
};
unsigned char code hanzi[]=
{
/*-- 文字: 單 --*/
/*-- 宋體9; 此字體下對應的點陣為:寬x高=12x12 --*/
/*-- 高度不是8的倍數,現調整為:寬度x高度=12x16 --*/
0x00,0x00,0x7C,0x55,0x56,0xFC,0x56,0x55,0x54,0x7C,0x00,0x00,0x01,0x01,0x01,0x01,
0x01,0x07,0x01,0x01,0x01,0x01,0x01,0x00,
};
void delayms(unsigned int ii) //1ms延時函數
{
unsigned int i,x;
for (x=0;x<ii;x++)
{
for (i=0;i<100;i++);
}
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口寫數據到LCD
輸入參數:dt:寫入的數據;
command :寫數據/命令選擇;
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i;
sce=0;
dc=command;
for(i=0;i<8;i++)
{
if(dt&0x80)
sdin=1;
else
sdin=0;
dt=dt<<1;
sclk=0;
sclk=1;
}
dc=1;
sce=1;
sdin=1;
}
/*---------------------------------------
LCD_init: 3310LCD初始化
----------------------------------------- */
void LCD_init(void)
{
res=0;
delayms(10);
res=1;
LCD_write_byte(0x21,0); //初始化Lcd,功能設定使用擴充指令
LCD_write_byte(0xC6,0); //設定液晶偏置電壓
LCD_write_byte(0x06,0); //溫度校正
LCD_write_byte(0x13,0); //1:48
LCD_write_byte(0x20,0); //使用基本指令
LCD_write_byte(0x0C,0); //設定顯示模式,正常顯示
}
/*-------------------------------------------
LCD_set_XY: 設置LCD坐標函數
輸入參數:X:0-83 Y:0-5
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
/*------------------------------------------
LCD_clear: LCD清屏函數
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
/*---------------------------------------------
LCD_write_shu: 顯示6(寬)*16(高)點陣列數字字母符號等半角類
輸入參數:c:顯示的字符;
-----------------------------------------------*/
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:頁 dd:字符
{
unsigned char i;
LCD_set_XY(row*6, page); // 列,頁
for(i=0; i<6;i++)
{
LCD_write_byte(shuzi[c*12+i],1);
}
LCD_set_XY(row*6, page+1); // 列,頁
for(i=6; i<12;i++)
{
LCD_write_byte(shuzi[c*12+i],1);
}
}
/*---------------------------------------------
LCD_write_hanzi: 顯示12(寬)*16(高)點陣列漢字等半角類
輸入參數:c:顯示的字符;
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:頁 dd:字符
{
unsigned char i;
LCD_set_XY(row*6, page); // 列,行
for(i=0; i<12;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
LCD_set_XY(row*6, page+1); // 列,行
for(i=12; i<24;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
}
main()
{
unsigned char k;
sce=0;
res=0;
for(k=0;k<250;k++);
res=1;
LCD_init(); //初始化LCD模塊
LCD_clear(); //清屏幕
LCD_write_hanzi(0,0,0); //單
LCD_write_shu(10,4,0); //G
while(1)
{
delayms(5000);
}
}
|