random.c

来自「zigbee通信系统中使用芯片cc2430实现点对点通信的源码」· C语言 代码 · 共 113 行

C
113
字号
/******************************************************************************
Filename:     random.c
Target:       cc2430
Revised:      16/12-2005
Revision:     1.0

Description:
    This application shows how to create a random sequence of bytes. The sequence
    is displayed on the LCD and used to toggle the green and yellow LEDs.

******************************************************************************/

#include "app_ex.h"

void initRandom(void);
void random_main(void);


/******************************************************************************
* @fn  initRandom
*
* @brief
*      Initializes the components for the random generator application example.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void initRandom(void)
{
   DISABLE_ALL_INTERRUPTS();

      halInitRandomGenerator();

   initLcd();

   INIT_GLED();
   INIT_YLED();
}


/******************************************************************************
* @fn  random_main
*
* @brief
*      Main function.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void random_main(void){
#else
void main(void){
#endif
   BYTE randomChar;
   UINT8 i, rand;

   initRandom();

   lcdUpdate((char*)"Random text:", (char*)"");

   while( !stopApplication() ){
      //read random register
      for(i = 0; (i < LINE_SIZE); i++)
      {
         GET_RANDOM_BYTE(rand);

         SET_LED_MASK( rand );

         // randChar is equal a random value between 'a' and 'z'
         // in the ascii table
         randomChar = 'a' + (rand % ('z' - 'a')) ;
         lcdUpdateChar(LINE2, i, randomChar);

         halWait(0x0F);
      }

      LED1 = LED3 = LED_OFF;
   }
   return;
}


/******************************************************************************
* @fn  clockmodes_init
*
* @brief
*      Initializes the random generator application example.
*
* Parameters:
*
* @param  APPLICATION *a
*         Main application
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void random_init(APPLICATION *a){
   a->menuText = (char*)"Random";
   a->description = (char*)"Sequence";
   a->main_func = random_main;
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?