Randy 发表于 2012-3-31 10:40:20

arduino学习笔记32 - Arduino nokia 5110 PCD8544驱动实验

arduino配套的显示器淘宝上大多是 1602 和12864 屏其中1602价格便宜,但液晶屏幕很小,而且不能显示英文,12864可以显示中文甚至有自带字库的,但价格相对比较贵
这时,我们还有另外一个选择,nokia 5110 液晶

这款屏幕分辨率为84x48,最多可以显示4行汉字,而且价格便宜,10几元钱就可以买到了

淘宝上卖的一般是带背光的,控制芯片位pcd8554,每家店里出售的可能多少有点小不同
这是显示效果。
Nokia/诺基亚5110 LCD原理应用资料:LPH7366 是NOKIA 公司生产的可用于其5110、6150,6100 等系列移动电话的液晶显示模块,国内厂家也生产有类似的兼容产品。该产品除应用于移动电话外,也可广泛应用于各类便携式设备的显示系统。与其它类型的产品相比,该模块具有以下特点:
●84x48 的点阵LCD,可以显示4 行汉字,
●采用串行接口与主处理器进行通信,接口信号线数量大幅度减少,包括电源和地在内的信号线仅有9 条。支持多种串行通信协议(如AVR 单片机的SPI、MCS51 的串口模式0等),传输速率高达4Mbps,可全速写入显示数据,无等待时间。
●可通过导电胶连接模块与印制版,而不用连接电缆,用模块上的金属钩可将模块固定到印制板上,因而非常便于安装和更换。
●LCD 控制器/驱动器芯片已绑定到LCD 晶片上,模块的体积很小。
●采用低电压供电,正常显示时的工作电流在200μA 以下,且具有掉电模式。
LPH7366 的这些特点非常适合于电池供电的便携式通信设备和测试设备中

首先申明一下,我所使用的nokia 5110屏是8个引脚的。有些是9个脚的,方法相同,自己按照方法接就好了。

先上实物图和连接图!

下面就是把驱动代码给附上了,有什么问题欢迎大家提问发言!// The pins to use on the arduino
#define PIN_SCE   7
#define PIN_RESET 6
#define PIN_DC    5
#define PIN_SDIN4
#define PIN_SCLK3

// COnfiguration for the LCD
#define LCD_C   LOW
#define LCD_D   HIGH
#define LCD_CMD   0

// Size of the LCD
#define LCD_X   84
#define LCD_Y   48

int scrollPosition = -10;

static const byte ASCII[] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c &yen;
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ←
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f →
};

void LcdCharacter(char character)
{
LcdWrite(LCD_D, 0x00);
for (int index = 0; index < 5; index++)
{
    LcdWrite(LCD_D, ASCII);
}
LcdWrite(LCD_D, 0x00);
}

void LcdClear(void)
{
for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
{
    LcdWrite(LCD_D, 0x00);
}
}

void LcdInitialise(void)
{
pinMode(PIN_SCE,   OUTPUT);
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_DC,    OUTPUT);
pinMode(PIN_SDIN,OUTPUT);
pinMode(PIN_SCLK,OUTPUT);

digitalWrite(PIN_RESET, LOW);
digitalWrite(PIN_RESET, HIGH);

LcdWrite(LCD_CMD, 0x21);// LCD Extended Commands.
LcdWrite(LCD_CMD, 0xBf);// Set LCD Vop (Contrast). //B1
LcdWrite(LCD_CMD, 0x04);// Set Temp coefficent. //0x04
LcdWrite(LCD_CMD, 0x14);// LCD bias mode 1:48. //0x13
LcdWrite(LCD_CMD, 0x0C);// LCD in normal mode. 0x0d for inverse
LcdWrite(LCD_C, 0x20);
LcdWrite(LCD_C, 0x0C);
}

void LcdString(char *characters)
{
while (*characters)
{
    LcdCharacter(*characters++);
}
}

void LcdWrite(byte dc, byte data)
{
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}

/**
* gotoXY routine to position cursor
* x - range: 0 to 84
* y - range: 0 to 5
*/
void gotoXY(int x, int y)
{
LcdWrite( 0, 0x80 | x);// Column.
LcdWrite( 0, 0x40 | y);// Row.
}

void drawBox(void)
{
int j;
for(j = 0; j < 84; j++) // top
{
    gotoXY(j, 0);
    LcdWrite(1, 0x01);
}

for(j = 0; j < 84; j++) //Bottom
{
    gotoXY(j, 5);
    LcdWrite(1, 0x80);
}

for(j = 0; j < 6; j++) // Right
{
    gotoXY(83, j);
    LcdWrite(1, 0xff);
}

for(j = 0; j < 6; j++) // Left
{
    gotoXY(0, j);
    LcdWrite(1, 0xff);
}
}

