News:

;) This forum is the property of Proton software developers

Main Menu

Mixed basic and assembly code for a 12F1840

Started by keytapper, Feb 23, 2022, 05:30 AM

Previous topic - Next topic

keytapper

Hi forum,
I'm study a kind of optimization for a 12F1840, so I supposed to set the indirect addressing for a fast indexing on a buffer. I haven't yet test the program but I doubt it will work.
This is the procedure
Proc calcCS(pointer as Word, length as byte),Bit
' pointer is a Word pointing to the RAM data
' length is the size of memory to scan

  Result = FALSE                     ' Initial setting to no good
  Dim bufpntr as FSR0L.Word          ' setting indirect addressing
  bufpntr = pointer                  ' getting the address
  Repeat                             ' Start the loop
    ck_a = ck_a + INDF0              ' read the bytes
    ck_b = ck_b + ck_a               ' calculate it
    inc bufpntr                      ' next position
    dec length                       ' one less to count
  until length <= 0                  ' until completion
  If ck_a = INDF0 Then               ' first checksum byte
    inc bufpntr                      ' point to next
    If ck_b = INDF0 Then             ' match ?
      Result = TRUE                  ' set the answer
    End If
  End If
EndProc                              ' value will return accordingly
Just a procedure to use the Fletcher Algorithm for a GPS data.
But it seems that one of the two block of memory are across the bank.
So should I use the virtual memory addressing? Which will consist of set the FSRnH.5 at 1 (Reading DS40001441F-page 31). But IIRC the initial addressing will be reduced to zero, so displaced of -32 bytes.

Furthermore, I like to read the assembler, but I don't see any use of the INDF1. My idea was to make a fast memory comparison. So one set will look to RAM incoming data e the second set will compare with the program data. Obviously I'm triggered of a bit more than basic code  ;D
Any input will be appreciated.
Ignorance comes with a cost

top204

#1
The FSR1L, FSR1H and INDF1 SFRs are used occasionally by the compiler when an array is loaded with another array. So they can keep hold of their address'

You can slim down the procedure a bit more if you change the "pointer" parameter to use the FSR0L\H pair as an alias:

Dim wFSR0 As FSR0L.Word

Proc calcCS(pointer as wFSR0, length as byte), Bit


Then remove the "bufpntr" variable and increment the "pointer" parameter instead. It's such a shame that Microchip did not add the POSTxxx and PRExxx SFRs with INDF0 and INDF1 on the enhanced 14-bit core devices, as they have in 18F devices. Instead they have new mnemonics such as Moviw and Movwi for auto address incrementing and decrementing with INDF0 and INDF1.

I would strongly advise moving to an 18F device because of your detailed interest in the device architecture, because they are so much nicer and more refined, and more pleasing to use. :-) And the new 18Fx4Qxx and 18Fx5Qxx and 18Fx6Qxx devices that I am adding to the compiler are really nice!!!! They have even surprised me as to how nice they are. LOL

acel

18Fx4Qxx and 18Fx5Qxx and 18Fx6Qxx what are the most obvious differences in these devices?

top204

#3
Take a look at their data sheet and you will see that they are:

Small in Size :-)
Have up to 64K of flash, but this can be increased to 128K of flash.
Have 4096 bytes of RAM, but with the design of the Q devices, this can increase a lot with future devices. Some of the current 18F27Qxx devices, that the compiler supports, have 13K of RAM.
Have a 12-bit ADC.
Have one, two or more 8-bit DACs. Two of these can easily be combined to make a 16-bit DAC, with a few resistors and a clever bit of coding. :-)
Have Hardware USARTs, SPI, I2C, CCP, NCO and CWG. Along with many other peripherals.

And at the moment, they are very inexpensive.

The size is what really matters for me. For years I have asked why there were no small package 18F devices available. All the small devices are 14-bit core types that have tiny amounts of RAM and flash, and if a person wanted more memory, they had to buy a large 18F device, even when most of it would be wasted!

Frizie

Just what I was looking for for a new project I'll be starting soon: 5 UARTs  :)
Ohm sweet Ohm | www.picbasic.nl

Dompie

Quote from: Frizie on Feb 23, 2022, 05:43 PMJust what I was looking for for a new project I'll be starting soon: 5 UARTs  :)

YES but also 950!! pages of datasheet  :(  :(

Johan

keytapper

Thanks Mr. Les for your tips.
I think that 18F family are a lot ahead, and a long learning time. It took me several year to get geared with midrange family MCU and a bunch of stock. My development won't finish my stock for a long time  :'(  :(
Ignorance comes with a cost