Example #1
0
void LCDWrite(uint8_t data,uint8_t rs) 
{
	/** rs = 0 instruction else data */
    if (rs)    
    	LCD_RS_PORT = 1; /** DATA */
    else     
    	LCD_RS_PORT = 0;  /** INSTRUCTION */

    
    /** 4 MSB bits */

	if(data & 0x80) LCD_DATA3_PORT = 1;
	if(data & 0x40) LCD_DATA2_PORT = 1;
	if(data & 0x20) LCD_DATA1_PORT = 1;
	if(data & 0x10) LCD_DATA0_PORT = 1 ;
    toggleE();
    
    Cpu_Delay100US(10);
	LCD_DATA0_PORT = 0;
	LCD_DATA1_PORT = 0;
	LCD_DATA2_PORT = 0;
	LCD_DATA3_PORT = 0;
    /** 4 LSB bits */
	if(data & 0x08) LCD_DATA3_PORT = 1;
	if(data & 0x04) LCD_DATA2_PORT = 1;
	if(data & 0x02) LCD_DATA1_PORT = 1;
	if(data & 0x01) LCD_DATA0_PORT = 1;
    toggleE();       
    Cpu_Delay100US(10);

	LCD_DATA0_PORT = 0;
	LCD_DATA1_PORT = 0;
	LCD_DATA2_PORT = 0;
	LCD_DATA3_PORT = 0;
}
Example #2
0
void toggleE()
{
	Cpu_Delay100US(1);
	LCD_E_PORT = 1;
	Cpu_Delay100US(1);
	LCD_E_PORT = 0;
}
Example #3
0
void LED_BrillarV(int a, word b){
    int i;
    for(i=0 ; i < a ; i++){
        LED_PrenderV();
        Cpu_Delay100US(b);
        LED_ApagarV();
        Cpu_Delay100US(b);
    }
}
Example #4
0
/******************************************************************************
 * Function:        void Check_USBBus_Status(void)
 * Input:           None
 * Output:          None
 * Overview:        This function can be used to detect if the USB bus has attached
 *                  on USB bus, we can use a GPIO, or KBI interrupt, it is disable here
 *
 *****************************************************************************/
void Check_USBBus_Status(void)
{
  if(CTL_USBEN == 0)                     /* module off ? */
  {
    EPCTL0 = 0x0D;
    INTSTAT = 0xBF;
    CTL = 0x00;
    INTENB = 0x00;                      /* disable USB interrupt*/
    CTL_USBEN = 0x01;                   /* enable module */
    USBCTL0 = UCFG_VAL;                 /* attach to USB bus*/

    Usb_Device_State = ATTACHED_STATE;      
  }

  if(Usb_Device_State == ATTACHED_STATE)
  {
    INTSTAT = 0xBF;                        /*clear USB interrupts*/
    INTENB = 0xBF; 
    Cpu_Delay100US(10000);                           
  }


  if(Usb_Device_State == USB_ENTER_SUSPEND)
  {
    USB_Suspend();
  }
}
Example #5
0
void main(void)
{
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  nLoop = 0; 
  SCIcount=0;
  AD1_Start();
  Puls1_Enable();
  Puls2_Enable();
  TI1_DisableEvent();
  Cpu_Delay100US(10000);
  
  if(!AD_Flag)
  {
        calibrateSensor();
        TI1_EnableEvent();
        AD_Flag = 1;
  }
 
  //----------------------------------------------------------------
  for(;;) 
  {   
    nLoop ++;
    if(nLoop >= LOOP_TIME) 	     
      nLoop = 0;
    else 
      continue;
    
   //----------------------------------------------------------------	
    if((g_fGyroscopeAngleIntegral < 50.0) && (g_fGyroscopeAngleIntegral > -50.0))    //ж╠а╒еп╤о
        standFlag = 1;
    else if((g_fGyroscopeAngleIntegral >= 50.0) || (g_fGyroscopeAngleIntegral <= -50.0))
        standFlag = 0;
      
    //----------------------------------------------------------------
    Cpu_Delay100US(100);

    if(UartFlag == 1)
    {
      sendData();          
      UartFlag = 0; 
    } 
    receiveData();
  }
}
Example #6
0
void delay_ms(U16 period)   //delay routine (milliseconds)
{
  
  while (period != 0)
  {
    Cpu_Delay100US (10);          
    period--;    
  }  
}
Example #7
0
void HopperScanID(void){
	
	uint8_t i=0,j=0;
	
	CleanBufferInput();
	cctalk.FlagReceiveData=0;
	for(i=3,j=0;i<20;i++){
		if(HopperSimplePoll(i)){
			cctalk.HopperAddress[j]=i;
			j++;
		}
		Cpu_Delay100US(500);
		cctalk.FlagReceiveData=0;
	}
	Cpu_Delay100US(100);
	//i=0;
	if(cctalk.HopperAddress[0]){		
		
		CleanBufferInput();
		cctalk.FlagReceiveData=0;
		cctalk.Hopper1FlagStatus = DEVICE_OK;
		(void)HopperReqSerialNumber(cctalk.HopperAddress[0],cctalk.Hopper1SerialNumber);
				
	}
	
	if(cctalk.HopperAddress[1]){		
			
		CleanBufferInput();
		cctalk.FlagReceiveData=0;
		cctalk.Hopper2FlagStatus = DEVICE_OK;
		(void)HopperReqSerialNumber(cctalk.HopperAddress[1],cctalk.Hopper2SerialNumber);
				
	}
	
	if(cctalk.HopperAddress[2]){		
				
		CleanBufferInput();
		cctalk.FlagReceiveData=0;
		cctalk.Hopper3FlagStatus = DEVICE_OK;
		(void)HopperReqSerialNumber(cctalk.HopperAddress[2],cctalk.Hopper3SerialNumber);
				
	}
	
}
Example #8
0
  void D4DLCD_Delay_ms_Common(unsigned short period)   //delay routine (milliseconds)
  {

    #ifdef MQX_CPU
    	_time_delay(period);
    #else

	    while (period != 0)
	    {
	        	Cpu_Delay100US (10);
	        period--;
	    }
    #endif

  }
