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

📄 menu_operation.c

📁 64输入32输出单片机程序
💻 C
字号:
//---------------------------------------------------------------------------
//	Project Title : Armature resistance tester for stator.
//	  Project No. : 
//	 Project Ver. : 1.00
//	    File Name : MENU_OPERATION.c
//	     Revision : 1.00
//	 Initial Date : 22-Oct,2002
//	  Modify Date : 09-Dec,2003
//	  Description : 
#include <..\atmel\at89s53.h>
#include <dom12a.h>
#include <absacc.h>
#include <stdio.h>

//extern variables
//extern UART_st uart;
extern uUART_protocol uart;
extern uUART_protocol uartIn;

extern struct 	systempara syspara;
extern uchar data keySTAGE[];
//external func.
extern void	 msDelay(unsigned int timer_count);
extern void	 Enable_Timer(char timer_name, unsigned int timer_count);
extern void	 Disable_Timer(char timer_name);
extern uchar STimerStillCounting(uchar idxStimer);

extern char _uart_command (unsigned char cmdcode);
extern char _uart_reply (void);

extern void _lcdCursorGoto(char r, char c);

uchar Menu_Operation(void);
uchar Display_menu_bar(uchar itemindex);
uchar EEPROM_WRITE(uint address, uint txINT);
uchar EEPROM_READ(uint address, uint *rxINT);
uchar Update_setting(uint *setting, char *pStr, uint UL, uint LL, uchar decplaces);
uchar Display_new_setting(uint newval, uchar decplaces);
void  Get_sys_para(void);

//*******************************************************
uchar Menu_Operation(void)
{
  uchar menuitem = 0;
  uchar retcode;

/*
			uchar totalCoils;
			uchar startBar;
			uint  totalTested;
			uint  totalPassed;
			uint  totalFailed;
			uint  UL;
			uint  LL;
			uint  average;
			uint  max;
			uint  min;
			uchar keylocking;
			uchar FixtureCtrlMode;
*/
  _lcdCursorGoto(1, 0);
  printf("Tester config:            ");
  _lcdCursorGoto(1, 0);
  printf("                          ");
  Display_menu_bar(menuitem);
  while (1) {
		if ( keySTAGE[pbF4] == 4 ) {
				menuitem = 1 - menuitem;
				Display_menu_bar(menuitem);
				keySTAGE[pbF4] = 0;
		} // end if
		
		if ( menuitem == 1 && keySTAGE[pbF3] == 4 ) {
			 keySTAGE[pbF3] = 0;
			 _lcdCursorGoto(1, 0);
			 printf("                       ");
			 _lcdCursorGoto(2, 0);
			 printf("                       ");
			 _lcdCursorGoto(3, 0);
			 printf("Exit menu...                  ");
			 msDelay(400);
			 _lcdCursorGoto(3,22);
  			 printf("F3:MENU    F4:TEST");
			 return(0);
		} // end if

	    if ( menuitem ) {
			if ( keySTAGE[pbF1] == 4) {
				keySTAGE[pbF1] = 0;
				retcode = Update_setting(&syspara.totalCoils, "TBar=", 24, 3, 0);
				Display_menu_bar(menuitem);
				if ( !retcode) {
					EEPROM_WRITE(eeprCoil, syspara.totalCoils);
					msDelay(100);

					uart.st.uiParam2 = syspara.totalCoils;
					uart.st.uiParam1 = syspara.startBar;
    				_uart_command(UART_CONFIG_SLOT);
				} // end if
			} else if ( keySTAGE[pbF2] == 4) {
				keySTAGE[pbF2] = 0;
				retcode = Update_setting(&syspara.startBar, "SBar=", 22, 1, 0);
				Display_menu_bar(menuitem);
				if ( !retcode) {
					EEPROM_WRITE(eeprStartBar, syspara.startBar);
					msDelay(100);
					uart.st.uiParam2 = syspara.totalCoils;
					uart.st.uiParam1 = syspara.startBar;
    				_uart_command(UART_CONFIG_SLOT);
				} // end if 
			} 

		} else {
			if ( keySTAGE[pbF1] == 4) {
				keySTAGE[pbF1] = 0;
				retcode = Update_setting(&syspara.UL, "UL = ", 20000, 1, 2);
				Display_menu_bar(menuitem);
				if ( !retcode)
					EEPROM_WRITE(eeprUL, syspara.UL);
			} else if ( keySTAGE[pbF2] == 4) {
				keySTAGE[pbF2] = 0;
				retcode = Update_setting(&syspara.LL, "LL = ", 20000, 1, 2);
				Display_menu_bar(menuitem);
				if ( !retcode)
					EEPROM_WRITE(eeprLL, syspara.LL);
			} else if ( keySTAGE[pbF3] == 4) {
				keySTAGE[pbF3] = 0;
				retcode = Update_setting( &syspara.FixtureCtrlMode, "Mod: ", 1, 0, 0);
				Display_menu_bar(menuitem);
				if (!retcode) {
					_lcdCursorGoto(0,21);
  					printf("Mode%u", syspara.FixtureCtrlMode);
					EEPROM_WRITE(eeprMode, syspara.FixtureCtrlMode);
				} // end if
			}  // end else
		} // end else
  } // end while  

} // end func.

