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

📄 serial.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 4 页
字号:
{
   if ((port != PORT0) && (port != PORT1) && (port != PORT2) && (port != PORT3) && (port != PORT4))
   {
      return (NOTOK);
   }

   for (; len > 0; len--)
   {
      if (ReadByteUART(port, str) != OK)
      {
         return (NOTOK);
      }
      str++;
   }

   return (OK);
}



/******************************************************************************
* Describe:   UART byte send routine
* Input :  port & data
* Output:  void
* return:  0 is OK
******************************************************************************/
byte Wr_Byte_Uart(byte port, byte sendByte)
{
   g_sysCount = RSTIMEOUT;

   if ((port != PORT0) && (port != PORT1) && (port != PORT2) && (port != PORT3) && (port != PORT4))
   {
      return (NOTOK);
   }

	while (CheckSdBufFull(port) ) {		// Send buffer full
		if (g_sysCount == 0) {		// 超时
			/* No need care the timer out of transmit, 2004-10-19 9:57 by ZXC */
			// 这里不返回NOTOK的目的主要是为了保证上层软件不会一直都死在这边
			// return NOTOK;

			/* The new modified by JWM, Ignore the buffer when the timer is out */
			return OK;
		}
		if (port_use_print == PRN_PORT)				// KP/RP data sending
		{
         if (kp_rp_busy_chk() != OK)
         {
         	return (NOTOK);
         }
		}
	}
	if (port == PORT0) {
		Uart_DisInt2(port);
      wr0_Buff[wr0_In] = sendByte;
      wr0_In++;
		wr0_In &= WRBUFLEN0;
		Uart_EnInt2(port);
	}
	else if (port == PORT1) {
		Uart_DisInt2(port);
      wr1_Buff[wr1_In] = sendByte;
      wr1_In++;
		wr1_In &= WRBUFLEN1;
		Uart_EnInt2(port);
	}
	else if (port == PORT2) {
		Uart_DisInt2(port);
      wr2_Buff[wr2_In] = sendByte;
      wr2_In++;
		wr2_In &= WRBUFLEN2;
		Uart_EnInt2(port);
	}
	else if (port == PORT3) {
		Uart_DisInt2(port);
      wr3_Buff[wr3_In] = sendByte;
      wr3_In++;
		wr3_In &= WRBUFLEN3;
		Uart_EnInt2(port);
	}
	else if (port == PORT4) {
		Uart_DisInt2(port);
      wr4_Buff[wr4_In] = sendByte;
      wr4_In++;
		wr4_In &= WRBUFLEN4;
		Uart_EnInt2(port);
	}

   return (OK);
}

/******************************************************************************
* Describe:   UART byte receive routine
* Input :  port
* Output:  data pointer
* return:  0 is recieve valid data
******************************************************************************/
byte ReadByteUART(byte port, byte *getByte)
{
   g_sysCount = RSTIMEOUT;

   if (port == PORT0)
   {
      while (rs0_In == rs0_Out)
      {
         if (g_sysCount == 0)
         {
            return (NOTOK);
         }
      }
		Uart_DisInt2(port);
      *getByte = rs0_Buff[rs0_Out];
      rs0_Out++;
      rs0_Out &= RSBUFLEN0;
		Uart_EnInt2(port);
   }
   else if (port == PORT1)
   {
      while (rs1_In == rs1_Out)
      {
         if (g_sysCount == 0)
         {
            return (NOTOK);
         }
      }
		Uart_DisInt2(port);
      *getByte = rs1_Buff[rs1_Out];
      rs1_Out++;
      rs1_Out &= RSBUFLEN1;
		Uart_EnInt2(port);
   }
   else if (port == PORT2)
   {
      while (rs2_In == rs2_Out)
      {
         if (g_sysCount == 0)
         {
            return (NOTOK);
         }
      }
		Uart_DisInt2(port);
      *getByte = rs2_Buff[rs2_Out];
      rs2_Out++;
      rs2_Out &= RSBUFLEN2;
		Uart_EnInt2(port);
   }
   else if (port == PORT3)
   {
      while (rs3_In == rs3_Out)
      {
         if (g_sysCount == 0)
         {
            return (NOTOK);
         }
      }
		Uart_DisInt2(port);
      *getByte = rs3_Buff[rs3_Out];
      rs3_Out++;
      rs3_Out &= RSBUFLEN3;
		Uart_EnInt2(port);
   }
   else if (port == PORT4)
   {
      while (rs4_In == rs4_Out)
      {
      	if (g_sysCount == 0)
         {
            return (NOTOK);
         }
      }
		Uart_DisInt2(port);
      *getByte = rs4_Buff[rs4_Out];
      rs4_Out++;
      rs4_Out &= RSBUFLEN4;
		Uart_EnInt2(port);
	}
   return (OK);
}

