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

📄 dom12a_8253v1.c

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

#define debug_uart
 	
sbit    PIN_5            = P1^3;
sbit    EXTOUT_EN        = P3^5;

//------------------------------------------------------------
extern uchar data keySTAGE[];
extern uUART_protocol uart, uartIn;

// extern func.
extern void	 Init_Sys_Timer(void);
extern void	 Enable_Timer(char timer_name, unsigned int timer_count);
extern void	 Disable_Timer(char timer_name);
extern void	 msDelay(unsigned int timer_count);
extern uchar STimerStillCounting(uchar idxStimer);
extern void  Mask_Key_Detect(uchar flagClear_nDisable, uchar keyMask);

extern void _initial_disp (void);
extern void _clear_disp (void);
extern void _lcdCursor_FlashToggling (char stFlashing);
extern void _lcdCursorGoto(char r, char c);

extern uchar Menu_Operation(void);
extern void  Get_sys_para(void);

extern char _get_panelsw (char f);
extern char _set_extoutp (char f, char s);
extern char _get_extinp (char f);

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

extern uchar start_Fixture_control(uchar FCM);
extern uchar Fixture_Sequence_Control(uchar flagPass, uchar FCM);

unsigned char outbuf;
unsigned char test_end;
unsigned int  uns16b;
unsigned long uns32b;
struct 	systempara syspara;

unsigned char xdata eeprom _at_ 0x0000;
//---------------------------------------------------------------------------

//Functions prototype
char   _initial_system (void);
void   Error_Handler(uchar errorcode);
void   _disp_screen(void);
uchar  Display_Result(void);
uchar  Armature_Resistance_Test(void);

//global variables
uint resis[24];

//*********************************************************************
void main (void)
{
   uchar retcode, i;
   uchar flagPass;

    Init_Sys_Timer();
	msDelay(100);		//delay for 0.5s

	_initial_disp();
    msDelay(200);
	_lcdCursorGoto(0,0);
	_lcdCursor_FlashToggling (notFlashing);
    printf(" Johnson Electric Industrial Mfty. LTD.\n");
    printf("    DOM-12A Armature resistance tester\n\n");
    printf("    rev.: 1.0 1st release for product.");

	msDelay(150);		//15s
	_uart_initial();  
	_initial_system();
	msDelay(200);
    syspara.totalTested = 0;
	syspara.totalPassed = 0;
	syspara.totalFailed = 0;

	_set_extoutp(EXT_OUTP0,ON);		//Top pis
	_set_extoutp(EXT_OUTP0,OFF);	//Top pis
	_set_extoutp(EXT_OUTP1,ON);	//Top pis
	_set_extoutp(EXT_OUTP1,OFF);	//Top pis

	for (i=0; i<10; i++)
		uartIn.sbuf[i] = 0;
    msDelay(200);

    Get_sys_para();
	//-------------------------------------------------------
	Enable_Timer(2, 1000);
	_lcdCursorGoto(3,0);
	printf("Setup total coils, start bar...\n");

    uart.st.uiParam2 = syspara.totalCoils;
	uart.st.uiParam1 = syspara.startBar;
    _uart_command(UART_CONFIG_SLOT);

	_lcdCursorGoto(3,0);
    while ( !_uart_reply() )
		if ( !STimerStillCounting(2) )
			break;
	if ( !STimerStillCounting(2) ) {    
		printf("Uart error: cannot setup coil#\n");
		_set_extoutp(BUZZER, ON);
		Disable_Timer(2);
		Disable_Uart();
		msDelay(2000);	
	} else if ( uartIn.st.uiParam2 != syspara.totalCoils ||
				uartIn.st.uiParam1 != syspara.startBar ) {
		printf("Uart error: incorrect data rx.\n");
		_set_extoutp(BUZZER, ON);
		Disable_Timer(2);
		Disable_Uart();
		msDelay(2000);	
	} // end if
    _lcdCursorGoto(3,0);
	printf("Completed!\n");

	msDelay(2000);
 	_disp_screen();
	syspara.keylocking = _get_panelsw(LOCK_KEY);
	_lcdCursorGoto(0,27);
    if (syspara.keylocking) {
		printf("LK");
		Mask_Key_Detect(flagKeyDet_nDisable, mask_pbMENU );
	} else {
		printf("UL");
		Mask_Key_Detect(flagKeyDetClear, mask_pbMENU );
	} // end else
	//----------------------------------------------------------
	while (1) {
		if ( _get_panelsw(LOCK_KEY) ) {  //being locked
			if ( !syspara.keylocking) {
				Mask_Key_Detect(flagKeyDet_nDisable, mask_pbMENU );
				syspara.keylocking = True;
				_lcdCursorGoto(0,27);
				printf("LK");
			} // end if
		} else {	// no locking
			if ( syspara.keylocking ) { // detect if keylock
				Mask_Key_Detect(flagKeyDetClear, mask_pbMENU );
				_lcdCursorGoto(0,27);
				printf("UL");
				syspara.keylocking = False;
  			} // end if
			
			//msDelay(200);
            //_set_extoutp(FAIL_LAMP,OFF);
            //_set_extoutp(BUZZER,OFF);
            //_set_extoutp(EXT_OUTP0,OFF);
        } // end if

		//--------------------------------------------------------
        if ( keySTAGE[pbTEST] == 4 || !_get_extinp(START_SW) ) {  
			//Conduct resistance measurement & display result
			keySTAGE[pbTEST] = 0; 
			start_Fixture_control(syspara.FixtureCtrlMode);
            _set_extoutp(FAIL_LAMP,OFF);
            _set_extoutp(PASS_LAMP,OFF);
            _set_extoutp(BUZZER,OFF);
            
			retcode = Armature_Resistance_Test();
			if ( !retcode ) {
				flagPass = Display_Result();
				// control the sequence of fixture according to mode:x
				//_set_extoutp(EXT_OUTP0,OFF);
				if ( !flagPass )
					_set_extoutp(BUZZER,ON);
				Fixture_Sequence_Control(flagPass, syspara.FixtureCtrlMode);
			} else {
				_set_extoutp(BUZZER,ON);
				Error_Handler( retcode);
			} // end else	

	    	_set_extoutp(BUZZER,OFF);
			_lcdCursorGoto(3,22);
  			printf("F3:MENU    F4:TEST");
			_lcdCursorGoto(0, 15);
			printf("Stdy");
			_lcdCursor_FlashToggling (notFlashing);
        } // end if

		//------------------------------------------------------	
		if ( !syspara.keylocking && keySTAGE[pbMENU] == 4 ) { // MENU Operation  
			keySTAGE[pbMENU] = 0;
			Mask_Key_Detect(flagKeyDetClear, mask_pbF1 | mask_pbF2 );
            Menu_Operation();
            test_end = FALSE;
			Mask_Key_Detect(flagKeyDet_nDisable, mask_pbF1 | mask_pbF2 );
		} // end if

	} // end while
}

