News:

;) This forum is the property of Proton software developers

Main Menu

PIC12F683 a way to load Dword to an array

Started by JackB, Dec 20, 2024, 11:28 PM

Previous topic - Next topic

JackB

Hello everyone,

a simple question, about array in general using a 12F683 since this Pic is not supported for string.

is it possible to load a byte array with a DWord value "4294967295"

array element   0   1   2   3   4   5   6   7   8   9 

value           4   2   9   4   9   6   7   2   9   5


Thanks for any comments.


Frizie

If a WORD array (not DWORD) works in a 12F683, then you could split the DWORD first in two WORDS with Variable.LOWWORD and Variable.HIGHWORD.
Ohm sweet Ohm | www.picbasic.nl

trastikata

Hi Frizie,

I think he meant loading a Byte array with the ASCII values for each digit index in the Dword.

Device 12F683     
Declare Xtal = 4

Dim dwTemp As Dword         'Temporary Dword variable
Dim baString[10] As Byte    'Byte array to hold the output string

Main:
    Clear                   'Reset
    dwTemp = 4294967295     'Load some value to dwTemp
    DwordToString(dwTemp)   'Convert dwTemp to string and place it into baString array
End


Proc DwordToString(dwData As dwTemp)
    Dim bCounter As Byte 
    Dim bTemp As Byte
   
    Clear baString                      'Reset baString
    For bCounter = 0 To 9               'Loop through dwData
        bTemp = Dig dwData,bCounter     'Get digit indexed by bCounter
        baString[bCounter] = bTemp + 48 'Load digit value as ASCII code
    Next
EndProc

trastikata

If you want to extract only the relevant digits in a umber without running through all 9 array elements, this code could be faster when working with smaller numbers because it will exit the loop when no more relevant digits were to extract.

Device 12F683     
Declare Xtal = 4

Dim dwTemp As Dword         'Temporary Dword variable
Dim baString[10] As Byte    'Byte array to hold the output string

Main:
    Clear                   'Reset
    dwTemp = 4294967295     'Load some value to dwTemp
    DwordToString(dwTemp)   'Convert dwTemp to string and place it into baString array
End


Proc DwordToString(dwData As dwTemp)
    Dim bCounter As Byte
    Dim bTemp As Byte
   
    Clear baString                      'Reset baString
    bCounter = 0                        'Reset bCounter
    While dwData > 0                    'Extract only relevant digits
        bTemp = dwData // 10
        baString[bCounter] = bTemp + 48
        dwData = dwData / 10
        Inc bCounter 
    Wend
EndProc

JackB

Hello trastikata,

you realy help me with this function, I read about function about 35 years ago
with VB and did not catch the real potential.

I understand somehow the effect/result of it.

with time on my side I'll start learning about function.

I recal with VB, it had Sub Private & Sub Public function, I guess with Positron it use Private for now.

Many thanks