/******************************************************************************
* Describe:   UART Transfer routine
* Input :  port, Select which port
* Output:  void
* return:  void
******************************************************************************/
void Uart_Transfer(byte port)
{
   switch(ser_port[port].device)
   {
   	case	PT_PC_COMM:
   	case	PT_POS_KB:
   	case	PT_SC:
		case	PT_ELEC_SCALE:
		case	PT_FP:
		case	PT_ONLINE:
		case	PT_CAT:
		case	PT_TS:
   			Uart_Send_Data(port);	/*send data to send register*/
				break;

   	case	PT_KP:
   	case	PT_RP:
				kp_rp_data_sd_chk(port);		/* Check the kitchen printer */
				break;

   	case	PT_NONE:
      default:
//				ClrWrBuf(port);
				Uart_Send_Null(port);
   			break;
   }
}

/******************************************************************************
* Describe:   UART Receive routine
* Input :  port, Select which port
* Output:  void
* return:  void
******************************************************************************/
void Uart_Receive(byte port, byte ch)
{
   switch(ser_port[port].device)
   {
		case 	PT_TS:
			if(TS_Init_Flag == 1)
			{
				Uart_Data_Store(port, ch);
			}
			else
			{
				if(TS_keyenable == 0)
				{
					if(TS_timercnt <= 5)
						TS_keyenable = 1;
					else
					{
						TS_timercnt = 55;
						break;
					}
				}
				if(TS_keyenable == 1)//allow to receive new ts key
					polling_PSKey(port, ch);
			}
			break;

   	case	PT_PC_COMM: 											/*PC connected*/
   	case	PT_POS_KB:							/*External keyboard connected*/
		case	PT_FP:
		case	PT_ONLINE:
		case	PT_CAT:
   			Uart_Data_Store(port,ch);
   			break;

		case	PT_KP:
		case	PT_RP:
				kp_rp_xonoff_chk(ch);
				break;

   	case	PT_SC:											 /*scanner connected*/
   			Uart_Scan_Data_Store(port,ch);
   			break;

		case	PT_ELEC_SCALE:									  /*Scale connected */
				Uart_Scale_Data_Store(port,ch);
				break;

   	case	PT_NONE:									 	 /* No device connected*/
		default:
//				Uart_Data_Store2(port);			/* discard the data */
				break;
	}
}

