News:

;) This forum is the property of Proton software developers

Main Menu

Forcing cdata to an address on a 12f device

Started by TimB, Jul 03, 2024, 10:02 AM

Previous topic - Next topic

TimB


Hi All

I'm trying to write some PM (permanent memory) routines for a Pic12f1572.

Part of the testing I need to force some data into the PM code area at compile time so I can test if erase works.

I tried
Org 0X7F0
Cdata x,x,x,x

But the compiler said cannot do that with Optimisation on
Then turned that off and it said cannot do that with procedures

Is there another way to force data into program code space?

Thanks
Tim

trastikata


TimB


Thanks

The warning Error Les issued is valid, The compiler adds the data inline before the subs then the assembler just shifts the code above my ORG statement

I got it kind of working by turning off the optimiser and not using procs

But not ideal

Tim

top204

#3
Here you go Tim:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Read Flash Memory data using the CData directive at a particular address, and with the default optimiser enabled and using procedures.
' For use on a PIC12F1572 device.
'
' Written by Les Johnson for the Positron8 BASIC compiler.
'
    Device = 12F1572                                ' Tell the compiler what device to compile for
    Declare Xtal = 32                               ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Setup the bit-bashed serial out
'
    Declare Serial_Baud = 9600
    Declare RSOut_Pin   = PORTA.4
    Declare RSOut_Mode  = 0
    Declare RSOut_Pace  = 1000
'
' Create any global variables here
'
    Dim bFlashOffset As Byte                        ' Holds an offset to the flash memory address
    Dim MyByte       As Byte                        ' Holds the byte read from flash memory

'--------------------------------------------------------------------------------------------------
' The main program starts here
'
Main:
    Setup()                                         ' Setup the program and any variables and peripherals

    For bFlashOffset = 0 To 9                       ' Create a loop for the address offset
        MyByte = Cread8 DataTable[bFlashOffset]     ' Read the data from flash memory
        RSoutLn "bFlashOffset: ", Dec bFlashOffset, ' \ Transmit the data read to a serial terminal
                " = ", IHex2 MyByte                 ' /
    Next                                            ' Close the loop

'--------------------------------------------------------------------------------------------------
' Setup the program and any variables and peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    OSCCON = %01110000                              ' Setup the device for internal clock at 8MHz
    DelayMs 100                                     ' Wait for the oscillator to stabilise
EndProc

'--------------------------------------------------------------------------------------------------
' Place the CData table at the end of flash memory
'
@   _Save_PC_ Equ $                                 ' Save the Program Counter in an assembler variable
'
' Place Flash Memory data at address $07F0
'
@    Org 0x07F0
DataTable: CData 10, 11, 12, 13, 14, 15, 16, 17, 18, 19

@    Org _Save_PC_                                  ' Restore the Program Counter from an assembler variable

'-----------------------------------------------------------------------------------------
' Setup the fuses for internal oscillator with 4xPLL enabled on a PIC12F1572 device.
' With the OSC pins set as I/O pins.
'
    Config1 FOSC_INTOSC,_                           ' Internal oscillator. I/O function on CLKIN pin
            WDTE_OFF,_                              ' Watchdog Timer disabled
            PWRTE_OFF,_                             ' Power-up Timer disabled
            MCLRE_ON,_                              ' MCLR/VPP pin function is MCLR
            CP_OFF,_                                ' Program memory code protection is disabled
            BOREN_ON,_                              ' Brown-Out Reset enabled
            CLKOUTEN_OFF                            ' CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin

    Config2 WRT_OFF,_                               ' Flash Memory Self-Write Protection disabled
            PLLEN_ON,_                              ' 4xPLL enabled
            STVREN_ON,_                             ' Stack Overflow or Underflow will cause a Reset
            BORV_LO,_                               ' Brown-Out Reset Voltage, low trip point selected
            LPBOREN_OFF,_                           ' Low Power Brown-Out Reset disabled
            LVP_OFF                                 ' High voltage on MCLR/VPP must be used for programming

On the serial terminal, it will display:

bFlashOffset: 0 = $0A
bFlashOffset: 1 = $0B
bFlashOffset: 2 = $0C
bFlashOffset: 3 = $0D
bFlashOffset: 4 = $0E
bFlashOffset: 5 = $0F
bFlashOffset: 6 = $10
bFlashOffset: 7 = $11
bFlashOffset: 8 = $12
bFlashOffset: 9 = $13

If you look in the assembler code produced, it will show:

    _SAVE_PC_ equ $
     org 0X07F0
DataTable
    dt 10,11,12
    dt 13,14,15
    dt 16,17,18
    dt 19
     org _SAVE_PC_

This shows that the current Program Counter position is saved in the assembler variable '_SAVE_PC_', then the flash memory data table is created, then the Program Counter position is restored to where it was before the assembler flash memory data directives were placed.