News:

Let's find out together what makes a PIC Tick!

Main Menu

Is there a problem with HSerial_ChangeBaud

Started by RGV250, Today at 07:22 PM

Previous topic - Next topic

RGV250

Hi,
I have tried everything I can think of but this just does not work for me.
I am trying to get the serial display from here to work with 18F25K20 for the LCD side.
https://protoncompiler.com/index.php/topic,2116.msg16269.html#msg16269

It works fine if I set the BAUD rate directly Declare Hserial_Baud = 19200 but if I use ChangeBaud after it does not work even if the rate is what I am in theory changing it to.
This could be a VSM issue but I thought I would ask first.
The original code had brackets around the value where the example in the manual does not, both compile OK but neither work.
This is the code with everything stripped out, very minimal changes to the original.
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A simple Serial LCD using the USART of the device.
'
' Written for the Positron8 BASIC compiler by Les Johnson.
'
     Include "Amicus18.inc"

;-------------------------------------------------------------------------------

    Declare Watchdog = On                               ' Tell the compiler that the watchdog timer is enabled
'
' Setup USART1
'
'   This instruction is normally in the Amicus.inc file !!!
'   Copied here to make it easier to change.
    Declare Hserial_Baud = 19200                        ' Set the Baud rate
    Declare HRSOut1_Pin = PORTC.6                       ' Tell the compilr what pin to use for the USART TX
    Declare HRSIn1_Pin = PORTC.7                        ' Tell the compilr what pin to use for the USART RX
'
' Setup the LCD
'
    Declare LCD_Data4_Pin = PORTC.0                     ' Connect PORTC.0 to the LCD's D4 line
    Declare LCD_Data5_Pin = PORTC.1                     ' Connect PORTC.1 to the LCD's D5 line
    Declare LCD_Data6_Pin = PORTC.2                     ' Connect PORTC.2 to the LCD's D6 line
    Declare LCD_Data7_Pin = PORTC.3                     ' Connect PORTC.3 to the LCD's D7 line
    Declare LCD_ENPin = PORTA.0                         ' Connect PORTA.0 to the LCD's EN line
    Declare LCD_RSPin = PORTA.1                         ' Connect PORTA.1 to the LCD's RS line
    Declare LCD_Interface = 4                           ' Use a 4-line interface to the LCD
    Declare LCD_Lines = 2                               ' Tell the compiler that the LCD has two lines
    Declare LCD_Type = Alphanumeric                     ' Tell the compiler that the LCD is a Hitachi alphanumeric type
    Declare LCD_CommandUs = 2000                        ' Delay for 2000us bewtwwen sending command bytes to the LCD
    Declare LCD_DataUs = 50                             ' Delay for 50us bewtwwen sending data bytes to the LCD

' If either of these are enabled
 '   HSerial1_ChangeBaud 19200
 '   HSerial1_ChangeBaud(19200)   
    Dim ByteIn As Byte                                  ' Holds the received byte to send to the LCD

'------------------------------------------------------------------------------------------------
' The main program starts here
' Wait in a loop and send bytes received via the USART directly to the LCD
'
Main:
    Setup()                                             ' Setup the program and any peripherals

    Do 
        ByteIn = HRSIn1, {1024, Continue}               ' Receive a byte serially into ByteIn, with a timeout of approx 1 second
        Print ByteIn                                    ' Send the byte received to the LCD
        HRSOut1  ByteIn
    Loop                                                ' Do it forever

'------------------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : PinMode is only available on the devices that can control pull-up resistors on individual pins.
'
Proc Setup()
    HRSOutLn ""                                         ' Transmit a dummy byte to settle the PPS and the USART
    Cls                                                 ' Clear the LCD's display
    Print At 1, 1, "    Positron    ",                  ' \
          At 2, 1, " Serial LCD 1.0 "                   ' / Transmit a start-up message on the LCD
    DelayMS 1000
    Cls
EndProc


Regards,
Bob

John Lawton

You are including Amicus.inc which has these lines in it:

    Device = 18F25K20
    Declare Xtal = 64

    Declare Hserial_Baud = 9600                 ' Set the Baud rate
    Declare Hserial_Clear = 1                   ' Enable Error clearing on received characters

I'm not sure that matters though?

John
-----------------------------------------------------------------------------------------
Amicus 8 and 16A/16B dev boards
Especially created for Positron development
https://www.easy-driver.co.uk/Amicus

RGV250

#2
Hi John,
I commented out the set baud one and moved it to the main file so it is easier to change.

I also added a hserout so I could see what was being received and it does not send anything if I use change baud. Something is being sent as the display shows rubbish or just blocks.

Bob