/******************************************************************************
* Describe:   UART 0 Transfer ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial0T(void)
{
   if (ti_u0c1)                  // transmit complete
   {
      if (wr0_In == wr0_Out)
      {
         uart0_Sending = 0;         // send one byte finished
      }
      else
      {
			Uart_Transfer(PORT0);
      }
   }
}

/******************************************************************************
* Describe:   UART 0 Receive ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial0R(void)
{
	byte ch;
   if (ri_u0c1)                  // receive complete
   {
      if ((u0rbh & 0x80) == 0)      // no error occur
      {
         ch = u0rbl;
			Uart_Receive(PORT0, ch);
      }
      else                    // error occur when receive, reset it
      {
         if (oer_u0rb == 1)         // overrun error, next valid data received
         {                    // NOTE: see specification page 144.
            if (((rs0_In + 1) & RSBUFLEN0) != rs0_Out)
            {
               rs0_Buff[rs0_In] = u0rbl;
               rs0_In++;
               rs0_In &= RSBUFLEN0;
            }
         }
         re_u0c1 = 0;            // disable receive
         re_u0c1 = 1;            // enable receive
      }
   }
}


/******************************************************************************
* Describe:   UART 1 Transfer ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial1T(void)
{
	if (ti_u1c1)                  // transmit complete
	{
		if (wr1_In == wr1_Out)
		{
			uart1_Sending = 0;         // send one byte finished
		}
		else
		{
			Uart_Transfer(PORT1);
		}
	}
}

/******************************************************************************
* Describe:   UART 1 Receive ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial1R(void)
{
	byte ch;
	
//	bellcnt = 0x30;
   if (ri_u1c1)                  // receive complete
   {
      if ((u1rbh & 0x80) == 0)      // no error occur
      {
		ch = u1rbl;
		Uart_Receive(PORT1, ch);
      }
      else                    // error occur when receive, reset it
      {
         if (oer_u1rb == 1)         // overrun error, next valid data received
         {                    // NOTE: see specification page 144.
            if (((rs1_In + 1) & RSBUFLEN1) != rs1_Out)
            {
               rs1_Buff[rs1_In] = u1rbl;
               rs1_In++;
               rs1_In &= RSBUFLEN1;
            }
         }
         re_u1c1 = 0;            // disable receive
         re_u1c1 = 1;            // enable receive
      }
   }
}


/******************************************************************************
* Describe:   UART 2 Transfer ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial2T(void)
{
   if (ti_u2c1)                  // transmit complete
   {
      if (wr2_In == wr2_Out)
      {
         uart2_Sending = 0;         // send one byte finished
      }
      else
      {
			Uart_Transfer(PORT2);
      }
   }
}

/******************************************************************************
* Describe:   UART 2 Receive ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial2R(void)
{
	byte ch;
	if (ri_u2c1)                  // receive complete
	{
		if ((u2rbh & 0x80) == 0)      // no error occur
		{
			ch = u2rbl;
			Uart_Receive(PORT2, ch);
		}
		else                    // error occur when receive, reset it
		{
			if (oer_u2rb == 1)         // overrun error, next valid data received
			{                    // NOTE: see specification page 144.
				if (((rs2_In + 1) & RSBUFLEN2) != rs2_Out)
				{
					rs2_Buff[rs2_In] = u2rbl;
					rs2_In++;
					rs2_In &= RSBUFLEN2;
				}
			}
			re_u2c1 = 0;            // disable receive
			re_u2c1 = 1;            // enable receive
		}
	}
}


/******************************************************************************
* Describe:   UART 3 Transfer ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial3T(void)
{
   if (ti_u3c1)                  // transmit complete
   {
      if (wr3_In == wr3_Out)
      {
         uart3_Sending = 0;         // send one byte finished
      }
      else
      {
			Uart_Transfer(PORT3);
      }
   }
}

/******************************************************************************
* Describe:   UART 3 Receive ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial3R(void)
{
	byte ch = 0;
   	if (ri_u3c1)                  // receive complete
   	{
      if ((u3rbh & 0x80) == 0)      // no error occur
      {
         ch = u3rbl;
//		Uart_Receive(PORT3, ch);
		Ts_Fx_Data_Input(ch);		/*Check the data legabilty of touch screen input*/
      }
      else                    // error occur when receive, reset it
      {
         if (oer_u3rb == 1)         // overrun error, next valid data received
         {                    // NOTE: see specification page 144.
			Ts_Fx_Data_Input(ch);

            if (((rs3_In + 1) & RSBUFLEN3) != rs3_Out)
            {
               rs3_Buff[rs3_In] = u3rbl;
               rs3_In++;
               rs3_In &= RSBUFLEN3;
            }
         }
         re_u3c1 = 0;            // disable receive
         re_u3c1 = 1;            // enable receive
      }
   }
}


/******************************************************************************
* Describe:   UART 4 Transfer ISR
* Input :  void
* Output:  void
* return:  void
******************************************************************************/
void Serial4T(void)
{
   if (ti_u4c1)                  // transmit complete
   {
      if (wr4_In == wr4_Out)
      {
         uart4_Sending = 0;         // send one byte finished
      }
      else
      {

⌨️ 快捷键说明

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