找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 5280|回復(fù): 9
打印 上一主題 下一主題
收起左側(cè)

STM32與LCD1602連接GPIO_Mode配置用什么方式

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:71233 發(fā)表于 2015-3-27 10:38 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
請(qǐng)教:大家在處理STM32與LCD1602連接時(shí),GPIO_Mode配置用什么方式?用什么方式較安全?還有,LCD1602為5V的,可以直接相連嗎?
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:78060 發(fā)表于 2015-4-25 21:12 | 只看該作者
不知道!!我也在學(xué)習(xí)!!
回復(fù)

使用道具 舉報(bào)

板凳
ID:58502 發(fā)表于 2015-4-26 02:51 | 只看該作者
最好使用開漏輸出
回復(fù)

使用道具 舉報(bào)

地板
ID:190624 發(fā)表于 2017-8-25 16:47 | 只看該作者
連接有圖片嗎?
回復(fù)

使用道具 舉報(bào)

5#
ID:229469 發(fā)表于 2017-8-26 16:29 | 只看該作者
1602是什么接口的,I2C嗎
回復(fù)

使用道具 舉報(bào)

6#
ID:71233 發(fā)表于 2023-1-4 09:28 | 只看該作者
zhouwentao 發(fā)表于 2017-8-26 16:29
**** 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽 ****

I2C或并口
回復(fù)

使用道具 舉報(bào)

7#
ID:996773 發(fā)表于 2023-1-4 10:24 | 只看該作者
1602液晶屏原生是沒有i2c接口的,有也是用串轉(zhuǎn)并芯片實(shí)現(xiàn)的,如果用并口的話還是用傳統(tǒng)弱上拉模式,要么上拉高電平,要么拉低低電平。開漏模式就是懸空高阻抗容易受干擾
回復(fù)

使用道具 舉報(bào)

8#
ID:1034262 發(fā)表于 2023-1-4 11:09 | 只看該作者
開漏+上拉。
回復(fù)

使用道具 舉報(bào)

