打印
[技术问答]

N76E003这段代码怎么解释

[复制链接]
835|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的概率更大。

使用特权

评论回复
5
小明的同学| | 2020-8-12 12:45 | 只看该作者
没用error的情况

使用特权

评论回复
6
xukng|  楼主 | 2020-8-12 15:15 | 只看该作者
明白了,谢啦,陷进自己的错误逻辑去了

使用特权

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

本版积分规则

4

主题

13

帖子

0

粉丝