📄 menu_robot.c
字号:
/*------------------------------------------------------------------*-
Menu_Robot.C (v1.00)
------------------------------------------------------------------
Simple framework for controlling a robot over a serial link.
On PC 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_Robot.h"
#include "PC_IO.h"
// ------ Public variable declarations -----------------------------
// See Stepper.c
extern bit Motor_L;
extern bit Motor_R;
// ------ 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();
}
}
/*------------------------------------------------------------------*-
FUNCTION: MENU_Show_Menu()
Display menu options on PC screen (via serial link)
- edit as required to meet the needs of your application.
HARDWARE: -
GLOBALS: -
PARAMS: void
RETURNS: void
-*------------------------------------------------------------------*/
void MENU_Show_Menu(void)
{
PC_LINK_IO_Write_String_To_Buffer("a - Ahead\n");
PC_LINK_IO_Write_String_To_Buffer("l - Left\n");
PC_LINK_IO_Write_String_To_Buffer("r - Right\n");
PC_LINK_IO_Write_String_To_Buffer("s - STOP\n\n");
PC_LINK_IO_Write_String_To_Buffer("? : ");
}
/*------------------------------------------------------------------*-
FUNCTION: MENU_Perform_Task()
Perform the required user task
- edit as required to match the needs of your application.
HARDWARE: Uses the on-chip UART hardware.
GLOBALS: -
PARAMS: void
RETURNS: void
-*------------------------------------------------------------------*/
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':
{
PC_LINK_IO_Write_String_To_Buffer("<*> AHEAD\n\n");
Motor_L = 1;
Motor_R = 1;
break;
}
case 'l':
case 'L':
{
PC_LINK_IO_Write_String_To_Buffer("<** LEFT\n\n");
Motor_L = 0;
Motor_R = 1;
break;
}
case 'r':
case 'R':
{
PC_LINK_IO_Write_String_To_Buffer("**> RIGHT\n\n");
Motor_L = 1;
Motor_R = 0;
break;
}
case 's':
case 'S':
{
PC_LINK_IO_Write_String_To_Buffer("*** STOP\n\n");
Motor_L = 0;
Motor_R = 0;
}
}
}
/*------------------------------------------------------------------*-
---- END OF FILE -------------------------------------------------
-*------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -