STM32驱动Nokia5110

本文详细介绍了如何使用STM32微控制器来驱动Nokia5110液晶显示屏,涵盖了初始化设置、数据传输等关键步骤,为嵌入式开发提供实用指南。
摘要由CSDN通过智能技术生成

//以下是lcd5110.c

#include "lcd5110.h"  
#include "english_6x8_pixel.h"  
//中文字库自己添加,如果没有请注释起来#include "write_chinese_string_pixel.h"  
  
  
//lcdgpio初始化函数  
//GPIOC.0.9.10.11.12推挽输出,GPIO口可自己设置  
void LCD_GPIO_init(void)  
{  
    GPIO_InitTypeDef GPIO_InitStructure;  
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);  
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12;  
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  
    GPIO_Init(GPIOC,&GPIO_InitStructure);  
}  
  
  
//初始化函数  
void LCD_init(void)  
{  
      
    //产生一个让lcd复位的低电平脉冲  
    LCD_RST = 0;  
    delay_us(1);  
    LCD_RST = 1;  
    //关闭lcd  
    LCD_CE = 0;  
    delay_us(1);  
    //使能lcd  
    LCD_CE = 1;  
    delay_us(1);  
      
    LCD_write_byte(0x21, 0);  
    LCD_write_byte(0xc8, 0);  
    LCD_write_byte(0x06, 0);  
    LCD_write_byte(0x13, 0);  
    LCD_write_byte(0x20, 0);  
    LCD_clear();  
    LCD_write_byte(0x0c, 0);  
    //关闭lcd  
    LCD_CE = 0;  
}  
      
      
//清屏函数  
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坐标函数  
void LCD_set_XY(unsigned char X, unsigned char Y)  
{  
  LCD_write_byte(0x40 | Y, 0);        // column  
  LCD_write_byte(0x80 | X, 0);    // row  
}  
  
  
//显示英文字符  
//输入参数c为显示的字符  
void LCD_write_char(unsigned char c)  
{  
  unsigned char line;  
  
  c -= 32;  
  
  for (line=0; line<6; line++)  
    LCD_write_byte(font6x8[c][line], 1);  
}  
  
  
//数字显示函数  
void LCD_write_number(unsigned char X,unsigned char Y,u16 num)  
{  
      
    //如果数字大于32000则显示输入错误  
    if(num>32000)  
        LCD_write_english_string(X,Y,"ERROR!");  
      
    //如果输入在32000内正常显示  
    else  
    {  
          
        unsigned char a,b,c,d,e; //a,b,c,d,e分别代表数字的万千百十个位  
        a=num/10000;  
        b=(num-a*10000)/1000;  
        c=(num-a*10000-b*1000)/100;  
        d=(num-a*10000-b*1000-c*100)/10;  
        e=num-a*10000-b*1000-c*100-d*10;  
        
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值