LCD5110

原创 2015年07月08日 22:44:49
#ifndef _LCD_H
#define _LCD_H

#include <reg51.h>

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;

#define WIDTH   84
#define HEIGHT  48

sbit LCD_RST =  P1^0;   //RST
sbit LCD_CE =   P1^1;   //CE
sbit LCD_DC =   P1^2;   //DC
sbit LCD_SDA =  P1^3;   //D1
sbit LCD_SCL =  P1^4;   //D0
sbit LCD_VCC =  P1^5;
sbit LCD_BL =   P1^6;
sbit LCD_GND =  P1^7;

/* OLED IO输出宏替换 */
#define LCD_SCLK_OL     LCD_SCL = 0;
#define LCD_SCLK_OH     LCD_SCL = 1;

#define LCD_SDIN_OL     LCD_SDA = 0;
#define LCD_SDIN_OH     LCD_SDA = 1;

#define LCD_RST_OL      LCD_RST = 0;
#define LCD_RST_OH      LCD_RST = 1;

#define LCD_DC_OL       LCD_DC = 0;
#define LCD_DC_OH       LCD_DC = 1;

#define LCD_CE_OL       LCD_CE = 0;
#define LCD_CE_OH       LCD_CE = 1;

#define LCD_BL_OH       LCD_BL = 0;

void LCD5110_Init(void);
void LCD5110_Clear(void);
void LCD5110_Write_Char(uint8_t x, uint8_t y, uint8_t c);
void LCD5110_Write_Num5(uint8_t x, uint8_t y, uint16_t num);
void LCD5110_Write_String(uint8_t x, uint8_t y, uint8_t *s);

#endif
#include "lcd.h"
#include "ziku.h"
#include <intrins.h>

void Delay10us()
{
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
    _nop_();
}

/*
 *  延时函数
 */
void delay_ms(uint16_t ms)
{                         
    uint16_t a;

    while (ms--)
    {
        a = 100;
        while (a--)
        {
            Delay10us();
        }
    }
}

//作用:写一个字节(数据或命令)
//两个参数:dt为要写入的字节,command为数据/命令选择
void LCD5110_WrDat(uint8_t dat)
{
    uint8_t i = 8;
    LCD_CE_OL;      //片选信号拉低,选中芯片,进行下一步操作
    LCD_DC_OH;      //写数据
    _nop_();
    LCD_SCLK_OL;
    _nop_(); 
    while (i --)//每个时钟周期写入一位
    {
        if (dat & 0x80)
        {
            LCD_SDIN_OH;
        }
        else
        {
            LCD_SDIN_OL;
        }
        LCD_SCLK_OH; 
        _nop_();_nop_();
        LCD_SCLK_OL;    
        dat <<= 1;    
    }
    LCD_CE_OH;
}
void LCD5110_WrCmd(uint8_t cmd)
{
    uint8_t i = 8;
    LCD_CE_OL;
    LCD_DC_OL;//写命令
    _nop_();
    LCD_SCLK_OL;
    _nop_(); 
    while (i --)
    {
        if (cmd & 0x80)
        {
            LCD_SDIN_OH;
        }
        else
        {
            LCD_SDIN_OL;
        }
        LCD_SCLK_OH; 
        _nop_();_nop_();
        LCD_SCLK_OL;    
        cmd <<= 1;    
    }
    LCD_CE_OH;  
}
//设置坐标,两个参数:X,Y坐标
void LCD5110_Set_XY(uint8_t X, uint8_t Y)
{
     Y |= 0x40;
     X |= 0x80;
     LCD5110_WrCmd(Y);
     LCD5110_WrCmd(X);

}

//整屏清屏(可以从中扩展出指定行列的清除)
void LCD5110_Clear(void)
{
     uint8_t t,k;
     LCD5110_Set_XY(0,0);
     for(t = 0; t < (HEIGHT >> 3); t++)
     {
        for(k = 0;k < WIDTH; k++)
        {           
            LCD5110_WrDat(0x00);
        }
     }
}

