News:

;) This forum is the property of Proton software developers

Main Menu

HRSout problem

Started by joesaliba, Nov 27, 2021, 08:22 PM

Previous topic - Next topic

joesaliba

As per the title, I spent around half a day with this HRSout on an 18F26K22. I think I never used HRSout on this device, and really I do not know what is going on.

At this time I am only doing some tests to a data terminal on a PC. As far as I know I set everything with regards to HRSout, however, the data that is going to the terminal is garbage.

After external oscillator, internal oscillator and had spent some good amount of time on this, I thought to replace HRSout with RSout to give it a try, and it worked!

So please, where am I missing the correct setup to make the hardware USART work as it should be?

Device = 18F26K22

Xtal = 16

osccon = %01110010

'===================================================================================================

Dim bMyArray[10] as Byte = "Hello"      ' Load the first 5 bytes of the array

Dim Li          As Byte = 102

'===================================================================================================

Declare TRIS_REVERSE = On           ' Handle the Read, Modify, Write differently
declare Dead_Code_Remove = 1        ' Remove dead code
Declare Optimiser_Level  = 2

Declare Hserial1_Baud = 19200
'Declare Hserial2_Baud = 19200

Declare Hserial1_Clear   = On        ' Clear overflow automatically
Declare Hserial1_Parity Even

'Declare Hserial2_Clear   = On        ' Clear overflow automatically
'Declare Hserial2_Parity Even
'Declare Hserial2_Terminator = CRLF

    Declare Serial_Baud = 19200
    Declare Rsout_Pin = PORTb.6
    Declare Rsout_Mode = 0
    Declare Rsout_Pace = 1000

'    Declare Rsin_Pin = PORTC.5
'    Declare Rsin_Mode = 1

'===================================================================================================
'*********************
'* Set Pic registers *
'*********************
'>>>Analog, comparators etc..<<<

PMD0   = %00111111      '
PMD1   = %10011111      '
PMD2   = %00001110      ' Enable / disable peripheral modules
                        ' Bit 0 = ADC module
                        ' Bit 1 = Comparator 1 module
                        ' Bit 2 = Comparator 2 module
                        ' Bit 3 = CTMU module
                        ' Bit 4 - 7 = Unimplemented

VREFCON0 = %00000000    ' Turn OFF VREF
CTMUCONH = %00000000    ' Turn OFF CTMU

HLVDCON = %00000000     ' Turn OFF HLVD
CM1CON0 = %00000000     ' Turn OFF comparators
CM2CON0 = %00000000     ' Turn OFF comparators

ADCON0  = %00000000     ' Disable analog on startup and select analog pins
ADCON1  = %00000000     ' Select VREF; Connected to internal signal AVDD / AVSS
ADCON2  = %10000011     ' Select FRC and right justify analog result

TRISA   = %00000000     ' Configure PORTB I/O
TRISB   = %10000000     ' Configure PORTB I/O
TRISC   = %10000001     ' Configure PORTB I/O

WPUB    = %00000000     ' Disable PORTB pull-up

ANSELA  = %00000000     ' Set analog / digital ports
ANSELB  = %00000000     ' Set analog / digital ports
ANSELC  = %00000000     ' Set analog / digital ports

INTCON  = %00000000
INTCON2 = %10000000     ' Disable all PORTB pull-ups; Bit 7 = 1
IOCB    = %00000000     ' Turn OFF all Interrupt On Change on PORTB

LATA = 0                ' Turn OFF PORTA
portb = 0
PORTC = 0

DelayMS 200             ' Stabilise PIC and wait for handheld to finish

PIR1 = %00000000
PIE1 = %00000000
PIE2 = %00000000

 RCSTA1     = %10010000 '%11010000 = 208; %10010000 = 144 ; Enable continuous receive
  RCSTA2     = %10010000 '%11010000 = 208; %10010000 = 144 ; Enable continuous receive

  TXSTA1     = %00100100
  TXSTA2     = %00000100

BAUDCON1 = %00001000 '(BAUDCON.5 = 1 is inverted; BAUDCON.5 = 0 is non-inverted)
BAUDCON2 = %00011000 '(BAUDCON.5 = 1 is inverted; BAUDCON.5 = 0 is non-inverted)

'===================================================================================================
'****************
'* Main routine *
'****************
'>>>Main routine<<<

Main:

hrsout "Hello"

rsout "Hello  "

'rsout dec li

delayms 500
high lata.0
delayms 500
low lata.0

GoTo Main

'===================================================================================================
'===================================================================================================
'**********************
'* Fuse Configuration *
'**********************