void Scroll(String message)
{
for (int i = scrollPosition; i < scrollPosition + 11; i++)
{
    if ((i >= message.length()) || (i < 0))
    {
      LcdCharacter(' ');
    }
    else
    {
      LcdCharacter(message.charAt(i));
    }
}
scrollPosition++;
if ((scrollPosition >= message.length()) && (scrollPosition > 0))
{
    scrollPosition = -10;
}
}

void setup(void)
{
LcdInitialise();
LcdClear();
drawBox();

gotoXY(7,1);
LcdString("Nokia 5110");
gotoXY(4,2);
LcdString("Scroll Demo");
}

void loop(void)
{
gotoXY(4,4);
Scroll("for maore products please visit www.geeetech.com");
delay(200);
}


再提供一下字摸提取软件:



Randy 发表于 2012-3-31 10:42:05

欢迎大家提问,这个屏的资料在网上已经很多了,但是用arduino来驱动的还是蛮少的。接下来研究一下arduino驱动TFT3.2寸屏,有兴趣的大家一起研究啊!我还是小白!

悠然小调 发表于 2012-3-31 12:30:44

显示整数或小数怎么办呢?

悠然小调 发表于 2012-3-31 12:32:50

用arduino驱动感觉很占FLASH,用arduino328驱动好像不能超过10个汉字数组,超过了就没显示了。有什么办法解决呢?

悠然小调 发表于 2012-3-31 12:36:04

我试过还有两个5110的库都可用。

Malc 发表于 2012-3-31 12:43:32

悠然小调 发表于 2012-3-31 12:32 static/image/common/back.gif
用arduino驱动感觉很占FLASH,用arduino328驱动好像不能超过10个汉字数组,超过了就没显示了。有什么办法解 ...

用关键字const,把编码定义成常量,存储在flash中,32k的flash可以存很多字了吧
或者加个外部存储器,I2C读写,几十k~几百K的都有

wing 发表于 2012-3-31 21:51:43

+U,
我等着你的"arduino驱动TFT3.2寸屏"

Randy 发表于 2012-4-1 08:40:14

wing 发表于 2012-3-31 21:51 static/image/common/back.gif
+U,
我等着你的"arduino驱动TFT3.2寸屏"

我的屏还没回来,你现在也在玩吗?

wing 发表于 2012-4-1 22:54:43

搞過幾個低分辨率的TFT,不過按照"arduino驱动TFT3.2寸屏"的思路來說我不算玩過.
現在的TFT工藝非常精緻,3.2的分辨率和色彩可以很變態,
一般來說最少也有320*240,如果您能用328之類的輕量級的解決方案實現有效控制的話會是一個很酷的設計
如果您願意分享的話,我想有很多人都很感興趣

Randy 发表于 2012-4-5 08:41:40

wing 发表于 2012-4-1 22:54 static/image/common/back.gif
搞過幾個低分辨率的TFT,不過按照"arduino驱动TFT3.2寸屏"的思路來說我不算玩過.
現在的TFT工藝非常精緻,3. ...

我也是正在研究,目前对arduino驱动的库还是不会写,研究研究,出来就共享给您们!

Randy 发表于 2012-4-18 13:52:08

来一个给力点的程序,是带测距模块的程序!//端口定义

int LCD_CE=2;
int LCD_RST=3;
int SCLK=4;
int SDIN=5;
int LCD_DC=6;
int inputPin=8;// 定义超声波信号接收接口
int outputPin=9; // 定义超声波信号发出接口
/****************************************************************/
void setup()
{
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
}
//****************************定义ASCII字符**********************//

