野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13124|回复: 2

1602不显示,加了上拉电阻

[复制链接]
发表于 2015-5-3 15:46:25 | 显示全部楼层 |阅读模式
//----主函数-----//
#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

请问这有问题吗?



回复

使用道具 举报

 楼主| 发表于 2015-5-3 17:09:16 | 显示全部楼层
谢谢,我找到问题了,延时短了
回复 支持 反对

使用道具 举报

发表于 2015-5-4 09:13:21 | 显示全部楼层
嗯,51的程序移植到stm32是要把延时加长一点
回复 支持 反对

使用道具 举报

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

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-22 20:21 , Processed in 0.027295 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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