EasyManua.ls Logo

Microchip Technology dsPIC30F - Initialization

Microchip Technology dsPIC30F
738 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
dsPIC30F Family Reference Manual
DS70066C-page 19-20 © 2004 Microchip Technology Inc.
19.9 Initialization
Example 19-2 is an initialization routine for the Transmitter/Receiver in 8-bit mode. Example 19-3
shows an initialization of the Addressable UART in 9-bit Address Detect mode. In both examples,
the value to load into the UxBRG register is dependent on the desired baud rate and the device
frequency.
Example 19-2: 8-bit Transmit/Receive (UART1)
Example 19-3: 8-bit Transmit/Receive (UART1), Address Detect Enabled
Note: The UTXEN bit should not be set until the UARTEN bit has been set. Otherwise,
UART transmissions will not be enabled.
MOV #baudrate,W0 ; Set Baudrate
MOV W0,U1BRG
BSET IPC2,#U1TXIP2 ; Set UART TX interrupt priority
BCLR IPC2,#U1TXIP1 ;
BCLR IPC2,#U1TXIP0 ;
BSET IPC2,#U1RXIP2 ; Set UART RX interrupt priority
BCLR IPC2,#U1RXIP1 ;
BCLR IPC2,#U1RXIP0 ;
CLR U1STA
MOV #0x8800,W0 ; Enable UART for 8-bit data,
; no parity, 1 STOP bit,
; no wakeup
MOV W0,U1MODE
BSET U1STA,#UTXEN ; Enable transmit
BSET IEC0,#U1TXIE ; Enable transmit interrupts
BSET IEC0,#U1RXIE ; Enable receive interrupts
MOV #baudrate,W0 ; Set Baudrate
MOV W0,U1BRG
BSET IPC2,#U1TXIP2 ; Set UART TX interrupt priority
BCLR IPC2,#U1TXIP1 ;
BCLR IPC2,#U1TXIP0 ;
BSET IPC2,#U1RXIP2 ; Set UART RX interrupt priority
BCLR IPC2,#U1RXIP1 ;
BCLR IPC2,#U1RXIP0 ;
BSET U1STA,#ADDEN ; Enable address detect
MOV #0x8883,W0 ; UART1 enabled for 9-bit data,
; no parity, 1 STOP bit,
; wakeup enabled
MOV W0,U1MODE
BSET U1STA,#UTXEN ; Enable transmit
BSET IEC0,#U1TXIE ; Enable transmit interrupts
BSET IEC0,#U1RXIE ; Enable receive interrupts

Table of Contents

Other manuals for Microchip Technology dsPIC30F