/**********************************
6 x 8 font
1 pixel space at left and bottom
index = ASCII - 32
***********************************/
const unsigned char font6x8[] =
{
    { 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, 0x14, 0x14, 0x14, 0x14, 0x14 },   // =
    { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 },   // >
    { 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
};
/************************LCD初始化函数********************************/
void LCD_init(void)
{
    //先设置为输出
   pinMode(SCLK,OUTPUT);
   pinMode(SDIN,OUTPUT);
   pinMode(LCD_DC,OUTPUT);
   pinMode(LCD_CE,OUTPUT);
   pinMode(LCD_RST,OUTPUT);
   
    // 产生一个让LCD复位的低电平脉冲
   digitalWrite( LCD_RST, LOW);
   
   delayMicroseconds(1);
   digitalWrite( LCD_RST, HIGH);
   
    // 关闭LCD
   digitalWrite( LCD_CE, LOW);
   delayMicroseconds(1);

    // 使能LCD
   digitalWrite( LCD_CE, HIGH); //LCD_CE = 1;
   delayMicroseconds(1);
    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); // 设定显示模式,正常显示
         
    // 关闭LCD
   digitalWrite( LCD_CE, LOW);//LCD_CE = 0;
}
/************************LCD清屏函数*******************************/
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);
      }   
}
/*************************设置字符位置函数**************************/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
    LCD_write_byte(0x40 | Y, 0);// column
    LCD_write_byte(0x80 | X, 0);// row
}
/*************************ASCII字符显示函数*************************/
void LCD_write_char(unsigned char c)
{
    unsigned char line;
    c -= 32;
    for (line=0; line<6; line++)
    {
      LCD_write_byte(font6x8, 1);
    }
}
/*******************************************************************/
/*-------------------------------------------------
LCD_write_english_String: 英文字符串显示函数
输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置,x 0-83 ,y 0-5
--------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
    LCD_set_XY(X,Y);
    while (*s)
    {
   LCD_write_char(*s);
   s++;
    }
}
/******************************************************************/
/*---------------------------------------------
LCD_write_byte    : 写数据到LCD
输入参数:data    :写入的数据;
          command :写数据/命令选择;
---------------------------------------------*/
void LCD_write_byte(unsigned char dat, unsigned char command)
{
    unsigned char i;
   digitalWrite( LCD_CE, LOW); // 使能LCD_CE = 0
    if (command == 0)
    {
   digitalWrite( LCD_DC, LOW);// 传送命令 LCD_DC = 0;
    }
    else
    {
      digitalWrite( LCD_DC, HIGH);// 传送数据LCD_DC = 1;
    }

for(i=0;i<8;i++)
{
   if(dat&0x80)
   {
      digitalWrite( SDIN, HIGH);//SDIN = 1;
   }
    else
    {
   digitalWrite( SDIN, LOW);//SDIN = 0;
   }
   digitalWrite( SCLK, LOW);//SCLK = 0;
   dat = dat << 1;
   digitalWrite( SCLK, HIGH);//SCLK = 1;
}
    digitalWrite( LCD_CE, HIGH);//LCD_CE = 1;
      
}

/*************************以下为主函数*****************************/

void loop()
{
LCD_init();//初始化液晶   
LCD_clear();

    LCD_write_english_string(0,0," --Arduino-- ");
    LCD_write_english_string(0,2,"Renge:");
   
    LCD_write_english_string(0,4,"DESIGN BY KENT");
    LCD_write_english_string(0,5,"    2010.6    ");
   
    while(1)
    {
      digitalWrite(outputPin, LOW); // 使发出发出超声波信号接口低电平2μs
      delayMicroseconds(2);
      digitalWrite(outputPin, HIGH); // 使发出发出超声波信号接口高电平10μs,这里是至少10μs
      delayMicroseconds(10);
      digitalWrite(outputPin, LOW);    // 保持发出超声波信号接口低电平
      int distance = pulseIn(inputPin, HIGH);// 读出脉冲时间
      distance= distance/58;         // 将脉冲时间转化为距离(单位:厘米)
         if(distance>120)
       {
      
         LCD_write_english_string(35,2,"???");
      }
         else
      {
          LCD_write_english_string(60,2,"cm");
          LCD_set_XY(35, 2);
          LCD_write_char( 0x30+distance%1000/100); //显示百位数
          LCD_write_char( 0x30+distance%100/10);   //显示十位数
          LCD_write_char( 0x30+distance%10);       //显示个位数
            
      
         }
      delay(10);
      }         
   
}

Randy 发表于 2012-4-26 15:47:11

wing 发表于 2012-4-1 22:54 static/image/common/back.gif
搞過幾個低分辨率的TFT,不過按照"arduino驱动TFT3.2寸屏"的思路來說我不算玩過.
現在的TFT工藝非常精緻,3. ...

Arduino 328也可以驱动了,我试验过了,只是不能做触摸效果!

Randy 发表于 2012-4-28 10:28:06

bg7idj 发表于 2012-4-27 16:05 static/image/common/back.gif
非常期待,上图看看


tigerdawn 发表于 2012-5-17 16:58:31

原来都是用mega16驱动的5110.现在Arduino也可以了啊,非常好

Randy 发表于 2012-5-17 17:29:26

tigerdawn 发表于 2012-5-17 16:58 static/image/common/back.gif
原来都是用mega16驱动的5110.现在Arduino也可以了啊,非常好

呵呵,表示没压力的哦,有什么和本帖相关的问题,欢迎提出来让大家看看!
页: [1] 2 3 4
查看完整版本: arduino学习笔记32 - Arduino nokia 5110 PCD8544驱动实验