打印

1602不显示,加了上拉电阻

[复制链接]
257|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
王将|  楼主 | 2019-11-27 12:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
//----主函数-----//
#include "stm32f10x.h"
#include "1602.h"

void Delay(u32 nCont);          //延时函数

int main()
{
   Delay(100);
   GPIO_Config1();
   Init1602();
   disp(0,0,"I Love You");
   disp(1,0,"author is Zwl");
  while(1);  
}


void Delay(u32 nCont)
{
for(;nCont>0;nCont--);
}

//----显示-----//
#include "1602.h"

static void delay(u16 cnt)
{
  for(;cnt!=0;cnt--);
}

void GPIO_Config1(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);

  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;

  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

  GPIO_Init(GPIOD,&GPIO_InitStructure);

  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;

  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;

  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

  GPIO_Init(GPIOE,&GPIO_InitStructure);

}

void WriteCmd(u8 cmd)
{
  delay(1000);  
  RS0;  
  RW0;
  GPIO_Write(GPIOE,cmd);
  delay(500);  
  GPIO_ResetBits(GPIOD,GPIO_Pin_10);
  E1;
  delay(500);
GPIO_ResetBits(GPIOD,GPIO_Pin_10);
}

void WriteData(u8 Dat)
{
delay(1000);
  RS1;
  RW0;         
  GPIO_ResetBits(GPIOD,GPIO_Pin_10);
  delay(500);
  GPIO_Write(GPIOE,Dat);
  delay(500);  

  E1;
  delay(500);
  GPIO_ResetBits(GPIOD,GPIO_Pin_10);
}

void Init1602(void)
{
  WriteCmd(0x38);
  delay(100);
  WriteCmd(0x08);
  delay(100);
  WriteCmd(0x01);
  delay(100);
  WriteCmd(0x06);
  delay(100);
  WriteCmd(0x0c);
  delay(100);
}

void Set_xy(unsigned char x,unsigned char y)
{
  unsigned char ss;
  if(x==0)
    ss=0x80+y;
  if(x==1)
    ss=0xc0+y;
  WriteCmd(ss);
}

void disp(unsigned char x,unsigned char y,unsigned char *s)
{
    Set_xy(x,y);
        while(*s)
        {
          WriteData(*s);
          s++;
        }
}
#ifndef _1602_H_
#define _1602_H_

#include "stm32f10x.h"

#define RS0 GPIO_ResetBits(GPIOD,GPIO_Pin_8)
#define RS1 GPIO_SetBits(GPIOD,GPIO_Pin_8)

#define RW0 GPIO_ResetBits(GPIOD,GPIO_Pin_9)
#define RW1 GPIO_SetBits(GPIOD,GPIO_Pin_9)

#define E1 GPIO_SetBits(GPIOD,GPIO_Pin_10)

void WriteCmd(u8 cmd);
void WriteData(u8 Dat);
void Init1602(void);
void Set_xy(unsigned char x,unsigned char y);
void disp(unsigned char x,unsigned char y,unsigned char *s);

void GPIO_Config1(void);

#endif

请问这有问题吗?

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

419

主题

419

帖子

0

粉丝