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

📄 isp.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 2 页
字号:
				}
				if (result == OK)
					break;
				Fls_Reset();
			}
			if (result == NG)
			{
				OpenBuzzer();
				while (1);
			}
		}

      OpenBuzzer();
      Fls_Reset();

//		Isp_CmosSet();
		for (i = 0; i < 40; i++) {
			if (i&0x01)
				pSramLast512Bytes[i] = 0x55;
			else
				pSramLast512Bytes[i] = 0xaa;
		}
		for (i = 0; i < 40; i++) {
			cmosValid[i] = 0;
			cmosValid2[i] = 0;
		}

		//------- soft Reset
		prc1 = 1;
		pm03 = 1;
		prc1 = 0;
		asm("fset i");
		while (1);
	}
}

void ISPPart(void)
{
   if (GetNewProgram() != OK)
   {
   	Clr_Dsp_Data();
      disp_Char_Str("ER",0);

		Rst_Lcd_Text();
		Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, "ISP failure!", ALIGN_LEFT);
		Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);
		Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, "You must restart machine!", ALIGN_LEFT);
		Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);
		while (1);

      GetKey();
      return;
   }
   
   Clr_Dsp_Data();
   disp_Char_Str("I S P .",0);
   asm("mov.l #_ISP_WriteFls, _ispAddr");
   memcpy((byte *)(SRAM_BASE_ADDR-0x2000), (byte *)ispAddr, 0x2000);
   disint();
//	wdts = 0xff;
	/* Really write the code to Flash Chip */
   asm("jsr.a 17E000H");
}