9#
ID:1060471 發(fā)表于 2023-1-7 12:47 | 只看該作者
  #ifndef _LCD1602_H    #define _LCD1602_H    #include “LCD1602.H”    //============================端口位清除寄存器==============================================//    #define LCD1602_RS0 GPIOE-》BRR = 0x00000004 //低電平 PE.2    #define LCD1602_RW0 GPIOE-》BRR = 0x00000010 //低電平 PE.4    #define LCD1602_EN0 GPIOE-》BRR = 0x00000040 //低電平 PE.6    //============================端口位設(shè)置/清除寄存器=========================================//    #define LCD1602_RS1 GPIOE-》BSRR = 0x00000004 //高電平 PE.2    #define LCD1602_RW1 GPIOE-》BSRR = 0x00000010 //高電平 PE.4    #define LCD1602_EN1 GPIOE-》BSRR = 0x00000040 //高電平 PE.4    #define DATA_OUT GPIOD-》ODR//數(shù)據(jù)端口 PB0-PB7    //==========================================================================================//    //單片機(jī)系統(tǒng)時(shí)鐘在72MHZ下的延時(shí)    void Delay_us(unsigned long CountLing)    {    signed char i;    while(CountLing--)    {    i = 10;    while(i--);    }    }    //==========================================================================================//    //LCD1602液晶讀忙狀態(tài)    void LCD_FBUF(void)    {    LCD1602_RS0; //RS信號(hào)拉低    LCD1602_RW1; //RW信號(hào)拉高    LCD1602_EN1;//EN信號(hào)拉高    DATA_OUT = 0xFF; //數(shù)據(jù)端口 11111111全高電平    while((DATA_OUT & 0x80) == 0x80); //判斷數(shù)據(jù)端口PB7 是否一直高    LCD1602_RW1;//RW信號(hào)拉高    LCD1602_EN0; //EN信號(hào)拉低    }    //==========================================================================================//    //LCD1602寫指令子函數(shù)    void Write_LCD1602_InstrucTIon_Com(unsigned char Com)    {    LCD_FBUF(); //讀忙狀態(tài)    LCD1602_RS0; //RS信號(hào)拉低寫指令    LCD1602_RW0; //RW信號(hào)拉低    LCD1602_EN0; //EN信號(hào)拉低    DATA_OUT = Com; //數(shù)據(jù)端口指令輸入    Delay_us(340); //延時(shí)1ms    LCD1602_EN1; //EN信號(hào)一個(gè)高脈沖    Delay_us(340); //延時(shí)1ms    LCD1602_EN0;    }    //==========================================================================================//    //LCD1602寫數(shù)據(jù)子函數(shù)    void Write_LCD1602_InstrucTIon_Data(unsigned char Date)    {    LCD_FBUF(); //讀忙狀態(tài)    LCD1602_RS1; //RS信號(hào)拉高寫數(shù)據(jù)指令    LCD1602_RW0;    LCD1602_EN0; //EN信號(hào)拉低    DATA_OUT = Date; //數(shù)據(jù)端口數(shù)據(jù)輸入    Delay_us(340); //延時(shí)1ms    LCD1602_EN1; //EN信號(hào)一個(gè)高脈沖    Delay_us(340); //延時(shí)1ms    LCD1602_EN0;    }    //==========================================================================================//    //LCD1602寫指令和寫數(shù)據(jù)子函數(shù)    void Write_LCD1602_InstrucTIon_Com_Data(unsigned char CountLiey, unsigned char Date)    {    if(CountLiey == 0) //CountLiey == 0 寫指令    {    Write_LCD1602_InstrucTIon_Com(Date); // 寫指令    }    else //CountLiey !=0 寫數(shù)據(jù)    {    Write_LCD1602_Instruction_Data(Date); //不等于0寫數(shù)據(jù)    }    }    //==========================================================================================//    //LCD1602寫指令初始化子函數(shù)    void Init_LCD1602(void)    {    Write_LCD1602_Instruction_Com(0x38); //設(shè)置16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口    Delay_us(6); //延時(shí) 200us    Write_LCD1602_Instruction_Com(0x38); //設(shè)置16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口    Delay_us(6); //延時(shí) 200us    Write_LCD1602_Instruction_Com(0x0C); //設(shè)置打開顯示    Delay_us(6); //延時(shí) 200us    Write_LCD1602_Instruction_Com(0x06); //讀或?qū)懸粋(gè)字符后地址指針加1    Delay_us(6);    Write_LCD1602_Instruction_Com(0x01); //顯示清屏    Delay_us(6);    }    #endif    //========================================END==================================================//    #include “stm32f10x_lib.h”    #include “LCD1602.H”    //#include “DS18B20.H”    typedef volatile unsigned char uint8;    typedef volatile unsigned int uint16;    typedef volatile unsigned long uint32;    //==========================================================================================//    //配置GPIO端口    void GPIO_InitStructReadtempCmd(void)    {    GPIO_InitTypeDef GPIO_InitStruct;    //GPIOC端口初始化    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 |GPIO_Pin_4 | GPIO_Pin_6; // LCD1602 RS-RW-EN腳    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_OD; //開漏輸出    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //輸出速率50MHZ    GPIO_Init(GPIOE, &GPIO_InitStruct); //GPIOE端口初始化    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |//數(shù)據(jù)腳 PB0-PB7    GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_OD; //開漏輸出    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //輸出速率50MHZ    GPIO_Init(GPIOD, &GPIO_InitStruct); //GPIOD端口初始化    }    //==========================================================================================//    //配置GPIO外設(shè)時(shí)鐘    void RCC_APB2PeriphReadtempyCmd(void)    {    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); // 開啟GPIOD外設(shè)時(shí)鐘    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); // 開啟GPIOE外設(shè)時(shí)鐘    }    //==========================================================================================//    //函數(shù)主題    int main(void)    {    RCC_APB2PeriphReadtempyCmd();//外設(shè)時(shí)鐘初始化 //注意外設(shè)初始化一定要在GPIO端口配置初始化前面    GPIO_InitStructReadtempCmd(); //GPIO端口配置初始化    while(1)    {    Write_LCD1602_Instruction_Com_Data(0, 0x80+4); //0是寫指令    Write_LCD1602_Instruction_Com_Data(1, ‘A’ ); //1是寫數(shù)據(jù)    }    }
回復(fù)

使用道具 舉報(bào)

