Code/C-Code/dspic.c
/*************************************************************
This function configures the uart module of dsPIC
Called from the main() function.
Each UART register is individually configured here
Baud rate is 9600. 8 data bits No parity
There are multiple UARTs in dsPIC. Any one can be configured.
**************************************************************/
This function configures the uart module of dsPIC
Called from the main() function.
Each UART register is individually configured here
Baud rate is 9600. 8 data bits No parity
There are multiple UARTs in dsPIC. Any one can be configured.
This function configures the uart module of dsPIC Called from the main () function . Each UART register is individually configured here Baud rate is 9600 . 8 data bits No parity There are multiple UARTs in dsPIC . Any one can be configured .
void uart_config()
{
	int i;
	U1MODEbits.UARTEN  = 0;						
	U1MODEbits.USIDL   = 0;						
	U1MODEbits.IREN    = 0;						
	U1MODEbits.RTSMD   = 0;						
	U1MODEbits.UEN     = 0;						
	U1MODEbits.WAKE    = 0;						
	U1MODEbits.LPBACK  = 0;						
	U1MODEbits.ABAUD   = 0;						
	U1MODEbits.URXINV  = 0;						
	U1MODEbits.BRGH    = 0;						
	U1MODEbits.PDSEL   = 0;						
	U1MODEbits.STSEL   = 0;						
	U1BRG 				= 38;	
	U1STAbits.UTXISEL1 = 0;						
	U1STAbits.UTXINV   = 0;						
	U1STAbits.UTXISEL0 = 0;						
	U1STAbits.UTXBRK   = 0;						
	U1STAbits.UTXEN    = 0;						
	U1STAbits.UTXBF    = 0;						
	U1STAbits.TRMT     = 0;						
	U1STAbits.URXISEL  = 0;						
	U1STAbits.ADDEN    = 0;						
	U1STAbits.RIDLE    = 0;						
	U1STAbits.PERR     = 0;						
	U1STAbits.FERR     = 0;						
	U1STAbits.OERR     = 0;						
	U1STAbits.URXDA    = 0;						
	IPC2 = 0x4000;								
	IPC3 = 0x0004;								
	IFS0bits.U1TXIF = 0;						
	IEC0bits.U1TXIE = 0;						
	IFS0bits.U1RXIF = 0;						
	IEC0bits.U1RXIE = 0;						
	U1MODEbits.UARTEN = 1;						
	U1STAbits.UTXEN = 1;						
	for(i = 0; i < 50; i++)
	{
		Nop();
	}
	CNPU1 = 0x0000;								
	CNPU2 = 0x0000;								
}
void uart_config ( ) { int i ; U1MODEbits . UARTEN = 0 ; U1MODEbits . USIDL = 0 ; U1MODEbits . IREN = 0 ; U1MODEbits . RTSMD = 0 ; U1MODEbits . UEN = 0 ; U1MODEbits . WAKE = 0 ; U1MODEbits . LPBACK = 0 ; U1MODEbits . ABAUD = 0 ; U1MODEbits . URXINV = 0 ; U1MODEbits . BRGH = 0 ; U1MODEbits . PDSEL = 0 ; U1MODEbits . STSEL = 0 ; U1BRG = 38 ; U1STAbits . UTXISEL1 = 0 ; U1STAbits . UTXINV = 0 ; U1STAbits . UTXISEL0 = 0 ; U1STAbits . UTXBRK = 0 ; U1STAbits . UTXEN = 0 ; U1STAbits . UTXBF = 0 ; U1STAbits . TRMT = 0 ; U1STAbits . URXISEL = 0 ; U1STAbits . ADDEN = 0 ; U1STAbits . RIDLE = 0 ; U1STAbits . PERR = 0 ; U1STAbits . FERR = 0 ; U1STAbits . OERR = 0 ; U1STAbits . URXDA = 0 ; IPC2 = 0x4000 ; IPC3 = 0x0004 ; IFS0bits . U1TXIF = 0 ; IEC0bits . U1TXIE = 0 ; IFS0bits . U1RXIF = 0 ; IEC0bits . U1RXIE = 0 ; U1MODEbits . UARTEN = 1 ; U1STAbits . UTXEN = 1 ; for ( i = 0 ; i < 50 ; i ++ ) { Nop ( ) ; } CNPU1 = 0x0000 ; CNPU2 = 0x0000 ; }
This function configures the uart module of dsPIC
Called from the main() function.
This function configures the uart module of dsPIC Called from the main () function .
// configure U1MODE // Bit15 TX, RX DISABLED, ENABLE at end of func // Bit13 Continue in Idle // Bit12 No IR translation // Bit11 Simplex Mode // Bits8,9 TX,RX enabled, CTS,RTS not // Bit7 No Wake up ) // Bit6 No Loop Back // Bit5 No Autobaud (would require sending '55') // Bit4 IdleState = 1  (for dsPIC) // Bit3 16 clocks per bit period // Bits1,2 8bit, No Parity // Bit0 One Stop Bit // Load a value into Baud Rate Generator.  Example is for 9600. // 12Mhz osc, 9600 Baud // Load all values in for U1STA SFR // Bit15 Interrupt when Char is transferred // Bit14 N/A, IRDA config // Bit13 Other half of Bit15 // Bit11 Disabled // Bit10 TX pins controlled by periph // Bit9 *Read Only Bit* // Bit8 *Read Only bit* // Bits6,7 Int. on character recieved // Bit5 Address Detect Disabled // Bit4 *Read Only Bit* // Bit3 *Read Only Bit* // Bit2 *Read Only Bit* // Bit1 *Read Only Bit* // Bit0 *Read Only Bit* // Priority for Receive Interrupt // Priority for Transmit Interrupt // Clear the Transmit Interrupt Flag // Disable Transmit Interrupts // Clear the Recieve Interrupt Flag // Disable Recieve Interrupts // turn the peripheral on // Enable transimission /* wait at least 104 usec (1/9600) before sending first char */ // Pullups on change notification pins disabled // Pullups on change notification pins disabled