赐予我力量吧 2023-04-02 19:49 采纳率: 80%
浏览 29
已结题

请问为什么读不出来数据

请问为什么读不出来数据?



```c
#include "reg52.h"
#include "iic.h"

#define  AT24C02_ADD 0xa0
unsigned char SMGNoDot_CA[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; 
unsigned char count = 0;
unsigned char keynum = 0;
sbit S7=P3^0;
sbit S6=P3^1;
sbit S5=P3^2;
sbit S4=P3^3;

void Delay(unsigned int t)
{
    while(t--);
}

void DelayK(unsigned char t)
{
    while(t--);
}

//============
void DisplaySMG_Bit(unsigned char pos ,unsigned char value)
{
    P2 = 0xc0;
    P0 = pos;
    P2 = 0xe0;
    P0 = value;
}

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

void at24c02_writebyte(unsigned char dizhi,unsigned char shuzhi)
{
    IIC_Start();
    IIC_SendByte(AT24C02_ADD);
    IIC_WaitAck();            
    IIC_SendByte(dizhi);     
    IIC_WaitAck();           
    IIC_SendByte(shuzhi);     
    IIC_WaitAck();   
    IIC_Stop();
}

unsigned char AT24C02_Readbyte(unsigned char dizhi) 
{
  unsigned char Data;    
    IIC_Start();
    IIC_SendByte(AT24C02_ADD); 
    IIC_WaitAck();            
    IIC_SendByte(dizhi);       
    IIC_WaitAck();  
  IIC_Start();    
    IIC_SendByte(AT24C02_ADD | 0x01); 
    IIC_WaitAck();    
    Data = IIC_RecByte(); 
    IIC_SendAck(1);
    IIC_Stop();
    return Data;
}


void KeyBoard()
{
    if(S4 == 0)
        {
            DelayK(100);
            if(S4 == 0)
            {
              count++;
                while(S4 == 0);
            }
        }
        else if(S5 == 0)
        {
            DelayK(100);
            if(S5 == 0)
            {
              count--;
                while(S5 == 0);
            }
        }
        else if(S6 == 0)
        {
          DelayK(100);
            if(S6 == 0)
            {
             at24c02_writebyte(0x00,count);
             Delay(200);
             while(S6 == 0);
            }
        else if(S7 == 0)
        {
            DelayK(100);
            if(S7 == 0)
            {
              count = AT24C02_Readbyte(0x00);
                while(S7 == 0);
            }
        }
    }
}

void main()
{
    P2 = 0xa0;
    P0 = 0x00;
    P2 = 0x00;   
    
    P2 = 0x80;
    P0 = 0xff;
    P2 = 0x00;    
    while(1)
    {
        KeyBoard();
        DisplaySMG_Bit(0x01,SMGNoDot_CA[count / 10]);
        Delay(200);
        DisplaySMG_Bit(0x02,SMGNoDot_CA[count % 10]);
        Delay(200);
    }
}

```

  • 写回答

2条回答 默认 最新

  • 赐予我力量吧 2023-04-03 23:42
    关注

    因为大括号括错位置了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月3日
  • 已采纳回答 4月3日
  • 创建了问题 4月2日

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号