[技术问答] N76E003这段代码怎么解释

[复制链接]
1206|5
 楼主| xukng 发表于 2020-8-12 11:13 | 显示全部楼层 |阅读模式
Application: SPI Function
//  Master send 0x90 and recevie 0x4E
//  Master send 0x01 and recevie 0x55
//  Master send 0x02 and recevie 0x56
//  Master send 0x03 and recevie 0x4F
//  Master send 0x04 and recevie 0x54
//
//  Master recevie 0x4E and 0x4F form slave after transmitting
//
//  Output : P1.4 & P2.1 flash when SPI pass
//           UART show result on hyper-terminal
//           P0.7 flash when SPI error

void SPI_Error(void)
{
    printf ("\nSPI error.\n");
    while(1)                                    // SPI error and P0.7 flash/
    {
        P07 = 1;
        Timer0_Delay1ms(500);
        P07 = 0;
        Timer0_Delay1ms(500);
    }
        }
void Start_Sending_SPI(UINT8 *pu8MID,UINT8 *pu8DID)
{
    SS = 0;

    SPDR = 0x90;                                // Send 0x90 to Slave
    PCON |= SET_BIT0;                           // Enter idle mode
    if(SPDR != 0x4E)                            // Receive slave 1st DATA
       SPI_Error();
    printf ("\nSlave Return %c!\n",SPDR);
                                          
    SPDR = 0x01;                                // Send 0x01 to Slave
    PCON |= SET_BIT0;                           // Enter idle mode
    if(SPDR != 0x55)                            // Receive slave 2nd DATA  
       SPI_Error();
    printf ("\nSlave Return %c!\n",SPDR);

    SPDR = 0x02;                                // Send 0x02 to Slave
    PCON |= SET_BIT0;                           // Enter idle mode
    if(SPDR != 0x56)                            // Receive slave 3rd DATA
       SPI_Error();
    printf ("\nSlave Return %c!\n",SPDR);

    SPDR = 0x03;                                // Send 0x03 to Slave
    PCON |= SET_BIT0;                           // Enter idle mode
    if(SPDR != 0x4F)                            // Receive slave 4th DATA
       SPI_Error();
    printf ("\nSlave Return %c!\n",SPDR);

    SPDR = 0x04;                                // Send 0x04 to Slave
    PCON |= SET_BIT0;                           // Enter idle mode
    if(SPDR != 0x54)                            // Receive slave 5th DATA
       SPI_Error();
    printf ("\nSlave Return %c!\n",SPDR);

    SPDR = 0x4F;                  
    PCON |= SET_BIT0;                           // Enter idle mode
    *pu8MID = SPDR;                             // Receive Slave 1st DATA fron Slave      
    printf ("\nSlave Return %c!\n",SPDR);

    SPDR = 0x4E;                  
    PCON |= SET_BIT0;                           // Enter idle mode            
    *pu8DID = SPDR;                             // Receive Slave 2nd DATA from Slave
    printf ("\nSlave Return %c!\n",SPDR);

    SS = 1;   
 楼主| xukng 发表于 2020-8-12 11:16 | 显示全部楼层
SPDR = 0x90;                                // Send 0x90 to Slave
    PCON |= SET_BIT0;                           // Enter idle mode
    if(SPDR != 0x4E)                            // Receive slave 1st DATA
       SPI_Error();
    printf ("\nSlave Return %c!\n",SPDR);
按理说执行到SPI_Error就不会往下执行printf啦,怎么解释
wahahaheihei 发表于 2020-8-12 12:31 | 显示全部楼层
哪是if的,入股if不成立不就printf了吗
wahahaheihei 发表于 2020-8-12 12:32 | 显示全部楼层
条件成立才会执行Error,这不一定成立啊,所以printf的概率更大。
小明的同学 发表于 2020-8-12 12:45 | 显示全部楼层
没用error的情况
 楼主| xukng 发表于 2020-8-12 15:15 | 显示全部楼层
明白了,谢啦,陷进自己的错误逻辑去了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

13

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部