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

📄 uart0.c

📁 C语言源代码及相关资料
💻 C
字号:
#include <userint.h>
#include <rs232.h>
#include <utility.h>
#include <ansi_c.h>

#include "uartx.h"
/*
===================================
	uart0
===================================
*/

static
unsigned char *	puart;

static
int				com;

void	uart0_enable( void )
{
	puart = "CNCB0";
	com    = 2;
}

void	uart0_disable( void )
{
	puart = "";
	com    = 0;
}

int		uart0_close ( void )
{
	CloseCom ( com );
	uart0_disable ();
	return 0;
}

int		uart0_open ( int baud, int startbits, int databits, int paritybit, int stopbits )
{

	uart0_enable ();

	if ( OpenComConfig ( com, puart, baud, paritybit, databits, stopbits, 1024, 1024 ) < 0 ) MessagePopup ( "Uart 0", "Open Error..." );

/*  Turn off Hardware handshaking (loopback test will not function with it on) */
	SetCTSMode ( com, LWRS_HWHANDSHAKE_OFF );
//	SetCTSMode ( com, LWRS_HWHANDSHAKE_CTS_RTS_DTR );
//	SetCTSMode ( com, LWRS_HWHANDSHAKE_CTS_RTS );

/*  Make sure Serial buffers are empty */
	FlushInQ ( com );
	FlushOutQ ( com );

/*  Promt the user to enter an event character. */
//	PromptPopup ("Event Character", "Enter the Event Character", gEventChar, 1);

/*  Install a callback such that if the event character appears at the receive buffer, our function will be notified.  */
//	InstallComCallback (1, LWRS_RXFLAG, 0, (int)gEventChar[0] , Event_Char_Detect_Func, 0);

	return 0;
}

int		uart0_read ( unsigned char * pbuf, int nSize )
{
char	szTmp[ 160 ];
int		len;
int		count = 2;

	while ( !(len = GetInQLen ( com )) && (count-- > 0) );

	if ( len <= 0 || nSize <= 0 )
	{
		sprintf ( szTmp, "InQ 0 : %d, buffer size = %d\n", len, nSize );
//		printf ( szTmp );
//		MessagePopup ( "Debug", szTmp );
		return 0;
	}

	if ( len > nSize ) len = nSize;

	return ComRd ( com, pbuf, len );
}

int		uart0_write ( unsigned char * pdata, int size )
{
	return ComWrt ( com, pdata, size );
}

⌨️ 快捷键说明

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