//****************************************************************
uchar Display_Result(void)
{
  uchar i;
  uchar flagPass = True;
  uint  res;
  unsigned long average = 0;
  uint  max, min;

  _lcdCursor_FlashToggling (notFlashing);	
  max = 0; min = 65000;
  for(i=0; i< syspara.totalCoils; i++) { 
		res = resis[i];
    	if ( res > syspara.UL || res < syspara.LL )
			flagPass = False;
		average += (unsigned long) res;
		if ( res > max )
			max = res;
		if ( res < min )
			min = res;
  } // end for

  syspara.max = max; syspara.min = min;
  syspara.average = (uint) (average / syspara.totalCoils);
  _lcdCursorGoto(0, 35);
  printf("%5u", ++syspara.totalTested);
  _lcdCursorGoto(1, 11);
  if ( flagPass ) {  
	 printf("Passed   ");
	 _lcdCursorGoto(1, 35);
	 printf("%5u", ++syspara.totalPassed);
      _set_extoutp(PASS_LAMP,ON);//cdf

  } else {
	 printf("Failed!  ");
	 _lcdCursorGoto(2, 35);
	 printf("%5u", ++syspara.totalFailed);
	 _set_extoutp(BUZZER,ON); 
     _set_extoutp(FAIL_LAMP,ON);//cdf
	 flagPass = False;
  } // end if
  _lcdCursorGoto(3, 0);
  printf("Avg:%3u.%02u      ", syspara.average / 100, syspara.average %100);
  _lcdCursorGoto(2, 0);
  printf("max:%3u.%02u, ", max / 100, max %100);
  printf("min:%3u.%02u      ", min / 100, min %100);
  return ( flagPass );
} // end func.

