TODOPIC
Microcontroladores PIC => Lenguaje Basic para microcontroladores PIC => Mensaje iniciado por: Enner en 20 de Septiembre de 2013, 15:46:57
-
Hola,
Estoy haciendo un proyecto que necesita dos puertos series y necesito utilizar el 2do puerto del PIC 18F46J50 (tiene 2 EUSART) en el Data Sheet pone que
están Multiplexado, he ido al apto donde hablan de los puertos y leyendo tengohe entendido que se puede mapear, pero es la primera vez que hago
y no se como funciona.
Aquí os dejo mi código que de momento no funciona. Haber que puedo hacer..
Necesito vuestra ayuda, Muchas gracias..
DataSheet PIC 18F46J50 (http://ww1.microchip.com/downloads/en/DeviceDoc/39931d.pdf)
(http://imageshack.com/scaled/large/22/1riu.jpg)
'---------------Código...
Device = 18F46J50 'Selecciono pic
Declare Xtal 12 ' XTAL a 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
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
Config_End
All_Digital = TRUE ' Set PORTA to all digital
Dim Var1 As Byte
'Mapeo los puertos
RPINR16= 4 'Pongo RB1 para RX2
RPOR3 = 5 'Pongo RB0 para TX2
'Declarations EUSART2
Declare Hserial2_Baud = 9600
Declare Hserial2_RCSTA = %10010000
Declare Hserial2_TXSTA = %00100100
Declare Hserial2_SPBRG = 77
Declare Hserial2_Clear = On
Loop:
HSerIn2 1000, Timeout, [Var1]
Print Dec Var1, " "
GoTo Loop ' Loop forever
Timeout:
Cls
Print "Tiempo Error"
DelayMS 500
Stop
End
-
Le he echado un vistazo al datasheet del micro y realmente esta un poco lioso. Básicamente es porque el remapeado de los pin contiene unos bit de protección para que no se puedan variar, hasta que no se realiza la secuencia completa el micro no permite el remapeado de pin. En el data hay un ejemplo (EXAMPLE 9-7), este ejemplo está en código maquina para ser insertado en alguna versión de lenguaje C. El datasheets recomienda que se realice el remapeado en lenguaje máquina, porque debido a las protecciones que contiene el modulo PPS para que por descuido del programador o motivos de interferencia se cambia su configuración de forma accidental. El código maquina suele ser muy universal, posiblemente borrando los comentarios o cambiando el prefijo de inicio de comentario y las dos directivas de inserción en el código y fin de código maquina, puede que se integre en tu lenguaje. Es posible que no reconozca los nombres de los registros y tengas que sustituirlos por sus direcciones. De todas formas es un tema interesante que hace tiempo que quiero experimentar por necesidad pero por el momento no tengo tiempo.
-
Gracias por tu respuesta dogflu66,
Estuve leyendo el apto del data sheet que se refiere al USART 10.0 y tienes razón.
He agregado tres cosas en el código una es la de un Fuse para este tipo de micro para el registro "IOL1WAY = PPSCON", TRISA
y la otra el código ASM. pero aún asi, no me funciona no se si tengo que declarar algo mas o que!!.
Gracias.
-------------------- CÓDIGO -------------------------------------------------------
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
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
IOL1WAY = OFF ;The IOLOCK bit (PPSCON<0>) can be set once <------------- AÑADIDO
Config_End
Dim Var1 As Byte
DIM BANKED as Byte
'Declaro la 2 EUSART
Declare Hserial2_Baud = 9600
Declare Hserial2_RCSTA = %10010000
Declare Hserial2_TXSTA = %00100100
Declare Hserial2_SPBRG = 77
Declare Hserial2_Clear = On
Declare All_Digital = True
TRISA = %00000001 <------------- AÑADIDO
Asm <------------- AÑADIDO
Movlb 0X0E
Bcf INTCON,7,0
Movlw 0x55
Movwf EECON2, 0
Movlw 0xAA
Movwf EECON2, 0
Bcf PPSCON,0, BANKED
Movlw 0x00
Movwf RPINR16, BANKED 'Mapeo Puerto RP0=RX2 = RA0
Movlw 0X05
Movwf RPOR7, BANKED 'Mapeo Puerto RP1=TX2 = RA1
Movlw 0x55
Movwf EECON2, 0
Movlw 0xAA
Movwf EECON2, 0
Bsf PPSCON,0, BANKED
Bsf INTCON,7, 0
EndAsm
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
-
Hola,
Intentando todavia, que funcione el 2 Uart del PIC18F46J50 he borrado parte del Código ASM
por este otro pero de momento sigue sin funcionar.
Ayuda porfavor!!
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 todo digital
Dim Var1 As Byte
'---------------------------------------------------------------
'---- CONFIGURANDO USART2 ------------------------------------
'---------------------------------------------------------------
Dim IOLOCK As PPSCON.0
Dim INTCON_GIE As INTCON.7 'Desabilitor bit (GIEH)
Dim t_gie As Bit 'Guardo el estado de GIEH
t_gie = 0 'Pongo GIEH a 0 para desprotección PPS
t_gie = INTCON_GIE 'Guardo estado de GIE intr Bit y desactivo las interrupciones
INTCON_GIE = 0
'Desbloqueo PPS
EECON2 = $55 'Envio secuencia Para desbloquear la configuración PPS
EECON2 = $AA
IOLOCK = 0
'Mapeo los puertos
PPSCON.0=0 'Quito la protección de escritura de PPS
RPINR16=0 'PortA.0= RX2 Mapeo Puerto
RPOR1=5 'PortA.1= TX2 Mapeo Puerto
'Bloqueo PPS
EECON2 = $55 'Envio secuencia Para bloqueo configuración PPS
EECON2 = $AA
IOLOCK = 1
If t_gie = 1 Then INTCON_GIE = 1 'Habilito bit (GIEH)
'------------------------------------------------------------------
'------------------------------------------------------------------
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