美文网首页
随机数的产生

随机数的产生

作者: 昨天剩下的一杯冷茶 | 来源:发表于2020-07-02 14:48 被阅读0次

    代码下载地址:
    https://download.csdn.net/download/qq_31806069/12569995

    int main(void)
    {
        char buf[30];
    
        simple_uart_config(0xff,9,0xff,11,false);
        uart_exit();
        
        while(1)
        {
            sprintf(buf,"rng:%02x\r\n",get_rng());
            simple_uart_putstring((const uint8_t *)buf);
            nrf_delay_ms(1000);
        }
    }
    
    
    
    uint8_t get_rng(void)
    {
        uint8_t result = 0;
        NRF_RNG->TASKS_START = 1; // start the RNG peripheral.
    
        // Clear the VALRDY EVENT.
        NRF_RNG->EVENTS_VALRDY = 0;
    
        // Wait until the value ready event is generated.
        while (NRF_RNG->EVENTS_VALRDY == 0)
        {
            // Do nothing.
        }
        result = (uint8_t)NRF_RNG->VALUE;
        
        NRF_RNG->TASKS_STOP = 1;
    
        return result;
    }
    
    
    
    

    效果:
    rng:c1
    rng:da
    rng:51
    rng:68
    rng:86
    rng:ef
    rng:db
    rng:cc
    rng:be
    rng:f1
    rng:70
    rng:93
    rng:a1
    rng:d0
    rng:ef
    rng:af
    rng:a3
    rng:ef
    rng:98
    rng:68
    rng:a5
    rng:ec
    rng:19
    rng:42
    rng:5f
    rng:1d

    相关文章

      网友评论

          本文标题:随机数的产生

          本文链接:https://www.haomeiwen.com/subject/rdkrqktx.html