//LCD初始化
void LCD5110_Init(void)
{
     LCD_VCC = 1;
     LCD_GND = 0;
     LCD_BL_OH;
     LCD_CE_OH;
     LCD_RST_OL;
     delay_ms(10);
     LCD_RST_OH;
     delay_ms(50);
     LCD5110_WrCmd(0x21);
     LCD5110_WrCmd(0x13);
     LCD5110_WrCmd(0xc8);//参考电压
     LCD5110_WrCmd(0x20);
     LCD5110_WrCmd(0x0c);
     LCD5110_Clear();
     LCD_CE_OL;
}

void LCD5110_Write_Char(uint8_t x, uint8_t y, uint8_t c) 
{
    uint8_t i = 0;
    if ((c >= 'A') && (c <= 'Z'))
    {
        c = c - 'A' + 10;
    }
    else if ((c >= 'a') && (c <= 'z')) 
    {
        c = c - 'a' + 44;
    }
    else if (c == ' ')
    {
        c = 36;
    }
    else if (c == ':')
    {
        c = 37;
    }
    else if (c == '-')
    {
        c = 38;
    }
    else if (c == '/')
    {
        c = 39;
    }
    else if(c == '.')
    {
        c = 40;
    }
    else if (c == ',')
    {
        c = 41;
    }
    else if (c == '^')
    {
        c = 42;
    }

    if (x > 126) // > 126 当前行不足以写完另一字符
    {
        x = 0;
        y ++;
    }

    LCD5110_Set_XY(x * 6, y);
    for (i = 0; i < 6; i++) 
    {
        LCD5110_WrDat(SmallChars[c * 6 + i]); 
    }                                        
}

void LCD5110_Write_String(uint8_t x, uint8_t y, uint8_t *s)
{
    uint8_t i;

    for (i=0; s[i]!='\0'; i++)
    {
        LCD5110_Write_Char(x + i, y, s[i]);
    }
}
void LCD5110_Write_Num5(uint8_t x, uint8_t y, uint16_t num)
{
    LCD5110_Write_Char(x,     y, num / 10000);
    LCD5110_Write_Char(x + 1, y, num % 10000 / 1000);
    LCD5110_Write_Char(x + 2, y, num % 1000 / 100);
    LCD5110_Write_Char(x + 3, y, num % 100/10);
    LCD5110_Write_Char(x + 4, y, num % 10);
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

LCD5110实时显示温度、湿度、光照度、颗粒物

先上图。 从上到下分别是 温度、湿度、光照度、颗粒物上接线图: [mw_shl_code=c,true] /* BH1750光照强度传感器接法: VCC-5v GND-GND SCL...

Nokia LCD 5110 移植(基于MSP430F5529)

今天也没什么想说的,因为某些事情忙的不行不行的。就偷个懒贴上自己移植的代码吧,希望能帮到初学者们。 头文件nokia_5110.h #ifndef __nokia_5110_h_ #define __...

Micropython加速物联网开发4 - SPI驱动5110LCD屏

5110是84*48点阵LCD屏,其性价比高、接口简单、速度快、功耗低,非常适合电池供电的便携式终端设备。 本例使用TPYBoard开发板SPI1接口驱动5110LCD屏。 连线图即接口说明 LC...

Linux下使用/dev/mem控制GPIO模拟SPI时序控制LCD5110

关于如何使用/dev/mem直接控制GPIO口参见我的另一篇博客:http://blog.csdn.net/tq384998430/article/details/53161192。这篇文章将使用GP...

stm32电机lcd-5110

lcd.c#include "lcd.h" #include "stdlib.h" #include "font.h" #include "usart.h" #include "delay.h" ...

LCD5110驱动代码

  • 2015-01-07 21:19
  • 2.81MB
  • 下载

【HDU】5110 Alexandra and COS 分块处理

传送门:【HDU】5110 Alexandra and COS

5110 lcd ACS2码

STM32_LCD5110驱动

  • 2013-10-17 22:20
  • 704KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)