找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2200|回复: 4
收起左侧

STM32F103ZET6嵌入式开发版驱动1602液晶显示屏问题

[复制链接]
ID:656632 发表于 2019-12-10 10:35 来自手机 | 显示全部楼层 |阅读模式
1.jpg


1引脚  VSS-GND(PE0)

2引脚  VDD-VCC(PE1)
3引脚  V0-GND(PE2)
4引脚  RS(PE3)
5引脚  R/W-GND(PE4)   //始终写指令或数据
6引脚~14引脚(PE7~PE14)
15引脚  A-VCC(PE6)
16引脚  R-GND(PE7)

以上是我的1602显示屏引脚接在我STM32F103ZET6开发板的引脚接口。

可以驱动1602液晶显示屏亮,但是写指令和写数据,不知道有没有写进去,显示屏没有显示相应的字符。
请你指导一下。

main.c文件

  1. #include"stm32f10x.h"
  2. #include"cko.h"
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. uchar table[]={"I like you"};                  //10
  6. uchar table1[]={"I favorite you"};            //14
  7. void delay(uint x)
  8. {
  9.    uint i;
  10.   while(x--)
  11.   for(i=0;i<216;i++);
  12. }
  13. /*int check_busy()                 //¶Áæ¼ì²â
  14. {
  15.    GPIO_Write(GPIOA,0xff);
  16.   RS_CLR;
  17.   delay(10);
  18.   RW_SET;
  19.   delay(10);
  20.   do
  21.   {
  22.      EN_CLR;
  23.     delay(20);
  24.     EN_SET;
  25.     delay(20);
  26.   }while(GPIOA->IDR&0x80);
  27.   return 0;
  28. }                                    */      
  29. void write_com(uint com)
  30. {
  31. //  check_busy();
  32.    RS_CLR;
  33.   RW_CLR;
  34.   EN_CLR;  
  35.   GPIO_Write(GPIOA,com);
  36.   delay(10);
  37.   EN_SET;
  38.   delay(5);
  39.   EN_CLR;
  40. }                              
  41. void write_data(uint shuju)
  42. {
  43. //  check_busy();
  44.    RS_SET;
  45.   RW_CLR;
  46.    EN_CLR;  
  47.   GPIO_Write(GPIOA,shuju);
  48.   delay(10);
  49.   EN_SET;
  50.   delay(5);
  51.   EN_CLR;
  52. }
  53. void init()
  54. {
  55.    uint i;
  56.   write_com(0x38);
  57.   delay(10);
  58.   write_com(0x01);
  59.    delay(10);
  60.   write_com(0x06);
  61.   delay(10);
  62.   write_com(0x0e);
  63.    delay(10);
  64. //  write_com(0x80);
  65. /*   write_com(0x80+0x10);
  66.    for(i=0;i<10;i++)
  67.    {
  68.      write_data(table[i]);
  69.     delay(200);
  70.   }
  71.   write_com(0x80+0x50);
  72.    for(i=0;i<14;i++)
  73.    {
  74.      write_data(table1);
  75.     delay(200);
  76.   }
  77.    for(i=0;i<16;i++)
  78.    {
  79.       write_com(0x18);
  80.      delay(200);
  81.   }                                          */
  82. }
  83. /*void write_char(uchar x,uchar y,uchar data)
  84. {
  85.    if(y==0)
  86.    {
  87.       write_com(0x80+x);
  88.    }
  89.    else
  90.    {
  91.       write_com(0xc0+x);
  92.    }
  93.    write_data(data);
  94.    delay(10);   
  95. }                                                     */
  96. int main()
  97. {
  98.   CKO_Init();
  99.   init();
  100. //  write_data('1');
  101. //  write_char(2,0,'0');
  102.    while(1);
  103. }

  104. cko.h文件
  105. #ifndef _CKO_H
  106. #define _CKO_H
  107. #include"stm32f10x.h"
  108. void CKO_Init(void);

  109. #define RS_SET  GPIO_SetBits(GPIOB,GPIO_Pin_8);
  110. #define RS_CLR  GPIO_ResetBits(GPIOB,GPIO_Pin_8);

  111. #define RW_SET  GPIO_SetBits(GPIOB,GPIO_Pin_9);
  112. #define RW_CLR  GPIO_ResetBits(GPIOB,GPIO_Pin_9);

  113. #define EN_SET  GPIO_SetBits(GPIOB,GPIO_Pin_10);
  114. #define EN_CLR  GPIO_ResetBits(GPIOB,GPIO_Pin_10);
  115. #endif

  116. cko.c文件
  117. #include"cko.h"
  118. #include"stm32f10x.h"
  119. void CKO_Init()
  120. {
  121.    GPIO_InitTypeDef GPIO_InitStructure;
  122.   GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
  123.   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  124.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  125.   
  126.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  127.   GPIO_Init(GPIOA,&GPIO_InitStructure);
  128.   GPIO_SetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);

  129.   GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
  130.   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  131.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  132.   
  133.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  134.   GPIO_Init(GPIOB,&GPIO_InitStructure);

  135.   GPIO_SetBits(GPIOB,GPIO_Pin_14|GPIO_Pin_15);
  136.    GPIO_ResetBits(GPIOB,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_11);
  137. }
复制代码

赋给指令和数据的代码,在PA0~7引脚用高低电平得到了验证,代码使PA0~7引脚输出程序所写的电平,但是显示屏还是没有亮。显示屏还是如上图所示。

回复

使用道具 举报

ID:98992 发表于 2019-12-10 19:13 | 显示全部楼层
就这点能看出来啥呀 把程序贴出来呀
回复

使用道具 举报

ID:416239 发表于 2019-12-10 22:00 | 显示全部楼层
发一下程序,看了程序就知道了,没有程序无法看你引脚怎么用要是引脚没问题那就是配置引脚有问题了一个引脚还有复用功能
回复

使用道具 举报

ID:656632 发表于 2019-12-11 11:18 | 显示全部楼层
erli122 发表于 2019-12-10 19:13
就这点能看出来啥呀 把程序贴出来呀

你好,程序发出来了,你指导一下。
回复

使用道具 举报

ID:656632 发表于 2019-12-11 11:19 | 显示全部楼层
李泽训 发表于 2019-12-10 22:00
发一下程序,看了程序就知道了,没有程序无法看你引脚怎么用要是引脚没问题那就是配置引脚有问题了一个引脚 ...

你好,程序发出来了,你指导一下。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表