zoukankan      html  css  js  c++  java
  • STM32 驱动1602液晶

    利用STM32f103c8t6单片机驱动1602A液晶进行显示功能

    上图即为写入信息后的效果图

    本人用的是STM32的核心系统,无任何外设

    库函数:3.5版本的库函数

    驱动模式:采用4线驱动模式

    供电:STM32采用3.3v供电,1602液晶采用5v供电(如果采用3.3v供电,只能显示背光,其他数据均无法显示)

    上图所示的杜邦线的连接方法:
    RS->C13,   RW->C14,   E->C15,  D4-D7->A4-A7

    代码部分:
    /****************************LCD.c**************************/

    #include "stm32f10x.h"
    #include "stm32f10x_conf.h"
    #include "LCD.h"
    unsigned char LCD_PORT;

    void LCD_delay(void)
    {
    unsigned int i,j;
    for(i=0;i<800;i++)
    for(j=0;j<800;j++);
    }


    void LCD_Write_Com(unsigned char c)
    {
    u16 f;
    register unsigned char i;
    GPIO_SetBits(GPIOA,GPIO_Pin_7);
    LCD_RS_L();
    LCD_RW_H();
    do
    {
    LCD_E_H();
    f=LCD_FLAG();
    LCD_E_L();
    }while(f==1);

    LCD_RW_L();


    i=c;
    i&=0xf0;
    GPIO_Write(GPIOA,i|0);
    LCD_E_H();
    LCD_delay();
    LCD_E_L();


    i=c<<4;
    i&=0xf0;
    GPIO_Write(GPIOA,i);
    LCD_E_H();
    LCD_delay();
    LCD_E_L();


    }


    void LCD_Write_Data(unsigned char d)
    {
    u16 f;
    register unsigned char i;
    GPIO_SetBits(GPIOA,GPIO_Pin_7);
    LCD_RS_L();
    LCD_RW_H();
    do
    {
    LCD_E_H();
    f=LCD_FLAG();
    LCD_E_L();
    }while(f==1);

    LCD_RS_H();
    LCD_RW_L();


    i=d;
    i&=0xf0;
    GPIO_Write(GPIOA,i);
    LCD_E_H();
    LCD_delay();
    LCD_E_L();


    i=(d<<4);
    i&=0xf0;
    GPIO_Write(GPIOA,i);
    LCD_E_H();
    LCD_delay();
    LCD_E_L();
    }


    void LCD_INIT(void)
    {
    LCD_delay();
    LCD_Write_Com(0x28);
    LCD_Write_Com(0x01);
    LCD_Write_Com(0x06);
    LCD_Write_Com(0x0f);
    }


    void LCD_PUTS(unsigned char line,unsigned char col,unsigned char *s)
    {
    unsigned char i,addr;
    if(line==1) addr=0x80;
    else if(line==2) addr=0x80+0x40;
    LCD_Write_Com(addr+col);
    for(i=0;i<20;i++)
    {
    if(s[i]!=0)
    LCD_Write_Data(s[i]);
    else
    break;
    }
    }

    /*****************主函数中的端口设置***********************/

    void Display_GPIO_Conf(void)
    {

    GPIO_InitTypeDef GPIO_InitIntructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);

    GPIO_InitIntructure.GPIO_Mode=GPIO_Mode_Out_PP;
    GPIO_InitIntructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitIntructure.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
    GPIO_Init(GPIOC,&GPIO_InitIntructure);

    GPIO_InitIntructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
    GPIO_Init(GPIOA,&GPIO_InitIntructure);

    GPIO_InitIntructure.GPIO_Pin=GPIO_Pin_7;
    GPIO_InitIntructure.GPIO_Mode=GPIO_Mode_Out_OD;
    GPIO_Init(GPIOA,&GPIO_InitIntructure);


    }

    其中最为特殊的是:A7,需要将其设置为OD模式,外接上拉电阻,将其拉到5v,目的:将其变为准双向IO口,可以读取1602的忙状态信号。

  • 相关阅读:
    分西瓜(dfs)
    括号配对(栈)
    gcd表(欧几里得定理)
    整数性质(拓展欧几里得算法)
    欧几里得算法(求最大公约数)拓展欧几里得算法
    删除元素(二分查找)
    括号配对问题
    公司组织看电影(综合)
    取余数(%)
    幼儿园分苹果(/)
  • 原文地址:https://www.cnblogs.com/ALLENGF/p/4651591.html
Copyright © 2011-2022 走看看