'---------------------------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config_Start
  FOSC = INTIO67     ;Internal oscillator bloc
  PLLCFG = OFF       ;Oscillator used directl
  PRICLKEN = ON      ;Primary clock enable
  FCMEN = OFF        ;Fail-Safe Clock Monitor disable
  IESO = OFF         ;Oscillator Switchover mode disable
  PWRTEN = ON        ;Power up timer enable
  BOREN = OFF        ;Brown-out Reset disabled in hardware and softwar
  BORV = 190         ;VBOR set to 1.90 V nomina
  WDTEN = OFF        ;Watch dog timer is always disabled. SWDTEN has no effect
  WDTPS = 32768      ;1:3276
  CCP2MX = PORTC1    ;CCP2 input/output is multiplexed with RC
  PBADEN = OFF       ;PORTB<5:0> pins are configured as digital I/O on Rese
  CCP3MX = PORTB5    ;P3A/CCP3 input/output is multiplexed with RB
  HFOFST = OFF       ;HFINTOSC output and ready status are delayed by the oscillator stable statu
  T3CMX = PORTC0     ;T3CKI is on RC
  P2BMX = PORTB5     ;P2B is on RB
  MCLRE = INTMCLR    ;RE3 input pin enabled; MCLR disable
  STVREN = ON        ;Stack full/underflow will cause Rese
  LVP = OFF          ;Single-Supply ICSP disable
  XINST = OFF        ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode
  DEBUG = OFF        ;Disable
  CP0 = OFF          ;Block 0 (000800-003FFFh) not code-protecte
  CP1 = OFF          ;Block 1 (004000-007FFFh) not code-protecte
  CP2 = OFF          ;Block 2 (008000-00BFFFh) not code-protecte
  CP3 = OFF          ;Block 3 (00C000-00FFFFh) not code-protecte
  CPB = OFF          ;Boot block (000000-0007FFh) not code-protecte
  CPD = OFF          ;Data EEPROM not code-protecte
  WRT0 = OFF         ;Block 0 (000800-003FFFh) not write-protecte
  WRT1 = OFF         ;Block 1 (004000-007FFFh) not write-protecte
  WRT2 = OFF         ;Block 2 (008000-00BFFFh) not write-protecte
  WRT3 = OFF         ;Block 3 (00C000-00FFFFh) not write-protecte
  WRTC = OFF         ;Configuration registers (300000-3000FFh) not write-protecte
  WRTB = OFF         ;Boot Block (000000-0007FFh) not write-protecte
  WRTD = OFF         ;Data EEPROM not write-protecte
  EBTR0 = OFF        ;Block 0 (000800-003FFFh) not protected from table reads executed in other block
  EBTR1 = OFF        ;Block 1 (004000-007FFFh) not protected from table reads executed in other block
  EBTR2 = OFF        ;Block 2 (008000-00BFFFh) not protected from table reads executed in other block
  EBTR3 = OFF        ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other block
  EBTRB = OFF        ;Boot Block (000000-0007FFh) not protected from table reads executed in other block
Config_End

'**** End of Fuse Configurator Settings ****
'---------------------------------------------------------------------------------------------------
'===================================================================================================

Pepe

Probe this



Device = 18F26K22

Xtal = 16



Declare TRIS_REVERSE = On           ' Handle the Read, Modify, Write differently
Declare Dead_Code_Remove = 1        ' Remove dead code
Declare Optimiser_Level  = 2

Declare Hserial_Baud = 19200
Declare Hserial2_Baud = 19200

Declare Hserial_Clear   = On        ' Clear overflow automatically
Declare Hserial2_Clear   = On

OSCCON = %01110010

'===================================================================================================
'*********************
'* Set Pic registers *
'*********************
'>>>Analog, comparators etc..<<<

PMD0   = %00111111      '
PMD1   = %10011111      '
PMD2   = %00001110      ' Enable / disable peripheral modules
                        ' Bit 0 = ADC module
                        ' Bit 1 = Comparator 1 module
                        ' Bit 2 = Comparator 2 module
                        ' Bit 3 = CTMU module
                        ' Bit 4 - 7 = Unimplemented

VREFCON0 = %00000000    ' Turn OFF VREF
CTMUCONH = %00000000    ' Turn OFF CTMU

HLVDCON = %00000000     ' Turn OFF HLVD
CM1CON0 = %00000000     ' Turn OFF comparators
CM2CON0 = %00000000     ' Turn OFF comparators

ADCON0  = %00000000     ' Disable analog on startup and select analog pins
ADCON1  = %00000000     ' Select VREF; Connected to internal signal AVDD / AVSS
ADCON2  = %10000011     ' Select FRC and right justify analog result

TRISA   = %00000000     ' Configure PORTB I/O
TRISB   = %10000000     ' Configure PORTB I/O
TRISC   = %10000001     ' Configure PORTB I/O