/*------------------------------------------------------------------
*  ISP function input check.
*  Step:   ---> 8888 --> CASH ---> 9999 --> SUBTTL 
*  Then start the ISP function.
*----------------------------------------------------------------*/
void isp_chk(void)
{
   Clr_Dsp_Data();
   disp_Char_Str("ISP-SURE",0);
	#if 0
   if ( GetIn() == OK )
   {
      if ( lnum == 9999 && (InCmd == KD_SUBTTL || InCmd == KD_SURE) )
      {
//      	if((port_sel>>4) != PT_ISP)
//      	{
//				if((CheckWrBufEmpty(ISP_PORT) != 0)/* || (CheckRsBufEmpty(ISP_PORT) != 0)*/)
//				{
//					errorType(ERR_BUFF_EMPTY);
//					return;
//				}
//      		Push_Pop_Port_Status(PUSH, PT_ISP, ISP_PORT);
//      	}
//      	else
//      	{
//				ClrRsBuf(ISP_PORT);				/* Clear the receive buffer */
//				ClrWrBuf(ISP_PORT);				/* Clear the send buffer */
//      	}
         ISPPart();
//         Push_Pop_Port_Status(POP, 0xFF, ISP_PORT);
      }
   }
	#endif
	if (Chk_Isp_Sure()) {
		Rst_Lcd_Text();
		Lcd_Send_Text_Buff_Str(BUF_ID_LCD_TEXT, 1, "Doing the ISP...", ALIGN_LEFT);
		Lcd_Disp_Text_Buff(BUF_ID_LCD_TEXT);

		ISPPart();
	}
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	检查是否因ISP而清除CMOS数据有效标志. (SRAM 最后512个字节)
// In Param:	void
// Out Param:	void
// Return:		OK -- 因ISP而起. / NG
///////////////////////////////////////////////////////////////////////////////
byte Isp_CmosChk(void)
{
	byte i;

	for (i=0; i<40; i++)
	{
		if ((i % 2) == 0)
		{
			if (pSramLast512Bytes[i] != 0xaa)
			{
				return NG;
			}
		}
		else
		{
			if (pSramLast512Bytes[i] != 0x55)
			{
				return NG;
			}
		}
	}
	return OK;
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	设置ISP的全清完成的标志. (SRAM 最后512个字节)
// In Param:	void
// Out Param:	void
// Return:		OK -- 因ISP而起. / NG
///////////////////////////////////////////////////////////////////////////////
void Isp_CmosSet(void)
{
	byte i;
	for (i = 0; i < 40; i++) {
		if (i&0x01)
			pSramLast512Bytes[i] = 0x55;
		else
			pSramLast512Bytes[i] = 0xaa;
	}
	CMOS_Illegal();
}

///////////////////////////////////////////////////////////////////////////////
// Descript:	清除因ISP而清除CMOS数据有效标志. (SRAM 最后512个字节)
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Isp_ClrCmos(void)
{
	memset(pSramLast512Bytes, 0, 40);
}




/*****************************************************************
从PC 下载图片存入Flash中去.
Flash 的起始地址为0x280000
但是最后的10个字节不能传送下来,
这个不会对整个画面造成什么影响
*****************************************************************/

byte ISP_FlsWrite_Logo(void)
{
   byte sendData[50];
   byte recvData[200];
   byte i;
   WORD j;
   dword tmpAddr, flsAddr;
   byte chkSum;
   byte *ptr;
   byte temp;
   dword lastAddr;
   byte port = ISP_PORT;
   long num;
	
   lastAddr = LCD_LOGO_SIZE;
	
	if (port == ISP_PORT)
	{
		// only for debug
		Uart_SetBaudRate(ISP_PORT, BRG_576);
	}
//	for ( j = 0; j < 5; j ++ ) 		/*Initial for can receive and transmit data*/
//		ser_port[j].device = PT_PC_COMM;

   	ta3s = 0;            // 关闭这些定时器,是为了提高串口通信速度.
   	tb2s = 0;
   	ta4s = 0;
   	CloseBuzzer();
  	 bellcnt = 0;
// 	ta0s = 0;
	Clr_Dsp_Data();
	disp_Char_Str("HAND-----", 0);
	
   	for (i=0; i<3; i++)
   	{
      	ClrRsBuf(port); 
      	sendData[0] = 0x1b;
	      sendData[1] = 0x10;
	      sendData[2] = 0xfe;
	      sendData[3] = 0x10;
	      sendData[4] = 0x07;
	      sendData[5] = 0x00;
	      sendData[6] = 0x1b + 0x10 + 0xfe + 0x10 + 0x07 + 0x00;
	      Wr_Str_Uart(port, sendData, 7);//send hand shake cmd
	      
	      if (ReadStringUART(port, recvData, 5) == OK)
	      {
         		if ((recvData[0] + recvData[1] + recvData[2] + recvData[3] == recvData[4]) && 
            		(memcmp(recvData, "OK", 2) == 0))
         		{
           			break;
         		}
      	}
		for (j=0; j<0xffff; j++);
		for (j=0; j<0xffff; j++);
	}
	if (i >= 3)
	{
		sendData[0] = 0x1b;
		sendData[1] = 0x10;
		sendData[2] = 0xfe;
		sendData[3] = 0x13;
		sendData[4] = 0x07;
		sendData[5] = 0x00;
		sendData[6] = 0x1b + 0x10 + 0xfe + 0x13 + 0x07 + 0x00;
		Wr_Str_Uart(port, sendData, 7);//end the hand shake
		
		ta3s = 1;
		tb2s = 1;
		ta4s = 1;
	// 	ta0s = 0;
		return 0xff;
	}
	
   	Clr_Dsp_Data();
   	disp_Char_Str("DOUN-----",0);
		
	//start receiving data	
  	for (tmpAddr=0; tmpAddr < lastAddr; tmpAddr+=0x80)
   	{
		flsAddr = tmpAddr;
     		 for (i=0; i<3; i++)
      	{
         		ClrRsBuf(port);
         		sendData[0] = 0x1b;
	         	sendData[1] = 0x10;
	         	sendData[2] = 0xfe;
	         	sendData[3] = 0x14;
	         	sendData[4] = 13;
	         	sendData[5] = 0;
	         	sendData[6] = (byte)flsAddr;
	         	sendData[7] = (byte)(flsAddr >> 8);
	         	sendData[8] = (byte)(flsAddr >> 16);
	         	sendData[9] = (byte)(flsAddr >> 24);
	         	sendData[10] = 0x80;
	         	sendData[11] = 0x00;
	         	sendData[12] = 0;
         		for (j=0; j<12; j++)
         		{
            		sendData[12] += sendData[j];
         		}
         		Wr_Str_Uart(port, sendData, 13);
					
         		if (ReadStringUART(port, recvData, 8+0x80) == OK)
         		{
		            chkSum = 0;
		            for (j=0; j<0x80+8; j++)
		            {
		               	chkSum += recvData[j];
		            }
		            if ((ReadByteUART(port, &temp) == 0) && (chkSum == temp))
            		{
			              if ((memcmp(recvData, "OK", 2) == 0) 
			                  	&& (memcmp(&recvData[4], &sendData[6], 4) == 0)
			                  	&& ((recvData[2] + recvData[3] * 0x100) == 0x89))
			                  break;
					//disp_Char_Str("DATA ERR",0);
		            }
				//else
					////disp_Char_Str("CS ERR",0);
        	 	}
		         for (j=0; j<0xffff; j++);
		         for (j=0; j<0xffff; j++);
      	}//request for 0x80byte data
	      if (i >= 3)
	      {
	         sendData[0] = 0x1b;
	         sendData[1] = 0x10;
	         sendData[2] = 0xfe;
	         sendData[3] = 0x13;
	         sendData[4] = 0x07;
	         sendData[5] = 0x00;
	         sendData[6] = 0x1b + 0x10 + 0xfe + 0x13 + 0x07 + 0x00;
	         Wr_Str_Uart(port, sendData, 7);
	         ta3s = 1;
	         tb2s = 1;
	         ta4s = 1;
		  // disp_Char_Str("RECE ERR",0);
	         return 0xff;
	      }

      	ptr = (byte *)(FLS_LCD_LOGO_ADDR+ tmpAddr);
      	Fls_WriteStr(ptr, &recvData[8], 0x80);/*Store the received data */
   	}
	//end of the request
	
   	sendData[0] = 0x1b;
   	sendData[1] = 0x10;
   	sendData[2] = 0xfe;
   	sendData[3] = 0x12;
   	sendData[4] = 0x07;
   	sendData[5] = 0x00;
   	sendData[6] = 0x1b + 0x10 + 0xfe + 0x12 + 0x07 + 0x00;
   	Wr_Str_Uart(port, sendData, 7);
   	ta3s = 1;
  	 tb2s = 1;
  	 ta4s = 1;
  	 return OK;
}


void isp_logo_Down(void)
{
   Clr_Dsp_Data();
   disp_Char_Str("ISP-SURE",0);
   if ( GetIn() == OK )
   {
      if ( lnum == 9999 && (InCmd == KD_SUBTTL||InCmd == KD_SURE) )
      {
         if(ISP_FlsWrite_Logo() != OK)
		disp_Char_Str("ISP Error",0);
      }
   }
}


⌨️ 快捷键说明

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