10#
ID:1060471 發(fā)表于 2023-1-7 12:48 | 只看該作者
  #ifndef _LCD1602_H

  #define _LCD1602_H

  #include “LCD1602.H”

  //============================端口位清除寄存器==============================================//

  #define LCD1602_RS0 GPIOE-》BRR = 0x00000004 //低電平 PE.2

  #define LCD1602_RW0 GPIOE-》BRR = 0x00000010 //低電平 PE.4

  #define LCD1602_EN0 GPIOE-》BRR = 0x00000040 //低電平 PE.6

  //============================端口位設(shè)置/清除寄存器=========================================//

  #define LCD1602_RS1 GPIOE-》BSRR = 0x00000004 //高電平 PE.2

  #define LCD1602_RW1 GPIOE-》BSRR = 0x00000010 //高電平 PE.4

  #define LCD1602_EN1 GPIOE-》BSRR = 0x00000040 //高電平 PE.4

  #define DATA_OUT GPIOD-》ODR//數(shù)據(jù)端口 PB0-PB7

  //==========================================================================================//

  //單片機(jī)系統(tǒng)時(shí)鐘在72MHZ下的延時(shí)

  void Delay_us(unsigned long CountLing)

  {

  signed char i;

  while(CountLing--)

  {

  i = 10;

  while(i--);

  }

  }

  //==========================================================================================//

  //LCD1602液晶讀忙狀態(tài)

  void LCD_FBUF(void)

  {

  LCD1602_RS0; //RS信號(hào)拉低

  LCD1602_RW1; //RW信號(hào)拉高

  LCD1602_EN1;//EN信號(hào)拉高

  DATA_OUT = 0xFF; //數(shù)據(jù)端口 11111111全高電平

  while((DATA_OUT & 0x80) == 0x80); //判斷數(shù)據(jù)端口PB7 是否一直高

  LCD1602_RW1;//RW信號(hào)拉高

  LCD1602_EN0; //EN信號(hào)拉低

  }

  //==========================================================================================//

  //LCD1602寫指令子函數(shù)

  void Write_LCD1602_InstrucTIon_Com(unsigned char Com)

  {

  LCD_FBUF(); //讀忙狀態(tài)

  LCD1602_RS0; //RS信號(hào)拉低寫指令

  LCD1602_RW0; //RW信號(hào)拉低

  LCD1602_EN0; //EN信號(hào)拉低

  DATA_OUT = Com; //數(shù)據(jù)端口指令輸入

  Delay_us(340); //延時(shí)1ms

  LCD1602_EN1; //EN信號(hào)一個(gè)高脈沖

  Delay_us(340); //延時(shí)1ms

  LCD1602_EN0;

  }

  //==========================================================================================//

  //LCD1602寫數(shù)據(jù)子函數(shù)

  void Write_LCD1602_InstrucTIon_Data(unsigned char Date)

  {

  LCD_FBUF(); //讀忙狀態(tài)

  LCD1602_RS1; //RS信號(hào)拉高寫數(shù)據(jù)指令

  LCD1602_RW0;

  LCD1602_EN0; //EN信號(hào)拉低

  DATA_OUT = Date; //數(shù)據(jù)端口數(shù)據(jù)輸入

  Delay_us(340); //延時(shí)1ms

  LCD1602_EN1; //EN信號(hào)一個(gè)高脈沖

  Delay_us(340); //延時(shí)1ms

  LCD1602_EN0;

  }

  //==========================================================================================//

  //LCD1602寫指令和寫數(shù)據(jù)子函數(shù)

  void Write_LCD1602_InstrucTIon_Com_Data(unsigned char CountLiey, unsigned char Date)

  {

  if(CountLiey == 0) //CountLiey == 0 寫指令

  {

  Write_LCD1602_InstrucTIon_Com(Date); // 寫指令

  }

  else //CountLiey !=0 寫數(shù)據(jù)

  {

  Write_LCD1602_Instruction_Data(Date); //不等于0寫數(shù)據(jù)

  }

  }

  //==========================================================================================//

  //LCD1602寫指令初始化子函數(shù)

  void Init_LCD1602(void)

  {

  Write_LCD1602_Instruction_Com(0x38); //設(shè)置16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口

  Delay_us(6); //延時(shí) 200us

  Write_LCD1602_Instruction_Com(0x38); //設(shè)置16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口

  Delay_us(6); //延時(shí) 200us

  Write_LCD1602_Instruction_Com(0x0C); //設(shè)置打開顯示

  Delay_us(6); //延時(shí) 200us

  Write_LCD1602_Instruction_Com(0x06); //讀或?qū)懸粋(gè)字符后地址指針加1

  Delay_us(6);

  Write_LCD1602_Instruction_Com(0x01); //顯示清屏

  Delay_us(6);

  }

  #endif

  //========================================END==================================================//

  #include “stm32f10x_lib.h”

  #include “LCD1602.H”

  //#include “DS18B20.H”

  typedef volatile unsigned char uint8;

  typedef volatile unsigned int uint16;

  typedef volatile unsigned long uint32;

  //==========================================================================================//

  //配置GPIO端口

  void GPIO_InitStructReadtempCmd(void)

  {

  GPIO_InitTypeDef GPIO_InitStruct;

  //GPIOC端口初始化

  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 |GPIO_Pin_4 | GPIO_Pin_6; // LCD1602 RS-RW-EN腳

  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_OD; //開漏輸出

  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //輸出速率50MHZ

  GPIO_Init(GPIOE, &GPIO_InitStruct); //GPIOE端口初始化

  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |//數(shù)據(jù)腳 PB0-PB7

  GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_OD; //開漏輸出

  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //輸出速率50MHZ

  GPIO_Init(GPIOD, &GPIO_InitStruct); //GPIOD端口初始化

  }

  //==========================================================================================//

  //配置GPIO外設(shè)時(shí)鐘

  void RCC_APB2PeriphReadtempyCmd(void)

  {

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); // 開啟GPIOD外設(shè)時(shí)鐘

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); // 開啟GPIOE外設(shè)時(shí)鐘

  }

  //==========================================================================================//

  //函數(shù)主題

  int main(void)

  {

  RCC_APB2PeriphReadtempyCmd();//外設(shè)時(shí)鐘初始化 //注意外設(shè)初始化一定要在GPIO端口配置初始化前面

  GPIO_InitStructReadtempCmd(); //GPIO端口配置初始化

  while(1)

  {

  Write_LCD1602_Instruction_Com_Data(0, 0x80+4); //0是寫指令

  Write_LCD1602_Instruction_Com_Data(1, ‘A’ ); //1是寫數(shù)據(jù)

  }

  }
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表