com.c

来自「基于MC9S12C64的CAN总线通讯源程序」· C语言 代码 · 共 78 行

C
78
字号
#include "Com.h"
#include "AS1.h"
#include "IO_Map.h"

/*******************************************************************
* Transmit char (ASCII) subroutine 
* Description : Transmit ascii via RS232
*			  :
* Example     : N/A  
* Input 	  : data
* Output	  : single ascii to screen 
* Modify      : N/A
* Return      : N/A
********************************************************************/ 
void tx_char0(char data)
{
	while ((SCISR1&0x40)!=0x40);
	SCIDRL = data;
}


/*******************************************************************
* printf0 subroutine
* Description : Transmit string via RS232
*			  :
* Example     : N/A  
* Input 	  : *str
* Output	  : ascii to screen without lf and cr at the end
* Modify      : N/A
* Return      : N/A
********************************************************************/ 
void printf0(char *str)
{	
	while((*str != '\r'))
	{
		tx_char0(*str);
		if(*str++=='\n')
		  tx_char0('\r');		
	}
}



/*******************************************************************
* Transmit out 1 char (ASCII) subroutine
* Description : Transmit out upper and lower 4 bit of char as ascii
*             : via RS232
*			  :
* Example     : 0x32  
* Input 	  : 0x32 (cdata)
* Output	  : 3 2 (ascii)
* Modify      : N/A
* Return      : void
********************************************************************/ 
void send_asc(char cdata)
{
 	if(cdata>9)
	  tx_char0(cdata+'0'+7);
	else
	  tx_char0(cdata+'0');	
}

/*******************************************************************
* Convert HEX to ASCII subroutine
* Description : Convert hex to ascii and send out via RS232
*			  :
* Example     : 0x32  
* Input 	  : 0x32 (cdata)
* Output	  : 3 2 (ascii)
* Modify      : N/A
* Return      : void
********************************************************************/ 
void hex_asc(char cdata)
{
	send_asc((cdata>>4)&0x0f);
	send_asc((cdata)&0x0f);	
}

⌨️ 快捷键说明

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