你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 2554|回复: 6

ARM®mbed OS入门开发 诺基亚5110 SPI显示

[复制链接]

61

主题

1071

回帖

17

蝴蝶豆

论坛元老

最后登录
2020-12-9
发表于 2016-10-30 21:55:46 | 显示全部楼层 |阅读模式





一个基础的 LCD显示测试, 原程序基于NXP LPC1768\'s

SPI 接口显示点阵,字符,数字基于 Nokia 5110 ,Nokia 3310 LCD
其控制器为 PCD8544

10168-02a.jpg 10168-03a.jpg

//平台nucleo 070r+mbed+Nokia5110 SPI屏幕
//
/*  1. RST ——复位
  2. CE  —— 片选
  3. DC  —— 数据/指令选择
  4. DIN —— 串行数据线
  5. CLK —— 串行时钟线
  6. VCC —— 电源输入(3.3v和5v均可,经过实验验证,没有问题)
  7. BL  ——  背光控制端
  8. GND —— 地线

接口为串行SPI接口
*/
#include "mbed.h"
#include "N5110.h"
//      VCC,SCE,RST,D/C,MOSI,SCLK,LED
N5110 lcd(D8,D9,D10,D11,D12,D13,D14);
//N5110 lcd VCC,SCE,RST,D/C,MOSI,SCLK,LED:  p7,p8,p9,p10,p11,p13,p21
//原程序基于xbed LPC1768      
// Can also power (VCC) directly from VOUT (3.3 V) -
// Can give better performance due to current limitation from GPIO pin

int main()
{
    // first need to initialise display
    lcd.init();

    while(1) {

        // these are default settings so not strictly needed
        lcd.normalMode();      // normal colour mode
        lcd.setBrightness(0.5); // put LED backlight on 50%

        // can directly print strings at specified co-ordinates
        lcd.printString("Hello, World!",0,0);

        char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
        // so can display a string of a maximum 14 characters in length
        // or create formatted strings - ensure they aren't more than 14 characters long
        int temperature = 27;
        int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
        // it is important the format specifier ensures the length will fit in the buffer
        if (length <= 14)  // if string will fit on display
            lcd.printString(buffer,0,1);           // display on screen

        float pressure = 1012.3;  // same idea with floats
        length = sprintf(buffer,"P = %.2f mb",pressure);
        if (length <= 14)
            lcd.printString(buffer,0,2);

        // can also print individual characters at specified place
        lcd.printChar('X',5,3);

        // draw a line across the display at y = 40 pixels (origin top-left)
        for (int i = 0; i < WIDTH; i++) {
            lcd.setPixel(i,40);
        }
        // need to refresh display after setting pixels
        lcd.refresh();

        // can also check status of pixels using getPixel(x,y)

        wait(5.0);
        lcd.clear();            // clear display
        lcd.inverseMode();      // invert colours
        lcd.setBrightness(1.0); // put LED backlight on full

        float array[84];

        for (int i = 0; i < 84; i++) {
            array = 0.5 + 0.5*sin(i*2*3.14/84);
        }

        // can also plot graphs - 84 elements only
        // values must be in range 0.0 - 1.0
        lcd.plotArray(array);
        wait(5.0);
        lcd.clear();
        lcd.normalMode();      // normal colour mode back
        lcd.setBrightness(0.5); // put LED backlight on 50%

        // example of drawing lines
        for (int x = 0; x < WIDTH ; x+=10) {
            // x0,y0,x1,y1,type 0-white,1-black,2-dotted
            lcd.drawLine(0,0,x,HEIGHT,2);
        }
        lcd.refresh();   // need to refresh screen after drawing lines

        wait(5.0);
        lcd.clear();

        // example of how to draw circles
        lcd.drawCircle(WIDTH/2,HEIGHT/2,20,1);  // x,y,radius,black fill
        lcd.drawCircle(WIDTH/2,HEIGHT/2,10,2);  // x,y,radius,white fill
        lcd.drawCircle(WIDTH/2,HEIGHT/2,30,0);  // x,y,radius,transparent with outline
        lcd.refresh();   // need to refresh screen after drawing circles

        wait(5.0);
        lcd.clear();
        // example of how to draw rectangles
        //          origin x,y,width,height,type
        lcd.drawRect(10,10,50,30,1);  // filled black rectangle
        lcd.drawRect(15,15,20,10,2);  // filled white rectange (no outline)
        lcd.drawRect(2,2,70,40,0);    // transparent, just outline
        lcd.refresh();   // need to refresh screen after drawing rects

        wait(5.0);
        lcd.clear();
    }
}


<
回复

使用道具 举报

61

主题

1071

回帖

17

蝴蝶豆

论坛元老

最后登录
2020-12-9
 楼主| 发表于 2016-10-30 22:00:59 | 显示全部楼层
另一种5110屏幕模块采用SPI接口,模块总共有8个引脚,接法如下:
  1. RST ====>复位
  2. CE  ====>片选
  3. DC  ====>数据/指令选择
  4. DIN ====>串行数据线
  5. CLK ====>串行时钟线
  6. VCC ====>电源输入(3.3v和5v均可)
  7. BL  ====>背光控制端
  8. GND ====>地线
T2bhbnXIhXXXXXXXXX-373154785.jpg
T2Lv6kXKxXXXXXXXXX-373154785.png


回复 支持 反对

使用道具 举报

4

主题

484

回帖

0

蝴蝶豆

金牌会员

最后登录
2020-8-12
发表于 2016-10-31 08:18:09 | 显示全部楼层
谢楼主分享
回复 支持 反对

使用道具 举报

4

主题

574

回帖

3

蝴蝶豆

高级会员

最后登录
2020-12-9
发表于 2016-10-31 08:30:51 | 显示全部楼层
感谢楼主分享,非常详细啊。
回复 支持 反对

使用道具 举报

0

主题

159

回帖

0

蝴蝶豆

高级会员

最后登录
2017-3-9
发表于 2016-10-31 18:54:58 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

6

主题

2397

回帖

0

蝴蝶豆

论坛元老

最后登录
2020-12-9
发表于 2016-11-1 08:05:07 | 显示全部楼层
谢谢楼主分享
回复 支持 反对

使用道具 举报

0

主题

9

回帖

0

蝴蝶豆

初级会员

最后登录
2020-10-10
发表于 2018-11-19 16:18:15 | 显示全部楼层
谢谢分享啊。
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版