野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10308|回复: 1

为啥我的写的数据无法显示 ,字符串可以显示,但是数字不行

[复制链接]
发表于 2018-10-9 15:45:55 来自手机 | 显示全部楼层 |阅读模式

  1. #include "bsp_1602display.h"


  2. void Delay(uint32_t nCont)
  3. {
  4. for(;nCont>0;nCont--);
  5. }

  6. //----显示-----//


  7. static void delay(uint16_t cnt)
  8. {
  9.   for(;cnt!=0;cnt--);
  10. }

  11. void GPIO_Config1(void)
  12. {
  13.   GPIO_InitTypeDef GPIO_InitStructure;

  14.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);

  15.   GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;

  16.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;

  17.   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

  18.   GPIO_Init(GPIOD,&GPIO_InitStructure);

  19.   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;

  20.   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;

  21.   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

  22.   GPIO_Init(GPIOE,&GPIO_InitStructure);

  23. }
  24. /*1602写命令函数*/
  25. void WriteCmd(u8 cmd)
  26. {
  27.   delay(10000);  
  28.   RS0;  
  29.   RW0;
  30.   GPIO_Write(GPIOE,cmd);
  31.   delay(5000);  
  32.   GPIO_ResetBits(GPIOD,GPIO_Pin_10);
  33.   E1;
  34.   delay(5000);
  35. GPIO_ResetBits(GPIOD,GPIO_Pin_10);
  36. }
  37. /*1602写数据函数*/
  38. void WriteData(u8 Dat)
  39. {
  40. delay(10000);
  41.   RS1;
  42.   RW0;         
  43.   GPIO_ResetBits(GPIOD,GPIO_Pin_10);
  44.   delay(5000);
  45.   GPIO_Write(GPIOE,Dat);
  46.   delay(5000);  

  47.   E1;
  48.   delay(5000);
  49.   GPIO_ResetBits(GPIOD,GPIO_Pin_10);
  50. }
  51. /*1602初始化函数*/
  52. void Init1602(void)
  53. {
  54.   WriteCmd(0x38);
  55.   delay(1000);
  56.   WriteCmd(0x08);
  57.   delay(1000);
  58.   WriteCmd(0x01);
  59.   delay(1000);
  60.   WriteCmd(0x06);
  61.   delay(1000);
  62.   WriteCmd(0x0c);
  63.   delay(1000);
  64. }

  65. void Set_xy(unsigned char x,unsigned char y)
  66. {
  67.   unsigned char ss;
  68.   if(x==0)
  69.     ss=0x80+y;
  70.   if(x==1)
  71.     ss=0xc0+y;
  72.   WriteCmd(ss);
  73. }

  74. void disp(unsigned char x,unsigned char y,unsigned char *s)
  75. {
  76.     Set_xy(x,y);
  77.         while(*s)
  78.         {
  79.           WriteData(*s);
  80.           s++;
  81.         }
  82. }

  83. void num_deal(unsigned char x,uint16_t data)
  84. {
  85.         uint16_t a,b,c,d,e,f,g,h;
  86.         a=data/10000000;
  87.         b=data/1000000%10;
  88.         c=data/100000%10;
  89.         d=data/10000%10;
  90.         e=data/1000%10;
  91.         f=data/100%10;
  92.         g=data/10%10;
  93.         h=data%10;
  94.         WriteCmd(0x80+x);
  95.         WriteData(a+0x30);
  96.         WriteData(b+0x30);
  97.         WriteData(c+0x30);
  98.         WriteData(d+0x30);
  99.         WriteData(e+0x30);
  100.         WriteData(f+0x30);
  101.         WriteData(g+0x30);
  102.         WriteData(h+0x30);
  103. }
复制代码
回复

使用道具 举报

发表于 2018-10-9 17:06:18 | 显示全部楼层
u16最大值才65535吧
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-29 00:48 , Processed in 0.026694 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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