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

📄 conu1.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 "conU1.h"

// I/O definitions for the Explorer16
#define TRTS1    TRISDbits.TRISD15   // tris control for RTS pin

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

// init the serial port (UART1, 115200@32MHz, 8, N, 1, CTS/RTS )
void initU1( void)
{
	U1BRG 	= BRATE1;
	U1MODE 	= U_ENABLE1;
	U1STA 	= U_TX1;
	TRTS1   = 0;        // make RTS output
	RTS1    = 1;        // set RTS default status
} // initCon

// send a character to the UART2 serial port
int putU1( int c)
{
	//while ( CTS1);		        // wait for !CTS, clear to send
	while ( U1STAbits.UTXBF);   // wait while Tx buffer full
	U1TXREG = c;
	return c;
} // putU1


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


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


char *getsn1( char *s, int len)
{
    char *p = s;            // copy the buffer pointer 
    do{
        *s = getU1();       // wait for a new character
        putU1( *s);         // echo character
        
        if (( *s==BACKSPACE1)&&( s>p))
        {
            putU1( ' ');     // overwrite the last character
            putU1( BACKSPACE1);
            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
} // getsn1
    

⌨️ 快捷键说明

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