Mondalot
Junior Member level 3
- Joined
- Sep 28, 2013
- Messages
- 29
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 235
Hello,
A week ago to enable the UART 2 and there is no way, it doesn't work.
The Proton Compiler code was easy to understand, That I need to do!!
My code was tested with the original datasheet and did not work.
The code work ok using RX1&TX1.(without ASM code)
Someone may Help me. Thanks.
_____ORIGINAL DATASHEET___________________________________
-----------------------------------------------------
______________MY CODE ________________________
THX.
A week ago to enable the UART 2 and there is no way, it doesn't work.
The Proton Compiler code was easy to understand, That I need to do!!
My code was tested with the original datasheet and did not work.
The code work ok using RX1&TX1.(without ASM code)
Someone may Help me. Thanks.
_____ORIGINAL DATASHEET___________________________________
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ;************************************* ; Unlock Registers ;************************************* ; PPS registers are in BANK 14 MOVLB 0x0E BCF INTCON, GIE ; Disable interrupts ; for unlock sequence MOVLW 0x55 MOVWF EECON2, 0 MOVLW 0xAA MOVWF EECON2, 0 ; Turn off PPS Write Protect BCF PPSCON, IOLOCK, BANKED ;*************************** ; Assign RX2 To Pin RP0 ;*************************** MOVLW 0x00 MOVWF RPINR16, BANKED ;*************************** ; Assign TX2 To Pin RP1 ;*************************** MOVLW 0x05 MOVWF RPOR1, BANKED ;************************************* ; Lock Registers ;************************************* MOVLW 0x55 MOVWF EECON2, 0 MOVLW 0xAA MOVWF EECON2, 0 ; Write Protect PPS (if desired) BSF PPSCON, IOLOCK, BANKED
-----------------------------------------------------
______________MY CODE ________________________
Code Basic4GL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 Device = 18F46J50 'PIC Selection Declare Xtal 12 'FIX XTAL to 12Mhz Config_Start 'Fuses WDTEN = OFF ;Disabled - Controlled by SWDTEN bit PLLDIV = 3 ;Divide by 3 (12 MHz oscillator input) STVREN = On ;Enabled XINST = OFF ;Enabled Extended intruction disable Debug = OFF ;Disabled CPUDIV = OSC1 ;No CPU system clock divide CP0 = OFF ;Program memory is not code-protected OSC = HS 'HSPLL ;HS+PLL, USB-HS+PLL T1DIG = On ;Secondary Oscillator clock source may be selected LPT1OSC = OFF ;High-power operation FCMEN = OFF ;Disabled fail-safe clock monitor IESO = On ;Enabled 'two-speed start-up WDTPS = 32768 ;1:32768 DSWDTOSC = INTOSCREF ;DSWDT uses INTRC RTCOSC = T1OSCREF ;RTCC uses T1OSC/T1CKI DSBOREN = On ;Enabled DSWDTEN = OFF ;Watch Dog DSWDTPS = G2 ;1:2,147,483,648 (25.7 days) IOL1WAY = OFF ;The IOLOCK bit (PPSCON<0>) can be set once ' MSSP7B_EN = MSK7 ;7 Bit address masking mode 'WPFP = PAGE_63 ;Write Protect Program Flash Page 63 ' WPEND = PAGE_WPFP ;Page WPFP<5:0> through Configuration Words erase/write protected WPCFG = OFF ;Configuration Words page not erase/write-protected WPDIS = OFF ;WPFP<5:0>/WPEND region ignored Config_End ''Declarations EUSART2 Declare Hserial2_Baud = 9600 'Set baud rate to 9600 Declare Hserial2_RCSTA = %10010000 'Enable serial port and continuous receive Declare Hserial2_TXSTA = %00100100 'Enable transmit and asynchronous mode Declare Hserial2_SPBRG = 77 'Set SPBRG for 12Mhz Xtal Declare Hserial2_Clear = On 'Optionally clear the buffer before receiving Declare All_Digital = True 'PortA all Digital Dim Var1 As Byte 'Configuring USART2 Movlw 0x55 Movwf EECON2, 0 Movlw 0xAA Movwf EECON2, 0 PPSCON.0=0 'Turn off PPS Write Protect 0 RPINR16=0 'PortA.0= RX2 Mapping Port RPOR1=5 'PortA.1= TX2 Mapping Port, view datasheet Table 10-14 Movlw 0x55 Movwf EECON2, 0 Movlw 0xAA Movwf EECON2, 0 PPSCON.0=1 ' Turn on PPS Write Protect TRISA = %00000001 '1=Input A.0 / 0 = Outs A.1 Loop: HSerIn2 1000, Timeout, [Var1] ' Receive a byte serially into Var1 Print Dec Var1, " " ' Display the byte received GoTo Loop ' Loop forever Timeout: Cls Print "Timed Out" ' Display an error if Hserin2 timed out DelayMS 500 Stop End
THX.
Last edited by a moderator: