標(biāo)題: 這個(gè)單片機(jī)抽獎(jiǎng)原理圖,實(shí)在搞不懂這個(gè)SW1開(kāi)關(guān)的作用,有懂的嗎? [打印本頁(yè)]

作者: 977261156    時(shí)間: 2020-7-13 12:56
標(biāo)題: 這個(gè)單片機(jī)抽獎(jiǎng)原理圖,實(shí)在搞不懂這個(gè)SW1開(kāi)關(guān)的作用,有懂的嗎?


作者: 草草111111    時(shí)間: 2020-7-13 16:18
這個(gè)撥碼開(kāi)關(guān)當(dāng)某一個(gè)開(kāi)關(guān)撥過(guò)去的時(shí)候就輸入低電平,至于怎么用,還需要看設(shè)計(jì)
作者: angmall    時(shí)間: 2020-7-13 19:21
這個(gè)SW1開(kāi)關(guān)的作用是控制隨機(jī)數(shù)的初始化種子

  1. void initrand(void)
  2. {
  3.            unsigned char counter=0;
  4.     P1 = 0xff;
  5.     sw = P1;
  6.     counter = 0;  //統(tǒng)計(jì)開(kāi)關(guān)閉合的數(shù)碼
  7.     if(sw0 == 1)
  8.     {
  9.        counter++;
  10.     }
  11.     if(sw1 == 1)
  12.     {
  13.        counter++;
  14.     }
  15.     if(sw2 == 1)
  16.     {
  17.        counter++;
  18.     }
  19.     if(sw3 == 1)
  20.     {
  21.        counter++;
  22.     }
  23.     if(sw4 == 1)
  24.     {
  25.        counter++;
  26.     }
  27.     if(sw5 == 1)
  28.     {
  29.        counter++;
  30.     }
  31.     if(sw6 == 1)
  32.     {
  33.        counter++;
  34.     }
  35.     if(sw7 == 1)
  36.     {
  37.        counter++;
  38.     }
  39.     srand(counter);       //初始化種子
  40. }
復(fù)制代碼



http://www.torrancerestoration.com/bbs/dpj-159156-1.html

作者: 不要黑    時(shí)間: 2020-7-13 23:04
void srand (unsigned seed); seed:隨機(jī)數(shù)產(chǎn)生器的初始值(種子值)。
通過(guò)撥碼開(kāi)關(guān)可以產(chǎn)生不同的種子值,根據(jù)不同的初始化種子就能產(chǎn)生不同系列的隨機(jī)數(shù),這樣能讓數(shù)據(jù)更大意義上的隨機(jī)
作者: comeon劉    時(shí)間: 2020-7-13 23:35
拉低。。。。。
作者: f556    時(shí)間: 2020-7-14 14:48
抽獎(jiǎng),要有隨機(jī)數(shù),這是基本原理。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1