//---------------------------------------------------------------------------
char _initial_system (void)
{	
  unsigned int xdata *ptr;
  unsigned int i;
  uchar flagTimeOut = False;

  for (i = 0x9000; i != 0; i++)	{	
		ptr = i;
        *ptr = 0x00;
  } // end for

  msDelay(500);
  Out_Port = 0;
    EXTOUT_EN = 0;
    _set_extoutp(PASS_LAMP,OFF);
    _set_extoutp(FAIL_LAMP,OFF);
    _set_extoutp(BUZZER,OFF);
    _lcdCursorGoto(3, 0);
	printf("Uart commu. test...     \n");
	msDelay(500);
    //----------------------------------------------------------
	msDelay(100);
	Enable_Timer(2, 1000);
	for (i=0; i<10; i++) {
		uart.sbuf[i] = i;
		uartIn.sbuf[i] = 0;
	} // end for
	_uart_command(UART_TEST);
    
	while ( !_uart_reply() )
		if ( !STimerStillCounting(2) ) {
			flagTimeOut = True;
			break;
		} // end if		
	if ( flagTimeOut ) {
		Disable_Timer(2);
		Disable_Uart();
		Error_Handler(0x04);
		_set_extoutp(BUZZER,ON);
		msDelay(3000);
    } // end if

    _set_extoutp(PASS_LAMP,OFF);
    _set_extoutp(FAIL_LAMP,OFF);
    _set_extoutp(BUZZER,OFF);
       
    if (uartIn.sbuf[0] == 'O' && uartIn.sbuf[1] == 'K') {
		_lcdCursorGoto(3, 19);
		printf("Pass!");
    } else {
		Error_Handler(0x01);
		Disable_Uart();
        _set_extoutp(PASS_LAMP,OFF);
        _set_extoutp(FAIL_LAMP,ON);
        _set_extoutp(BUZZER,ON);
        msDelay(3000);
    } // end else
	return TRUE;
}

//---------------------------------------------------------------------------
void _disp_screen(void)
{
  Mask_Key_Detect(flagKeyDetClear,   mask_pbTEST | mask_pbMENU);
  Mask_Key_Detect(flagKeyDet_nDisable, mask_pbF1 | mask_pbF2);
  _clear_disp();
  _lcdCursor_FlashToggling (notFlashing);
  _lcdCursorGoto(0,0);
  printf("Model:DOM-12A");
  _lcdCursorGoto(0,15);
  printf("Stdy");

  _lcdCursorGoto(0,21);
  printf("Mode%u", syspara.FixtureCtrlMode);
  _lcdCursorGoto(0,30);
  printf("Ttl :%5u", syspara.totalTested);
  _lcdCursorGoto(1,30);
  printf("Pass:%5u", syspara.totalPassed);
  _lcdCursorGoto(2,30);
  printf("Fail:%5u", syspara.totalFailed);
  
  _lcdCursorGoto(3,22);
  printf("F3:MENU    F4:TEST");
} // end func.

//**********************************************************************
void Error_Handler(uchar errorcode)
{
  _lcdCursorGoto(2,0);
  switch(errorcode) {
	case 0x01:printf("Err0x01:Uart send timeout!");
			  break;
	case 0x02:printf("Err0x02:Uart wrong commu.!");
			  break;
	case 0x04:printf("Err0x04:Uart init. timeout!");
			  break;
  } // end switch
} // end func.

//*********************************************************************
uchar Armature_Resistance_Test(void)
{
  uchar i, idxBar, flagTimeOut;
  uint  resistance;

  _lcdCursorGoto(0, 15);
  printf("Run ");
  _lcdCursorGoto(1, 0);
  printf("Testing...             ");
  _lcdCursor_FlashToggling (onFlashing);
		
  idxBar = syspara.startBar;
  _lcdCursorGoto(2, 0);
  printf("Slot#                    ");
  _lcdCursorGoto(3, 0);
  printf("Res :                    ");

  for (i=0; i< syspara.totalCoils; i++) {
		uart.st.uiParam1 = (uint) idxBar++;
		_uart_command(UART_Bar2Bar_Test);
		Enable_Timer(2, 1000); 
		flagTimeOut = False; 
		while ( !_uart_reply() )
			if ( !STimerStillCounting(2) ) {
				flagTimeOut = True;
				break;
			} // end if

		if ( flagTimeOut ) {
			Disable_Timer(2); 
			Disable_Uart();
			return ( 0x01);
		} else {
			resistance = uartIn.st.uiParam1;
			//((unsigned char *)&resistance)[0] = uartIn.sbuf[0];
			//((unsigned char *)&resistance)[1] = uartIn.sbuf[1];
			resis[i] = resistance; // unit in 0.01 ohm
			_lcdCursorGoto(2, 4);
			printf("%2bu     ", idxBar);
			_lcdCursorGoto(3, 4);
			printf("%4u.%02u       ", resistance / 100, resistance % 100);
		} // end else
		msDelay(200);
	} // end for	
	Disable_Timer(2); 
	return (0);
} // end func.

⌨️ 快捷键说明

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