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

📄 conu2.c

📁 PIc24 Real time clock with alarm and 10sec interruptions
💻 C
字号:
/*
** CONIO.C
** Basic CONSOLE I/O for Explorer16 demonstration board
*/

#include <p24fj128ga010.h>
#include "conU2.h"

// I/O definitions for the Explorer16
#define TRTS2    TRISFbits.TRISF13   // tris control for RTS pin

// timing and baud rate settings 
#define BRATE2		68		    // [35] 111111 [34] 115200 [68] 57600 (BREGH=1)
#define U_ENABLE2	0x8008		// enable the UART peripheral
#define U_TX2		0x0400		// enable transmission

// init the serial port (UART2, 115200@32MHz, 8, N, 1, CTS/RTS )
void initU2( void)
{
	U2BRG 	= BRATE2;
	U2MODE 	= U_ENABLE2;
	U2STA 	= U_TX2;
	TRTS2   = 0;        // make RTS output
	RTS2    = 1;        // set RTS default status
} // initCon

// send a character to the UART2 serial port
int putU2( int c)
{
	//while ( CTS2);		        // wait for !CTS, clear to send
	while ( U2STAbits.UTXBF);   // wait while Tx buffer full
	U2TXREG = c;
	return c;
} // putU2


// wait for a new character to arrive to the UART2 serial port
char getU2( void)
{
    RTS2 = 0;            // assert Request To Send !RTS
	while ( !U2STAbits.URXDA);	// wait for a new character to arrive
	RTS2 = 1;
	return U2RXREG;		// read the character from the receive buffer
}// getU2


// send a null terminated string to the UART2 serial port
void putsU2( char *s)
{
	while( *s)			// loop until *s == '\0' the  end of the string
		putU2( *s++);	// send the character and point to the next one
    putU2( '\r');       // terminate with a cr / line feed
} // putsU2


char *getsn( char *s, int len)
{
    char *p = s;            // copy the buffer pointer 
    do{
        *s = getU2();       // wait for a new character
        putU2( *s);         // echo character
        
        if (( *s==BACKSPACE2)&&( s>p))
        {
            putU2( ' ');     // overwrite the last character
            putU2( BACKSPACE2);
            len++;
            s--;            // back the pointer
            continue;
        }
        if ( *s=='\n')      // line feed, ignore it
            continue;
        if ( *s=='\r')      // end of line, end loop
            break;          
        s++;                // increment buffer pointer
        len--;
    } while ( len>1 );      // until buffer full
 
    *s = '\0';              // null terminate the string 
    
    return p;               // return buffer pointer
} // getsn
    

⌨️ 快捷键说明

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