//***********************************************************
uchar Update_setting(uint *setting, char *pStr, uint UL, uint LL, uchar decplaces)
{
  uint  val = *setting;
  uchar pbUpStage = 0;
  uchar pbDnStage = 0;
  uchar arrowkeypressed;
  uint  incvalue;
  
  _lcdCursorGoto(2,0);
  printf("%s   ", pStr);
  Display_new_setting(val, decplaces);		
  _lcdCursorGoto(3,0);
  printf("F1:UP     F2:DN     F3:Cancel    F4:Save");

  while (1) {
	 if ( keySTAGE[pbF3] == 4) {
			keySTAGE[pbF3] = 0;
			_lcdCursorGoto(3,0);
			printf("Cancel setup...\n");
			msDelay(1000);
			_lcdCursorGoto(2,0);
			printf("                       ");
			return (0x01);
	 } else if ( keySTAGE[pbF4] == 4) {
			keySTAGE[pbF4] = 0;
			_lcdCursorGoto(3,0);
			printf("New setup confirmed...\n");
			msDelay(1000);
			_lcdCursorGoto(2,0);
			printf("                       ");
			*setting = val;
			return (0x00); 
	 } // end if

    if ( keySTAGE[pbF1] == 4 ) { // pressing UP
		keySTAGE[pbF1] = 0;
		pbUpStage = 0; 
		if ( val < UL )
			Display_new_setting(++val, decplaces);	
    } else if ( keySTAGE[pbF1] == 2 ) { // continous pressing
		 switch ( pbUpStage ) {
			case 0: Enable_Timer(1, 1500);
					pbUpStage = 1; 
					arrowkeypressed = 1;
					break;
		 	case 1: if ( !STimerStillCounting(1) ) {
						incvalue = 5;
						val += incvalue;
						if ( val > UL)
							val = UL;

						Enable_Timer(1, 750);
						pbUpStage = 2; 
						Display_new_setting(val, decplaces);					
					} // end if
					break;
			case 2: if ( !STimerStillCounting(1) ) {
						if ( incvalue < 50)
							incvalue += 2;

						val += incvalue;
						if ( val > UL)
							val = UL;
						
						Enable_Timer(1, 250);
						Display_new_setting(val, decplaces);	
					} // end if
					break;
			default:pbUpStage = 0;
		  } // end switch
	  } // end if

	if ( keySTAGE[pbF2] == 4 ) { // pressing DN
		keySTAGE[pbF2] = 0;
		pbDnStage = 0; 
		if ( val > LL )
			Display_new_setting(--val, decplaces);
    } else if ( keySTAGE[pbF2] == 2 ) { // continous pressing
		 switch ( pbDnStage ) {
			case 0: Enable_Timer(1, 1500);
					pbDnStage = 1; 
					arrowkeypressed = 1;
					break;
		 	case 1: if ( !STimerStillCounting(1) ) {
						incvalue = 5;
						if ( val > LL + incvalue)
							val -= 5;
						else
							val = 0;
						Enable_Timer(1, 750);
						pbDnStage = 2; 
						Display_new_setting(val, decplaces);					
					} // end if
					break;
			case 2: if ( !STimerStillCounting(1) ) {
						if ( incvalue < 50)
							incvalue += 2;
						if ( val > LL + incvalue)
							val -=  incvalue;
						else
							val = 0;
						Enable_Timer(1, 250);
						Display_new_setting(val, decplaces);	
					} // end if
					break;
			default:pbUpStage = 0;
		  } // end switch
	  } // end if

  } // end while

  return (0);
} // end func.

