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

📄 root.c

📁 Demo HZ256 Cluster LCD2 CW31 SH v1 ICD
💻 C
字号:
/******************************************************************************
*                                                  
*  (c) copyright Freescale Semiconductor Hong Kong Ltd. 2004
*  ALL RIGHTS RESERVED
*                                                                       
*******************************************************************************  
** THIS  CODE IS ONLY INTENDED AS AN EXAMPLE FOR DEMONSTRATING THE FREESCALE **
** MICROCONTROLLERS.  IT  HAS ONLY BEEN GIVEN A MIMIMUM LEVEL OF TEST. IT IS **
** PROVIDED  'AS  SEEN'  WITH  NO  GUARANTEES  AND  NO  PROMISE  OF SUPPORT. **
*******************************************************************************  
*                                                                           
* FILE:         root.c	          REVISION 0.3
*  
* DESCRIPTION:  Application code is placed here.
*               This module handles main task related to search all test menus 
*               and options to be tested.
*               Program the main task to search the sub-menu tasks to execuate.
*               Decode commands from PC Hyperterminal via SCI0 to select 
*               appropriate menu task to execuate.
* 			
*
* COMPILER: Metrowerks            VERSION: ADS v1.2 (initial version)           
*                                 VERSION: ADS v2.0 (Demo alpha/beta version)
*                                 VERSION: ADS v3.1 (Demo version)
*
* NOTES
* -----
* All modules remain at their reset addresses.                                                      
*
*
* UPDATED HISTORY:
*
* REV   YYYY.MM.DD  AUTHOR        DESCRIPTION OF CHANGE
* ---   ----------  ------        --------------------- 
* 0.0   2002.03.27  Kenny Lam     Initial version
* 0.1   2002.09.12  Kenny Lam     Demo alpha version
* 0.2   2004.04.12  Kenny Lam     Demo beta version
* 0.2   2006.01.22  Kenny Lam     Demo version
*
******************************************************************************/                                                                        
/* Freescale  is  not  obligated  to  provide  any  support, upgrades or new */
/* releases  of  the Software. Freescale may make changes to the Software at */
/* any time, without any obligation to notify or provide updated versions of */
/* the  Software  to you. Freescale expressly disclaims any warranty for the */
/* Software.  The  Software is provided as is, without warranty of any kind, */
/* either  express  or  implied,  including, without limitation, the implied */
/* warranties  of  merchantability,  fitness  for  a  particular purpose, or */
/* non-infringement.  You  assume  the entire risk arising out of the use or */
/* performance of the Software, or any systems you design using the software */
/* (if  any).  Nothing  may  be construed as a warranty or representation by */
/* Freescale  that  the  Software  or  any derivative work developed with or */
/* incorporating  the  Software  will  be  free  from  infringement  of  the */
/* intellectual property rights of third parties. In no event will Freescale */
/* be  liable,  whether in contract, tort, or otherwise, for any incidental, */
/* special,  indirect, consequential or punitive damages, including, but not */
/* limited  to,  damages  for  any loss of use, loss of time, inconvenience, */
/* commercial loss, or lost profits, savings, or revenues to the full extent */
/* such  may be disclaimed by law. The Software is not fault tolerant and is */
/* not  designed,  manufactured  or  intended by Freescale for incorporation */
/* into  products intended for use or resale in on-line control equipment in */
/* hazardous, dangerous to life or potentially life-threatening environments */
/* requiring  fail-safe  performance,  such  as  in the operation of nuclear */
/* facilities,  aircraft  navigation  or  communication systems, air traffic */
/* control,  direct  life  support machines or weapons systems, in which the */
/* failure  of  products  could  lead  directly to death, personal injury or */
/* severe  physical  or  environmental  damage  (High  Risk Activities). You */
/* specifically  represent and warrant that you will not use the Software or */
/* any  derivative  work of the Software for High Risk Activities.           */
/* Freescale  and the Freescale logos are registered trademarks of Freescale */
/* Semiconductor Inc.                                                        */ 
/*****************************************************************************/

#include <hidef.h>
#include "cluster_includes.h"
#include "rooth.h"
#include "H256Port.h"
#include "Const.h"
#include "GlobalVar.h"

const struct text root_menu_text =
					  {"\n\t\tTest Menu(v.6)\n"\
					  "\t0. Root Menu\n"\
					  "\n\r",
					  "1",	
					  ROOT_PAGE,
					  &root_test_option,};	//ROOT_PAGE

const struct text *text_option[] = {{&root_menu_text},
									};


#pragma CODE_SEG DEFAULT
/****************************************************************************
* get_menu() -
*
* Description : Get the test menu 
*             : 
*			  :
* Example     : 
* Input 	    : page_refresh
* Output	    : N/A
* Modify      : N/A
* Return      : void
****************************************************************************/
void get_menu(char page_refresh)
{	
	const struct text 	*st_ptr;
	struct menu_ret     m_data;
	byte			          cdata,option_limit;
	char			          *cptr;
	void			          *strptr;

	m_data.page=ROOT_PAGE;
	m_data.redraw=page_refresh;
	
  while(PowerFlag==ENABLE)
  {
    st_ptr = text_option[get_option(m_data.page)];  // get address from text option
	  cptr=st_ptr->str;					                      // structure char pointer for text display
  	  
	  if(m_data.redraw == ENABLE)										 
	    disp_str(cptr);															  // display the menu
	  
    option_limit=*(st_ptr->option_limit);           // get option limit for keyboard
      
    do
    {
      cdata=menurx_char0(m_data.page);
      if(cdata==CR || cdata=='9' || cdata==DISABLE)
	    break;
    }
    while((cdata>option_limit)||(cdata<'0'));
      							            // get input from user and limited by *cptr++
	  strptr=(void*)st_ptr->fn;	  // get structure fn pointer
	  m_data.option=cdata;		    // update the m_data.option for fn pointer
	  ((void (*)(struct menu_ret *)) strptr)(&m_data);    // invoke the selected function table
	}
}