WPUB    = %00000000     ' Disable PORTB pull-up

ANSELA  = %00000000     ' Set analog / digital ports
ANSELB  = %00000000     ' Set analog / digital ports
ANSELC  = %00000000     ' Set analog / digital ports

INTCON  = %00000000
INTCON2 = %10000000     ' Disable all PORTB pull-ups; Bit 7 = 1
IOCB    = %00000000     ' Turn OFF all Interrupt On Change on PORTB

LATA = 0                ' Turn OFF PORTA
PORTB = 0
PORTC = 0

DelayMS 200             ' Stabilise PIC and wait for handheld to finish

PIR1 = %00000000
PIE1 = %00000000
PIE2 = %00000000

  RCSTA1     = %10010000 '%11010000 = 208; %10010000 = 144 ; Enable continuous receive
  RCSTA2     = %10010000 '%11010000 = 208; %10010000 = 144 ; Enable continuous receive

  TXSTA1     = %00100100
  TXSTA2     = %00100100


'===================================================================================================
'****************
'* Main routine *
'****************
'>>>Main routine<<<

Main:

HRSOut "Hello"
HRSOut2 "Hello  "


DelayMS 500
High LATA.0
DelayMS 500
Low LATA.0

GoTo Main

'---------------------------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config_Start
  FOSC = intio67     ;Internal oscillator bloc
  PLLCFG = OFF       ;Oscillator used directl
  PRICLKEN = On      ;Primary clock enable
  FCMEN = OFF        ;Fail-Safe Clock Monitor disable
  IESO = OFF         ;Oscillator Switchover mode disable
  PWRTEN = On        ;Power up timer enable
  BOREN = OFF        ;Brown-out Reset disabled in hardware and softwar
  BORV = 190         ;VBOR set to 1.90 V nomina
  WDTEN = OFF        ;Watch dog timer is always disabled. SWDTEN has no effect
  WDTPS = 32768      ;1:3276
  CCP2MX = PORTC1    ;CCP2 input/output is multiplexed with RC
  PBADEN = OFF       ;PORTB<5:0> pins are configured as digital I/O on Rese
  CCP3MX = PORTB5    ;P3A/CCP3 input/output is multiplexed with RB
  HFOFST = OFF       ;HFINTOSC output and ready status are delayed by the oscillator stable statu
  T3CMX = PORTC0     ;T3CKI is on RC
  P2BMX = PORTB5     ;P2B is on RB
  MCLRE = INTMCLR    ;RE3 input pin enabled; MCLR disable
  STVREN = On        ;Stack full/underflow will cause Rese
  LVP = OFF          ;Single-Supply ICSP disable
  XINST = OFF        ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode
  Debug = OFF        ;Disable
  Cp0 = OFF          ;Block 0 (000800-003FFFh) not code-protecte
  CP1 = OFF          ;Block 1 (004000-007FFFh) not code-protecte
  CP2 = OFF          ;Block 2 (008000-00BFFFh) not code-protecte
  CP3 = OFF          ;Block 3 (00C000-00FFFFh) not code-protecte
  CPB = OFF          ;Boot block (000000-0007FFh) not code-protecte
  CPD = OFF          ;Data EEPROM not code-protecte
  WRT0 = OFF         ;Block 0 (000800-003FFFh) not write-protecte
  WRT1 = OFF         ;Block 1 (004000-007FFFh) not write-protecte
  WRT2 = OFF         ;Block 2 (008000-00BFFFh) not write-protecte
  WRT3 = OFF         ;Block 3 (00C000-00FFFFh) not write-protecte
  WRTC = OFF         ;Configuration registers (300000-3000FFh) not write-protecte
  WRTB = OFF         ;Boot Block (000000-0007FFh) not write-protecte
  WRTD = OFF         ;Data EEPROM not write-protecte
  EBTR0 = OFF        ;Block 0 (000800-003FFFh) not protected from table reads executed in other block
  EBTR1 = OFF        ;Block 1 (004000-007FFFh) not protected from table reads executed in other block
  EBTR2 = OFF        ;Block 2 (008000-00BFFFh) not protected from table reads executed in other block
  EBTR3 = OFF        ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other block
  EBTRB = OFF        ;Boot Block (000000-0007FFh) not protected from table reads executed in other block
Config_End

'**** End of Fuse Configurator Settings ****
'---------------------------------------------------------------------------------------------------
'===================================================================================================

joesaliba

Thanks Pepe,

Seems to be working. It was something to do with BAUDCON. I will investigate which bit I altered to make it stop.

Joe

joesaliba

Looks that I was forcing BAUDCON.3 to use BRG16 at 16-bit Baud Generator, but it must have been 8-bit Baud Generator.