//***********************************************************
uchar Display_new_setting(uint newval, uchar decplaces)
{
  _lcdCursorGoto(2,5);
  switch ( decplaces ) {
	case 0: printf("%u   ", newval);
			break;
    case 1: printf("%3u.%01u", newval / 10, newval % 10);
			break;
	case 2: printf("%3u.%02u", newval / 100, newval % 100);
			break;
  } // end switch
  return (0);
} // end func.


//***********************************************************
uchar Display_menu_bar(uchar itemindex)
{
  char code menuitem[][35] = {
						"F1:UL    F2:LL      F3:Mode   ",
						"F1:TBars F2:S.Bars  F3:Exit   "};
 
  _lcdCursorGoto(3, 0);
  if ( itemindex >= 2 )
		return ( 0x01);

  printf("%s", menuitem[itemindex]);
  _lcdCursorGoto(3, 33);
  printf("F4:Next");

} // end func.


//*********************************************************************
uchar EEPROM_READ(uint address, uint *rxINT)
{
  uchar pass = True;

  msDelay(100);
  Enable_Timer(2, 1000);  

  uart.st.uiParam1 = address;
  Enable_Timer(2, 1000);  
  _uart_command(UART_EEPR_R_INT);
  while ( !_uart_reply() )
		if ( !STimerStillCounting(2) ) {
			pass = False;
			break;
		} // end if
  *rxINT = uartIn.st.uiParam2;
  return( uartIn.st.uiParam1);
} // end func.

//*********************************************************************
uchar EEPROM_WRITE(uint address, uint txINT)
{
  uchar pass = True;

  Enable_Timer(2, 1000);  
  uart.st.uiParam1 = address;
  uart.st.uiParam2 = txINT;
  _uart_command(UART_EEPR_W_INT);
  while ( !_uart_reply() )
		if ( !STimerStillCounting(2) ) {
			pass = False;
			break;
		} // end if
  return(uartIn.st.uiParam2);
} // end func

//*******************************************************************
void Get_sys_para(void)
{
  uint para;

  EEPROM_READ(eeprCoil, &para);
  if ( para > 24)
		syspara.totalCoils = 3;
  else
		syspara.totalCoils = para;

  EEPROM_READ(eeprStartBar, &para);
  if ( para > 24)
		syspara.startBar = 11;
  else
		syspara.startBar = para;
  
  EEPROM_READ(eeprUL, &para);
  if ( para > 20000)
		syspara.UL = 20000;
  else
		syspara.UL = para;

  EEPROM_READ(eeprLL, &para);
  if ( para > syspara.UL)
		syspara.LL = 0;
  else
		syspara.LL = para;

  EEPROM_READ(eeprMode, &para);
  if ( para > 1)
		syspara.FixtureCtrlMode = 0;
  else
		syspara.FixtureCtrlMode = para;		

} // end func.

⌨️ 快捷键说明

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