/****************************************************************************
* get_option() -
*
* Description : Search the corresponding page fn call 
*             : 
*			  :
* Example     : 
* Input 	  : m_page
* Output	  : N/A
* Modify      : N/A
* Return      : corresponding fn call row (i)
****************************************************************************/
char get_option(char m_page)
{
	char 		i;
	const   struct text *st_ptr;
		
	for (i=0;i<NO_OF_PAGE;i++)			 // search the selected page
	{
	  st_ptr = text_option[i];			 // update selected page
	  if (m_page==st_ptr->mpage)
	  	break;
	}	  	
	return(i);  								    // return the selected page index
}

/****************************************************************************
* root_test_option() -
*
* Description : Root test option fn  
*             : 
*			  :
* Example     : 
* Input 	  : *root_data
* Output	  : N/A
* Modify      : N/A
* Return      : void
****************************************************************************/
void root_test_option(struct menu_ret *root_data)
{
	char	cdata;
	cdata = root_data->option;
	MenuPage=ROOT_PAGE;

  	switch(cdata)
	{ 
		case    '0': root_data->page=ROOT_PAGE; 	//root_test_menu(); 
					 break;
	}
	root_data->redraw = DISABLE;
}


/****************************************************************************
* disp_info() -
*
* Description : Display corresponding page info  
*             : 
*			  :
* Example     : 
* Input 	  : menu_page
* Output	  : N/A
* Modify      : N/A
* Return      : void
****************************************************************************/
void disp_info(char menu_page)
{
	switch (menu_page)
	{
	  case 	ROOT_PAGE	: root_info();	      // root information
	  				  	  	  break;
	}
}

/****************************************************************************
* root_info() -
*
* Description : Root info display 
*             : 
*			        :
* Example     : 
* Input 	    : N/A
* Output	    : N/A
* Modify      : N/A
* Return      : void
****************************************************************************/
void root_info()
{
 	 command_process();					
}


/****************************************************************************
* command_process() -
*
* Description : Update motor position on screen via SCI and LCD display panel
*             : 
* Example     : N/A
* Input 	  : N/A
* Output	  : N/A
* Modify      : N/A
* Return      : void
****************************************************************************/
void command_process()
{
	volatile unsigned long data=0;
	char		i;
    
	  if(PowerFlag==ON)
	  {
	    if(LCDDispCnt++>=200)
	    {
	      LCDDispCnt=0;
/*	      if((DemoIndex[0])>=16) 
          DemoIndex[0]=0;
	   
        if(DemoIndex[0]<=6) {
 	        PORTS|=DRIVE;          // drive "D" LED off
 	        PORTS&=~LOWDRIVE;		  // low drive "L" LED on
        } 
        else if(DemoIndex[0]<16) {
 	        PORTS|=LOWDRIVE;				// low drive "L" LED off
 	        PORTS&=~DRIVE;		      // drive "D" LED on
        }	      
*/
	      if(LCDTestFlag==DISABLE)
	      {
	        if(LCDMileage==TRIPA)
	        {
	          data=(volatile unsigned long)((Mileage));
            DigitA(ON);
            DigitB(OFF);
            DigitTrip(ON);
            DigitODO(OFF);
          }
          else if(LCDMileage==TRIPB)
          {
	          data=(volatile unsigned long)(Mileage);
            DigitA(OFF);
            DigitB(ON);
            DigitTrip(ON);
            DigitODO(OFF);
          }
          else if(LCDMileage==LIFE)
          {
  	        data=(volatile unsigned long)(Mileage);
            DigitA(OFF);
            DigitB(OFF);
            DigitTrip(OFF);
            DigitODO(ON);
			    }
  	     	if(data==0)
  	     	{
  	     	  LCD_disp_km(0);
			      i=LCD_Disp(2, 0);
			      DigitDot(ON);
			      i=LCD_Disp(1, 0);
  	     	}
  	     	else  
  	     	 LCD_disp_km(data);
  	    }
  	    else if((Time8ms-LCDTestTime)>500)  //4sec
  		    LCDTestFlag=DISABLE;
  	  }
	  }
		  
}

/****************************************************************************
* menurx_char0(char menu_page) -
*
* Description : Waiting for rx char and display page information
*			  :
* Example     : N/A  
* Input 	  : menu_page
* Output	  : N/A
* Modify      : N/A
* Return      : char
****************************************************************************/ 
byte menurx_char0(char menu_page)
{ 	
	disp_info(menu_page);		//display corresponding menu info
	  check_motor_demo();
	  if(PowerFlag==DISABLE)
	    return(DISABLE);
	return(0);
}

/****************************************************************************
* disp_str(char *str) -
*
* Description : Transmit string via RS232
*			  :
* Example     : N/A  
* Input 	    : *str
* Output	    : ascii to screen with lf and cr at the end
* Modify      : N/A
* Return      : N/A
****************************************************************************/ 
void disp_str(char *str)
{	
	char cdata;
	
	do
	{
	  cdata=*str++;
	}
	while ((cdata)!='\r');
}

⌨️ 快捷键说明

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