News:

;) This forum is the property of Proton software developers

Main Menu

Cannot get 16F1705 to work in ISIS

Started by JohnB, Aug 20, 2023, 05:35 PM

Previous topic - Next topic

JohnB

Can you help me setting up PIC16F1705

'***************************************************************************************************
' Name      :  MatrixDisplayDriver.bas                                                             *
' Author    :  John Barrat                                                                         *
' Copyright :  Copyright   2023 John Barrat                                                        *
' Version   :  0.0.0.0                                                                             *
'***************************************************************************************************

  Device = 16F1705
  Declare Xtal = 32

  Declare Optimiser_Level = 3
  Declare Dead_Code_Remove = On
  declare create_coff = true

  $define True 1
  $define False 0

  Declare Bootloader = 0
  Declare HRSOut_Pin     = PORTC.4
  Declare HRSIn_Pin      = PORTC.5
  Declare Hserial_Baud   = 19200           ' Set baud rate to 19200
  Declare Hserial_RCSTA  = %10010000       ' Enable serial port and continuous receive
  Declare Hserial_TXSTA  = %00100100       ' Enable transmit and asynchronous mode
  Declare Hserial_Clear  = On              ' Enable Error clearing on received characters      ' Clear the buffer before receiving

'  $define Max2719_SDA_Pin PortC.2         ' Matrix Display Data
'  $define Max2719_CS_Pin  PortC.1         ' Matrix Display Chip Select
'  $define Max2719_CLK_Pin PortC.0         ' Matrix Display Clock

'  $define Display_Count 4 ' number of 8x8 displays
'  $define Text_len 5      ' length of text

  Dim TempVal As Word
  Dim TempStr as STring*3
  Dim TmpB1 as byte
  Dim TmpB2 As byte

'  Include "MaxMatrixStatic.inc"

SetUp:

  PPS_UnLock()
  RXPPS = 0x15  'RC5 to RX input EUSART
  RC4PPS = 0x14 'TX Output from EUSART to RC4
  PPS_Lock()

  ' setup intosc for 32MHz
  OSCCON = $F2   ' 4*PPL on, 32MHz, Internal

  TRISA   = %00000000   ; ALL OUTPUT
  TRISC   = %00010000   ; RC4 is RX

  HSerOut [0x20]        ' Not sure this is necessary as not using buffered receive

DelayMS 1000

Start:
'  MaxMatrixInit()

Main:
  HRSOutLn "Hello"
  Do
    TmpB1 = HrsIn {1000,TimeOut}
    HrsOut TmpB1
Timeout:
    HrsOutLn "Waiting"
  loop


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

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PPS1WAY_OFF, ZCDDIS_OFF, PLLEN_ON, STVREN_ON, BORV_LO, LPBOR_OFF, LVP_OFF

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

It gets as far as Hello but nothing happens after that - doesnt echo any characters I type in the Virtual Terminal nor does it timeout.

I have checked the PPS settings and I am pretty confident I have them right although when it comes to PPS you can ever be wholly sure. Even if I am not receiving data correctly why is it not generating a timeout message?

Any help would be appreciated.  I have attached the ISIS model I am using.
JohnB

top204

#1
Try this John:

'***************************************************************************************************
' Name      :  MatrixDisplayDriver.bas                                                             *
' Author    :  John Barrat                                                                         *
' Copyright :  Copyright   2023 John Barrat                                                        *
' Version   :  0.0.0.0                                                                             *
'***************************************************************************************************

  Device = 16F1705
  Declare Xtal = 32

  Declare Optimiser_Level = 3
  Declare Dead_Code_Remove = On
  Declare Create_Coff = true

  $define True 1
  $define False 0

  Declare HRSOut_Pin     = PORTC.4
  Declare HRSIn_Pin      = PORTC.5
  Declare Hserial_Baud   = 19200           ' Set baud rate to 19200

'  $define Max2719_SDA_Pin PortC.2         ' Matrix Display Data
'  $define Max2719_CS_Pin  PortC.1         ' Matrix Display Chip Select
'  $define Max2719_CLK_Pin PortC.0         ' Matrix Display Clock

'  $define Display_Count 4 ' number of 8x8 displays
'  $define Text_len 5      ' length of text

  Dim TempVal As Word
  Dim TempStr as STring*3
  Dim TmpB1 as byte
  Dim TmpB2 As byte


SetUp:
    'PPS_UnLock()
    'RXPPS = 0x15  'RC5 to RX input EUSART
    'RC4PPS = 0x14 'TX Output from EUSART to RC4
    'PPS_Lock()

    ' setup intosc for 32MHz
    OSCCON = $F2            ' 4*PPL on, 32MHz, Internal

    TRISA   = %00000000   ' ALL OUTPUT
    'TRISC   = %00010000   ' RC4 is RX

    'HSerOut [0x20]        ' Not sure this is necessary as not using buffered receive

    DelayMS 1000

Start:
'  MaxMatrixInit()

Main:
  HRSOutLn "Start"
  Do
Again:
    TmpB1 = HrsIn, {10000, TimedOut}
    HrsOut TmpB1
  Loop

TimedOut:
    HrsOutLn "Timed Out"
    Goto Again

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

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PPS1WAY_OFF, ZCDDIS_OFF, PLLEN_ON, STVREN_ON, BORV_LO, LPBOR_OFF, LVP_OFF

'**** End of Fuse Configurator Settings ****

I've just tested it in Isis 8.16 and it is working as it should.

The compiler will calculate the RCSTA and TXSTA SFR values based upon the Baud and the device's operating frequency, because Microchip have changed what they require in some devices and the compiler adapts its setup code for what a particular device requires. It will also calculate the Baud generator's value from the "Hserial_Baud" declare for you. It will also setup the PPS (Peripheral Pin Select) for the pins chosen in the TX and RX port . pin declares for USART1, and USART2 and USART3 etc...

The HRsin will not timeout because it was missing the comma, and that is my fault in the compiler's syntax checking and the manual, so I will correct it so it will timeout with or without the comma after the HRSin command if the curly braces are found with the timeout value and label in them.

I've changed the program's layout a little, so it exits the loop only if a timeout occurs and not after any character is received as your original program would have done. :-)