Example #9
0
void LCDWriteChar(uint8_t data)
{
	/*
	if (data=='\n') 
	{
		if (g_nCurrentLine >= LCD_LINES - 1)
			lcd_setline(0);
		else
			lcd_setline(g_nCurrentLine+1);
	}
	else
	*/
	LCDWrite(data,1);
	Cpu_Delay100US(20);
}
Example #10
0
error SD_Escribir(byte *direccion, dato buf[][tam_dato]){
	UINT32 u32SD_Block; // Convertimos la direccion en una variable de 32 bits
    byte tem;
    
    SPI_Init();
    u32SD_Block = direccion[0];
    u32SD_Block <<= 8;
    u32SD_Block |= direccion[1];
    u32SD_Block <<= 8;
    u32SD_Block |= direccion[2];
    u32SD_Block <<= 8;
    u32SD_Block |= direccion[3];
    
    tem = SD_WriteSector(u32SD_Block, (UINT8 *) buf);
    
    (void)Cpu_Delay100US(100);
    ban_SDvacia=0;
    return _ERR_OK;
}
Example #11
0
void LCDInitialize()
{
	/** Set data direction on all pins to output */
	LCD_DATA0_DD = 1;
	LCD_DATA1_DD = 1;
	LCD_DATA2_DD = 1;
	LCD_DATA3_DD = 1;
	LCD_RS_DD = 1;	
	LCD_E_DD = 1;

	/** Delay for LCD to power up */
	Cpu_Delay100US(160);
	
	/** Set RS LOW */
	LCD_RS_PORT = 0;
	LCD_E_PORT = 0;

	/** Set output to 0x3*/
	LCDCommand(0x3);
	
	/** 5 ms wait */
	Cpu_Delay100US(50);
	/** Set output to 0x3 again*/
	LCDCommand(0x3);
	Cpu_Delay100US(50);
	LCDCommand(0x3);
	
	Cpu_Delay100US(2);
	
	/** Write 0x2 enable 4 bit mode*/
	LCDCommand(0x2);
	Cpu_Delay100US(20);
	
	/** Set to 4 bit mode, 2 lines */
	LCDCommand(0x28);
	Cpu_Delay100US(20);
	
	LCDCommand(0x8);
	
	LCDCommand(0x01);
	Cpu_Delay100US(20);
	
	LCDCommand(0x0C);
	
}
Example #12
0
error SD_Leer(byte *direccion, dato lectura[][tam_dato]){
    UINT32 u32SD_Block; // Convertimos la direccion en una variable de 32 bits
	
	SPI_Init();
	u32SD_Block = direccion[0];
	u32SD_Block <<= 8;
	u32SD_Block |= direccion[1];
	u32SD_Block <<= 8;
	u32SD_Block |= direccion[2];
	u32SD_Block <<= 8;
	u32SD_Block |= direccion[3];
    
    (void) SD_CalculaDireccion(dir_lectura, lectura);
    (void) SD_ReadSector(u32SD_Block,(UINT8 *) lectura);
    (void)Cpu_Delay100US(100); 
    //ban_bufferTx=0;
        
    return _ERR_OK;

}
Example #13
0
void main(void)
{
  /* Write your local variable definition here */

  long t=sizeof(byte*);
  ++t;
  --t;
  ++g;
  --g;
  g=t;
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  AS1_SendChar('a');
  for(;1;){AS1_SendChar('a');Cpu_Delay100US(1000);  }
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/*****************************************************************************
* void main(void)
*
* Main application.
*
* In:  n/a
*
* Out: n/a
*****************************************************************************/
void main(void)
{
  UInt16 state;
  char *temp_ptr;
  extern word _vba;
  uint8_t sw0, sw1;
  
  
  INTC_VBA = ((word)&_vba) >> (21-INTC_VBA_BITS);			   /* Set Vector Base Address */
  
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
    
    /*StartDelay = pmem_read((unsigned int *)BOOT_START_DELAY_PLACE) & 0x00FF;
    if(!StartDelay)  bootExit();
    else bootTimerInit();*/ 
   
    /* Write your code here */

   GPIO_A_PER &= ~GPIO_A_PER_PE0_MASK; // set to GPIO mode
   GPIO_A_PER &= ~GPIO_A_PER_PE1_MASK;
   GPIO_A_DDR |= GPIO_A_DDR_DD0_MASK;  // set as output
   GPIO_A_DDR |= GPIO_A_DDR_DD1_MASK;
   GPIO_A_DR &= ~GPIO_A_DR_D0_MASK;  // set low
   GPIO_A_DR &= ~GPIO_A_DR_D1_MASK; 			
			    
    Cpu_Delay100US(5000); // power-up delay
  
   // Initialize R0,R1,M01, and N for circular buffer (including shadows)
   asm {
        swap shadows                    ;// Switch to shadow registers
        moveu.w #(RX_DATA_SIZE-1),M01   ;// Set buffer size
        moveu.w #rx_data,R0             ;// Set starting address
        moveu.w #QSCI_STAT,R1           ;// Use R1 for SCI status register
        moveu.w #0,N                    ;// N is unused
        swap shadows                    ;// Switch back to normal registers
   }

		// with DEFCON 17, we used a timer to keep the badge in bootloader mode on power up for 10 seconds
		// for DEFCON 18, the bootloader mode is only enabled if both buttons are held down on power up
		// otherwise it jumps directly to the user application. no timer necessary, so that code is commented out
		
		// check buttons
   GPIO_C_PUR |= GPIO_C_PUR_PU0_MASK; // enable pull-up
   GPIO_C_PUR |= GPIO_C_PUR_PU1_MASK;   
   GPIO_C_DDR &= ~GPIO_C_DDR_DD0_MASK; // set as input
   GPIO_C_DDR &= ~GPIO_C_DDR_DD1_MASK;
   GPIO_C_PER &= ~GPIO_C_PER_PE0_MASK; // set to GPIO mode
   GPIO_C_PER &= ~GPIO_C_PER_PE1_MASK;
   Cpu_Delay100US(1000); // setup delay
   
   #define SW0_PIN_MASK       ((byte)1) /* Pin mask */
   #define SW1_PIN_MASK       ((byte)2) /* Pin mask */
	 sw0 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW0_PIN_MASK)));
   sw1 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW1_PIN_MASK)));

   if (sw0 || sw1) // one or more buttons has been pressed
	 {
		 Cpu_Delay100US(1000); 	// give the user time to press both buttons (also serves as 100mS debounce)

	 	 sw0 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW0_PIN_MASK)));
     sw1 = !((bool)(getRegBits(GPIO_C_RAWDATA,SW1_PIN_MASK)));
	 }
	
   if (sw0 && sw1) // if both buttons have been pressed, enter bootloader
   {
     // Turn on LEDs so the user knows we're here
     GPIO_A_DR |= GPIO_A_DR_D0_MASK;  // set high
   	 GPIO_A_DR |= GPIO_A_DR_D1_MASK;  
   
	   // Initialize globals
	   mem_init(rx_data, NULL, RX_DATA_SIZE);
	   data_out = data_in = rx_data; 
	   
	   state = INITIAL_STATE;
	   temp_ptr = rx_data;

	   // Disable protection
	   setReg(FM_PROT,BOOT_PROT_VALUE);

	   // Output banner
	   sci_tx(&StrCopyright[0]);
	   
	   // Now it is safe to enable interrupts
	   Cpu_EnableInt();

	   do  {
	      // State: Initial State
	      if (state == INITIAL_STATE) {
	         status = 0;
	         sci_tx(&StrWaitingSrec[0]);
	         sci_tx_char(XON);
	         state = WAIT_FOR_S;
	      }

	      if (data_in != temp_ptr) {
	         //Timer_Disable();

	         // State: Wait for Header "S"
	         if (state == WAIT_FOR_S) {
	            temp_ptr = data_out;
	            if (get_char(&temp_ptr) == 'S') { state = WAIT_FOR_0; }
	            else { get_char(&data_out); }
	         }
	         // State: Wait for Header "0"
	         else if (state == WAIT_FOR_0) {
	            if (get_char(&temp_ptr) == '0') { state = WAIT_FOR_EOL; }
	            else {
	               get_char(&data_out);
	               state = WAIT_FOR_S;
	            }
	         }
	         // State: Wait for EOL
	         else if (state == WAIT_FOR_EOL) {
	            if (get_char(&temp_ptr) == '\r') {
	               if (!(status & TX_XOFF)) {
	                  sci_tx_char(XOFF);
	                  status |= TX_XOFF;
	               }
	               srec_decode();
	               temp_ptr = data_out;
	            }
	         }
	      }
	      else {
	         if (status & TX_XOFF) {
	            sci_tx_char(XON);
	            status &= ~TX_XOFF;
	         }
	      }
	      // State: Error
	      if (status & DOWNLOAD_ERROR) {
	         sci_tx(StrErr);
	         sci_tx(int_to_string(status));
	         state = INITIAL_STATE;
	         sci_tx(StrNewLine);
	      }
	      
	      //bootTimerCheck();
	      
	   } while (status != DOWNLOAD_OK);
	   
	   sci_tx(StrNewLine); 
	   sci_tx(&StrLoaded[0]);
   }
   
   bootExit();
}
Example #15
0
void LCDHome()
{
   	LCDWrite(1, 0);
   	Cpu_Delay100US(5);
}
Example #16
0
void LCDClear()
{
	
   	LCDWrite(0, 0);
   	Cpu_Delay100US(5);
}
Example #17
0
void TaskccTalk(void){
	
	static uint8_t FlagTurnDevice=0;
	static uint8_t counter_events_coin_saved=0,coin_first_time=0;
	static uint8_t counter_events_bill_saved=0;
	uint8_t num_event;
	uint8_t string[6]={0};
	uint16_t time;
	uint8_t x;
	
	(void)EEPROM_GetPage(EEPROM_AREA_START);
	(void)EEPROM_GetBytePage(ADDR_SYSTEM_MODE,&cctalk.FlagPoll);
	(void)EEPROM_GetBytePage(ADDR_BILL_MODE,&cctalk.BillFlagMode);
	
	
	
	if(cctalk.FlagPoll==1){
		
		if(!coin_first_time){
			
			(void)CoinAcceptorReadBufferedCreditErrorCodes();
			counter_events_coin_saved=cctalk.CoinBufferErrorCredit[0];
			(void)BillReadBufferedBillEvents();
			counter_events_bill_saved=cctalk.BillBufferEvents[0];
			
			coin_first_time=1;			
		
		}else{
			
			//========================================================================//
			if(cctalk.CoinBufferErrorCredit[0]!=counter_events_coin_saved){
				num_event=cctalk.CoinBufferErrorCredit[0]-counter_events_coin_saved;
				if(num_event>=1 && cctalk.CoinBufferErrorCredit[1]){
					(void)CoinAcceptorReqCoinID(cctalk.CoinBufferErrorCredit[1],string);
					dataprintf("CI",2);
					dataprintf(string,6);
					dataprintf("\r\n",2);
				}
				
				if(num_event>=2 && cctalk.CoinBufferErrorCredit[3]){
					(void)CoinAcceptorReqCoinID(cctalk.CoinBufferErrorCredit[3],string);
					dataprintf("CI",2);
					dataprintf(string,6);
					dataprintf("\r\n",2);
				}
				
				if(num_event>=3 && cctalk.CoinBufferErrorCredit[5]){
					(void)CoinAcceptorReqCoinID(cctalk.CoinBufferErrorCredit[5],string);
					dataprintf("CI",2);
					dataprintf(string,6);
					dataprintf("\r\n",2);
				}
				
				if(num_event>=4 && cctalk.CoinBufferErrorCredit[7]){
					(void)CoinAcceptorReqCoinID(cctalk.CoinBufferErrorCredit[7],string);
					dataprintf("CI",2);
					dataprintf(string,6);
					dataprintf("\r\n",2);
				}
				
				if(num_event==5 && cctalk.CoinBufferErrorCredit[9]){
					(void)CoinAcceptorReqCoinID(cctalk.CoinBufferErrorCredit[9],string);
					dataprintf("CI",2);
					dataprintf(string,6);
					dataprintf("\r\n",2);
				}
				
				counter_events_coin_saved = cctalk.CoinBufferErrorCredit[0];
			}
			//===========================================================================//
			if(cctalk.BillBufferEvents[0]!=counter_events_bill_saved){
				
				num_event=cctalk.BillBufferEvents[0]-counter_events_bill_saved;
				
				if(num_event>=1 && cctalk.BillBufferEvents[1]){
									
					if(cctalk.BillFlagMode){
						//stacker automatically
						if(cctalk.BufferInput[2]){
							//send to stacker
							if(cctalk.BillBufferEvents[1]==255 && !cctalk.BillBufferEvents[1+2] && cctalk.BillBufferEvents[1+3]==20){
								(void)BillReqBarcode(cctalk.BillBarcode);								
							}
							(void)BillRouteBill(1,&x);//send to stacker
							
						}else{
							//bill stacked
							if(cctalk.BillBufferEvents[1]==255){
								dataprintf("BC",2);
								dataprintf(cctalk.BillBarcode,18);								
							}else{
								(void)BillReqBillTypeID(cctalk.BillBufferEvents[1],string);
								dataprintf("BI",2);
								dataprintf(string,6);
								dataprintf("ST",2);							
							}
							dataprintf("\r\n",2);
						}											
					}else{
						//escrow mode
						(void)BillReqBillTypeID(cctalk.BillBufferEvents[1],string);
						dataprintf("BI",2);
						dataprintf(string,6);
						if(cctalk.BillBufferEvents[2]){
							//escrow
							dataprintf("ES",2);
						}else{
							dataprintf("ST",2);
						}
						dataprintf("\r\n",2);
					}
				
				}
				
				if(num_event>=2 && cctalk.BillBufferEvents[3]){
													
					if(cctalk.BillFlagMode){
						//stacker automatically
						if(cctalk.BufferInput[4]){//bill in escrow
							//send to stacker
							if(cctalk.BillBufferEvents[3]==255 && !cctalk.BillBufferEvents[3+2] && cctalk.BillBufferEvents[3+3]==20){
								(void)BillReqBarcode(cctalk.BillBarcode);								
							}
							(void)BillRouteBill(1,&x);//send to stacker
							
						}else{
							//bill stacked
							if(cctalk.BillBufferEvents[3]==255){
								dataprintf("BC",2);
								dataprintf(cctalk.BillBarcode,18);								
							}else{
								(void)BillReqBillTypeID(cctalk.BillBufferEvents[3],string);
								dataprintf("BI",2);
								dataprintf(string,6);
								dataprintf("ST",2);							
							}
							dataprintf("\r\n",2);
						}											
					}else{
						//escrow mode
						(void)BillReqBillTypeID(cctalk.BillBufferEvents[3],string);
						dataprintf("BI",2);
						dataprintf(string,6);
						if(cctalk.BillBufferEvents[4]){
							//escrow
							dataprintf("ES",2);
						}else{
							dataprintf("ST",2);
						}
						dataprintf("\r\n",2);
					}
				
				}

				if(num_event>=3 && cctalk.BillBufferEvents[5]){
													
					if(cctalk.BillFlagMode){
						//stacker automatically
						if(cctalk.BufferInput[6]){
							//send to stacker
							if(cctalk.BillBufferEvents[5]==255 && !cctalk.BillBufferEvents[5+2] && cctalk.BillBufferEvents[5+3]==20){
								(void)BillReqBarcode(cctalk.BillBarcode);								
							}
							(void)BillRouteBill(1,&x);//send to stacker
							
						}else{
							//bill stacked
							if(cctalk.BillBufferEvents[5]==255){
								dataprintf("BC",2);
								dataprintf(cctalk.BillBarcode,18);								
							}else{
								(void)BillReqBillTypeID(cctalk.BillBufferEvents[5],string);
								dataprintf("BI",2);
								dataprintf(string,6);
								dataprintf("ST",2);							
							}
							dataprintf("\r\n",2);
						}											
					}else{
						//escrow mode
						(void)BillReqBillTypeID(cctalk.BillBufferEvents[5],string);
						dataprintf("BI",2);
						dataprintf(string,6);
						if(cctalk.BillBufferEvents[6]){
							//escrow
							dataprintf("ES",2);
						}else{
							dataprintf("ST",2);
						}
						dataprintf("\r\n",2);
					}
				
				}
				if(num_event>=4 && cctalk.BillBufferEvents[7]){
													
					if(cctalk.BillFlagMode){
						//stacker automatically
						if(cctalk.BufferInput[8]){
							//send to stacker
							if(cctalk.BillBufferEvents[7]==255 && !cctalk.BillBufferEvents[7+2] && cctalk.BillBufferEvents[7+3]==20){
								(void)BillReqBarcode(cctalk.BillBarcode);								
							}
							(void)BillRouteBill(1,&x);//send to stacker
							
						}else{
							//bill stacked
							if(cctalk.BillBufferEvents[7]==255){
								dataprintf("BC",2);
								dataprintf(cctalk.BillBarcode,18);								
							}else{
								(void)BillReqBillTypeID(cctalk.BillBufferEvents[7],string);
								dataprintf("BI",2);
								dataprintf(string,6);
								dataprintf("ST",2);							
							}
							dataprintf("\r\n",2);
						}											
					}else{
						//escrow mode
						(void)BillReqBillTypeID(cctalk.BillBufferEvents[7],string);
						dataprintf("BI",2);
						dataprintf(string,6);
						if(cctalk.BillBufferEvents[8]){
							//escrow
							dataprintf("ES",2);
						}else{
							dataprintf("ST",2);
						}
						dataprintf("\r\n",2);
					}
				
				}
				
				if(num_event>=5 && cctalk.BillBufferEvents[9]){
									
					if(cctalk.BillFlagMode){
						//stacker automatically
						if(cctalk.BufferInput[10]){
							//send to stacker
							if(cctalk.BillBufferEvents[9]==255){
								(void)BillReqBarcode(cctalk.BillBarcode);								
							}
							(void)BillRouteBill(1,&x);//send to stacker
							
						}else{
							//bill stacked
							if(cctalk.BillBufferEvents[9]==255){
								dataprintf("BC",2);
								dataprintf(cctalk.BillBarcode,18);								
							}else{
								(void)BillReqBillTypeID(cctalk.BillBufferEvents[9],string);
								dataprintf("BI",2);
								dataprintf(string,6);
								dataprintf("ST",2);							
							}
							dataprintf("\r\n",2);
						}											
					}else{
						//escrow mode
						(void)BillReqBillTypeID(cctalk.BillBufferEvents[9],string);
						dataprintf("BI",2);
						dataprintf(string,6);
						if(cctalk.BillBufferEvents[10]){
							//escrow
							dataprintf("ES",2);
						}else{
							dataprintf("ST",2);
						}
						dataprintf("\r\n",2);
					}
				
				}
				
				counter_events_coin_saved = cctalk.CoinBufferErrorCredit[0];
				
			}
			
		}
		
		
	}
	

	if(cctalk.FlagStatus){
		
		cctalk.FlagStatus=0;		
		
			switch(FlagTurnDevice){
			
			/////////////////////////////////////////////////////////
			
			case 0:
			
				if(cctalk.CoinFlagStatus!=DEVICE_NO_RESPONSE){
					
					cctalk.CoinFlagThere=1;
					
					(void)CoinAcceptorReadBufferedCreditErrorCodes();
					
					
				}else{
					
				//init coin acceptor
					
					cctalk.CoinFlagThere=0;
					
						if(CoinAcceptorPoll()){
							
							cctalk.CoinFlagStatus = DEVICE_OK;
							Cpu_Delay100US(100);
							//request manufacturer
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							(void)CoinAcceptorReqManufacturerID();
							
							Cpu_Delay100US(100);
							//request product code
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							
							(void)CoinAcceptorReqProductCode();
							Cpu_Delay100US(100);
							//request serial number
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							
							(void)CoinAcceptorReqSerialNumber();
							Cpu_Delay100US(100);
							//request software revision
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							
							(void)CoinAcceptorReqSoftwareVersion();
							Cpu_Delay100US(100);
							//request option flags
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							(void)CoinAcceptorReqOptionFlags();
							Cpu_Delay100US(100);
							//modify inhibit status
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							(void)CoinAcceptorModInhibitStatus(0xffff);
							Cpu_Delay100US(100);
							//modify master inhibit status
							CleanBufferInput();
							cctalk.FlagReceiveData=0;
							(void)CoinAcceptorModMasterInhibitStatus(1);
							Cpu_Delay100US(100);
																					
						}
					
				}
				
				FlagTurnDevice=1;
				
			break;
			////////////////////////////////////////////////////////
				
			case 1:
				
				if(cctalk.Hopper1FlagStatus!=DEVICE_NO_RESPONSE){
					
					cctalk.Hopper1FlagThere=1;
					
					if(cctalk.Hopper1FlagStatus == DEVICE_OK){
						
						(void)HopperSimplePoll(3);
					}
					
					if(cctalk.Hopper1FlagStatus == DEVICE_PAYOUT){
						
						if(HopperReqStatus(3,&cctalk.Hopper1CounterPay,&cctalk.Hopper1CoinsPendent,&cctalk.Hopper1CoinsPayOut,&cctalk.Hopper1UnPay)){
							
							(void)FC_HOPPER_GetTimeMS(&time);
							
							if((cctalk.Hopper1CoinsPayOut == cctalk.HopperCoinsToPay) && time>8500){
								
								UTIL_Num8uToStr(string,3,cctalk.Hopper1CounterPay);
								dataprintf("CTP",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper1CoinsPendent);
								dataprintf("CPD",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper1CoinsPayOut);
								dataprintf("CPY",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper1UnPay);
								dataprintf("CUP",3);
								dataprintf(string,3);
								dataprintf("\r\n",2);
								
							}
							
						}
						(void)HopperReqTestHopper(3,&cctalk.Hopper1Test);
					}
					
					
					
				}else{
					
					cctalk.Hopper1FlagThere=0;
					
					if(HopperSimplePoll(3)){
						
						cctalk.HopperAddress[0]=3;
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						cctalk.Hopper1FlagStatus = DEVICE_OK;
						(void)HopperReqSerialNumber(3,cctalk.Hopper1SerialNumber);
						
					}
					
				}
				
				FlagTurnDevice=2;
			
			break;
			/////////////////////////////////////////////////////////
			
			case 2:
				
				if(cctalk.Hopper2FlagStatus!=DEVICE_NO_RESPONSE){
							
					cctalk.Hopper2FlagThere=1;
					
					if(cctalk.Hopper2FlagStatus == DEVICE_OK){
						
						(void)HopperSimplePoll(4);		
					}
					
					if(cctalk.Hopper2FlagStatus == DEVICE_PAYOUT){
						
						if(HopperReqStatus(4,&cctalk.Hopper2CounterPay,&cctalk.Hopper2CoinsPendent,&cctalk.Hopper2CoinsPayOut,&cctalk.Hopper2UnPay)){
							
							(void)FC_HOPPER_GetTimeMS(&time);
														
							if((cctalk.Hopper2CoinsPayOut == cctalk.HopperCoinsToPay) && time>8500){
								
								UTIL_Num8uToStr(string,3,cctalk.Hopper2CounterPay);
								dataprintf("CTP",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper2CoinsPendent);
								dataprintf("CPD",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper2CoinsPayOut);
								dataprintf("CPY",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper2UnPay);
								dataprintf("CUP",3);
								dataprintf(string,3);
								dataprintf("\r\n",2);
								
							}
							
						}	
						
						(void)HopperReqTestHopper(4,&cctalk.Hopper2Test);
						
					}
					
					
					
				}else{
					
					cctalk.Hopper2FlagThere=0;
					
					if(HopperSimplePoll(4)){
									
						cctalk.HopperAddress[1]=4;
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						cctalk.Hopper2FlagStatus = DEVICE_OK;
						(void)HopperReqSerialNumber(4,cctalk.Hopper2SerialNumber);
						
					}
					
				}
				
				FlagTurnDevice=3;
			
			break;
			////////////////////////////////////////////////////////
			
			case 3:
			
				if(cctalk.Hopper3FlagStatus!=DEVICE_NO_RESPONSE){
					
					cctalk.Hopper3FlagThere=1;
					
					if(cctalk.Hopper3FlagStatus == DEVICE_OK){
						
						(void)HopperSimplePoll(5);
						
					}
					
					if(cctalk.Hopper3FlagStatus == DEVICE_PAYOUT){
					
						if(HopperReqStatus(5,&cctalk.Hopper3CounterPay,&cctalk.Hopper3CoinsPendent,&cctalk.Hopper3CoinsPayOut,&cctalk.Hopper3UnPay)){
							
							(void)FC_HOPPER_GetTimeMS(&time);
														
							if((cctalk.Hopper3CoinsPayOut == cctalk.HopperCoinsToPay) && time>8500){
								
								UTIL_Num8uToStr(string,3,cctalk.Hopper3CounterPay);
								dataprintf("CTP",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper3CoinsPendent);
								dataprintf("CPD",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper3CoinsPayOut);
								dataprintf("CPY",3);
								dataprintf(string,3);
								UTIL_Num8uToStr(string,3,cctalk.Hopper3UnPay);
								dataprintf("CUP",3);
								dataprintf(string,3);
								dataprintf("\r\n",2);
								
							}
							
						}	
						
						(void)HopperReqTestHopper(5,&cctalk.Hopper3Test);
		
					}
								
				}else{
					
					cctalk.Hopper3FlagThere=0;
					
					if(HopperSimplePoll(5)){
									
						cctalk.HopperAddress[2]=5;
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						cctalk.Hopper3FlagStatus = DEVICE_OK;
						(void)HopperReqSerialNumber(5,cctalk.Hopper3SerialNumber);
						
					}
				}
				
				FlagTurnDevice=4;
			break;
			///////////////////////////////////////////////////
			
			case 4:
				
				if(cctalk.BillFlagStatus!=DEVICE_NO_RESPONSE){
					
					cctalk.BillFlagThere=1;
					
					(void)BillReadBufferedBillEvents();
					
				}else{
					
					cctalk.BillFlagThere=0;
					
					if(BillPoll()){
						
						cctalk.BillFlagStatus = DEVICE_OK;
						
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						(void)BillReqProductCode();
						
						Cpu_Delay100US(100);
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						(void)BillReqManufacturerID();
						
						Cpu_Delay100US(100);
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						(void)BillReqSerialNumber();
						
						Cpu_Delay100US(100);
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						(void)BillModBillOperatingMode(3);
						
						Cpu_Delay100US(100);
						CleanBufferInput();
						cctalk.FlagReceiveData=0;
						(void)BillModMasterInhibitStatus(1);
						
					}
					
				}
				
				
				FlagTurnDevice=0;
				
			break;
			
		}
			

	}
	
	
}