⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu_data.c.bak

📁 Embedded C 这本书的范例光碟程式
💻 BAK
字号:
/*------------------------------------------------------------------*-

   Menu_Data.C (v1.00)

  ------------------------------------------------------------------

   Simple framework for menu-driven data acquisition.

   Use 'Hyperterminal' (under Windows 95, 98, 2000) or similar 
   terminal emulator program on other operating systems.

   Terminal options: 

   - Data bits    = 8
   - Parity       = None
   - Stop bits    = 1
   - Flow control = Xon / Xoff

   COPYRIGHT
   ---------

   This code is associated with the book:

   EMBEDDED C by Michael J. Pont 
   [Pearson Education, 2002: ISBN: 0-201-79523-X].

   This code is copyright (c) 2001 by Michael J. Pont.
 
   See book for copyright details and other information.

-*------------------------------------------------------------------*/

#include "Main.H"
#include "Port.H"

#include "Menu_Data.h"
#include "PC_IO.h"

// ------ Public variable declarations -----------------------------
// See Char_Map.c
extern const char code CHAR_MAP_G[10]; 

// ------ Private variables ----------------------------------------
static bit First_time_only_G;

/*------------------------------------------------------------------*-

  MENU_Command_Processor()

  This function is the main menu 'command processor' function.  

  Call this (say) once every 10 ms (approx.).

-*------------------------------------------------------------------*/
void MENU_Command_Processor(void)
   {
   char Ch;

   if (First_time_only_G == 0)
      {
      First_time_only_G = 1;
      MENU_Show_Menu();
      }

   // Check for user inputs
   PC_LINK_IO_Update();

   Ch = PC_LINK_IO_Get_Char_From_Buffer();
      
   if (Ch != PC_LINK_IO_NO_CHAR)
      {
      MENU_Perform_Task(Ch);
      MENU_Show_Menu();
      }
   }


/*------------------------------------------------------------------*-

  MENU_Show_Menu()

  Display menu options on PC screen (via serial link)
  - edit as required to meet the needs of your application.

-*------------------------------------------------------------------*/
void MENU_Show_Menu(void)
   {
   PC_LINK_IO_Write_String_To_Buffer("Menu:\n"); 
   PC_LINK_IO_Write_String_To_Buffer("a - Read P1\n");
   PC_LINK_IO_Write_String_To_Buffer("b - Read P2\n\n");
   PC_LINK_IO_Write_String_To_Buffer("c - Read P3\n\n");
   PC_LINK_IO_Write_String_To_Buffer("d - Read Download\n\n");
   PC_LINK_IO_Write_String_To_Buffer("e - Read Write\n\n");
   PC_LINK_IO_Write_String_To_Buffer("f - Read Status\n\n");
   PC_LINK_IO_Write_String_To_Buffer("? : ");
   }


/*------------------------------------------------------------------*-

  MENU_Perform_Task()

  Perform the required user task
  - edit as required to match the needs of your application.

-*------------------------------------------------------------------*/
void MENU_Perform_Task(char c)
   {
   // Echo the menu option
   PC_LINK_IO_Write_Char_To_Buffer(c);
   PC_LINK_IO_Write_Char_To_Buffer('\n');

   // Perform the task
   switch (c)
      {
      case 'a':
      case 'A':
         {
         Get_Data_From_Port1();
         break;
         }
      
      case 'b':
      case 'B':
         {
         Get_Data_From_Port2();
         break;
         }
      case 'c':
      case 'D':
         {
         Get_Data_From_Port3();
         break;
         }
      
      case 'e':
      case 'E':
         {
         //Get_Data_From_TR();
         break;
         }
      case 'f':
      case 'F':
         {
         //Get_Data_From_TX();
         break;
         }
      } 
   }

/*------------------------------------------------------------------*-

  Get_Data_From_Port1()

-*------------------------------------------------------------------*/
void Get_Data_From_Port1(void)
   {
   tByte Port1 = Data_Port1;
   char String[11] = "\nP1 = XXX\n\n";

   String[6] = CHAR_MAP_G[Port1 / 100];
   String[7] = CHAR_MAP_G[(Port1 / 10) % 10];
   String[8] = CHAR_MAP_G[Port1 % 10];

   PC_LINK_IO_Write_String_To_Buffer(String);
   }

/*------------------------------------------------------------------*-

  Get_Data_From_Port2()

-*------------------------------------------------------------------*/
void Get_Data_From_Port2(void)
   {
   tByte Port2 = Data_Port2;
   char String[11] = "\nP2 = XXX\n\n";

   String[6] = CHAR_MAP_G[Port2 / 100];
   String[7] = CHAR_MAP_G[(Port2 / 10) % 10];
   String[8] = CHAR_MAP_G[Port2 % 10];

   PC_LINK_IO_Write_String_To_Buffer(String);
   }

/*------------------------------------------------------------------*-
  ---- END OF FILE -------------------------------------------------
-*------------------------------------------------------------------*/

⌨️ 快捷键说明

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