Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Lists to simulate databases (OshonSoft Basic).

Status
Not open for further replies.

DogFlu66

Member
Hello; for those who need or want to experiment with lists, I leave you some libraries.
With these libraries it is possible to simulate small databases, with all its elements for its control, such as creation, search, substitution, deletion of records, etc.

For example: by adding a small menu (display and keyboard) you can manage the list of telephone numbers for access control with a garage door by adding the control of a gsm module, or also with radio modules.

To work with lists efficiently you need to use pointers. So I leave in the example how to get the memory address of a variable at runtime.

For any questions you can ask.



Code:
'************************************************
'Working with list.
'Assignment of pointers to variables.
'12/01/2023, By COS, PSI V4.34.
'************************************************
Include "_FuncionesListas.bas"
'String Variables.
Dim m1 As String
Dim m2 As String
Dim m3 As String
Dim m4 As String
'Declares vector of vectors (list).
Dim m0(51) As Byte
'Pointer variables, two bytes long.
Dim p_m0 As Word
Dim p_m1 As Word
Dim p_m2 As Word
Dim p_m3 As Word
Dim p_m4 As Word
'Aux. variables.
Dim n0 As Byte
Dim n1 As Byte
Dim n2 As Byte
Dim n3 As Byte
Dim n4 As Byte
Dim p_aux As Word
'Assign values.
m1 = "0123456789"
m2 = "9876543210"
m3 = "ABCDE"
m4 = "FGHIJKLMN"
'Pointer:
Dim _ADDRESS As Word  'Variable de paso
Symbol _Address_HB = _ADDRESS.HB
Symbol _Address_LB = _ADDRESS.LB
'Pointer assignment.
ASM:        LFSR 2,m0
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m0 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m1
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m1 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m2
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m2 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m3
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m3 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m4
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m4 = _ADDRESS
'*************************************************
Call _vstrformat(p_m0, 51)  'Format the list.
n0 = _vstrlong(p_m0)  'Number of ascii characters that the list can contain.
n1 = _vstrfree(p_m0)  'Number of free characters.
Call _vstradd(p_m0, p_m1)  'Add string
Call _vstradd(p_m0, p_m2)  'Add string
Call _vstradd(p_m0, p_m3)  'Add string
Call _vstradd(p_m0, p_m4)  'Add string
n3 = _vstrlong(p_m0)  'List lengts.
n4 = _vstrfree(p_m0)  'Number of free characters.
p_aux = _vstrcmp2(p_m0, p_m2)  'Search string
If p_aux > 0 Then Call _vstrsub(p_aux)  'Delete string and update list.
End
 

Attachments

  • _FuncionesListas.bas
    17.2 KB · Views: 298
Last edited:
It's really fun to see how the value registers change when the simulation is activated.
 

Attachments

  • Watch_Variables.jpg
    Watch_Variables.jpg
    372.2 KB · Views: 271
I leave you a second more complete example, with the result of your simulation:

Code:
'******************************************************
'Working with lists using pointers (12bit)
'01/2023, By COS, PSI V4.34.
'******************************************************
'Ejemplo_Lista_02
'******************************************************
Include "_FuncionesListas.bas"
UART_Init 4800
'String variables
Dim Str0 As String
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
'List
Dim List(51) As Byte  'Declares array of strings (List)
'Pointer Variables
'Will point to the first memory address of the vector.
Dim P_Str0 As Word
Dim P_Str1 As Word
Dim P_Str2 As Word
Dim P_Str3 As Word
Dim P_List As Word
Dim p_aux As Word
'Aux. variables
Dim n0 As Byte
Dim n1 As Byte
Dim n2 As Byte
Dim n3 As Byte
Dim n4 As Byte
'Pointer assignments
Dim _address As Word  'Value pass variable
Symbol _Address_HB = _address.HB
Symbol _Address_LB = _address.LB
'Pointer assignment
ASM:        LFSR 2,List
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
P_List = _address  '-> List
'Asignación puntero
ASM:        LFSR 2,Str0
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
P_Str0 = _address  '-> Str0
'Asignación puntero
ASM:        LFSR 2,Str1
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
P_Str1 = _address  '-> Str1
'Asignación puntero
ASM:        LFSR 2,Str2
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
P_Str2 = _address  '-> Str2
'Asignación puntero
ASM:        LFSR 2,Str3
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
P_Str3 = _address  '->Str3
'Assigning values to string
Str0 = "0123456789"
Str1 = "9876543210"
Str2 = "ABCDE"
Str3 = "FGHIJKLMN"
'*************************************************
main:
    Call _vstrformat(P_List, 51)  'Format de list.
    Call _vstradd(P_List, P_Str0)  'Add the string Str0 to the list.
    Call _vstradd(P_List, P_Str1)  'Suma el string Str1
    Call _vstradd(P_List, P_Str2)  'Suma el string Str2
    Call _vstradd(P_List, P_Str3)  'Suma el string Str3
    Hserout "List has ", #_vstrlen(P_List), " String named from 0 to ", #(_vstrlen - 1), CrLf
    Call _VStrOut(P_List, _vstrlen(P_List))  'Send the list to the serial port.
    Hserout "Maximum length of the list: ", #_vstrlong(P_List), CrLf  'Maximum length of the list.
    Hserout "Free characters: ", #_vstrfree(P_List), Lf, CrLf  'Number of free ASCII characters in the list.

    p_aux = _vstrcmp2(P_List, P_Str1)  'Search string
    If p_aux > 0 Then Call _vstrsub(p_aux)  'Delete string and update list.
    Hserout "Delete String 1 and update list: ", Str1, CrLf
    Hserout "List has ", #_vstrlen(P_List), " String named from 0 to ", #(_vstrlen - 1), CrLf
    Call _VStrOut(P_List, _vstrlen(P_List))  'Send the list to the serial port.
    Hserout "Maximum length of the List: ", #_vstrlong(P_List), CrLf  'Maximum length of the list
    Hserout "Free characters: ", #_vstrfree(P_List), Cr, CrLf  'Number of free ASCII characteres

'Goto main
End                                               
'Sends a list to the serial port.
'_address = address of the first item in the list.
'_len = number of string in the list, first string is 0.
Proc _VStrOut(_address As Word, _len As Word)
    Dim char As Byte
    Dim _n As Word
    CFor (_n = 0; _n < _len; _n++)  'Repeart to many vector there are.
        char = Pointer(_address)  'First element of the string.
        While char <> 0  'Until reaching the end of then string.
            Hserout char  'Send to the serial port.
            _address++  'Next character.
            char = Pointer(_address)  'Assign the charracter.
            If char == 0 Then  'If it is the end of string.
                Hserout CrLf  'Beginning and new line.
                _address++  'First element of then following string.
            Endif
        Wend
    CNext
End Proc

Ejemplo_02.jpg
 
Hello; for those who need or want to experiment with lists, I leave you some libraries.
With these libraries it is possible to simulate small databases, with all its elements for its control, such as creation, search, substitution, deletion of records, etc.

For example, by adding a small menu (display and keyboard) you can manage the list of telephone numbers for access control with a garage door by adding the control of a gsm module, or also with radio modules.

To work with lists efficiently you need to use pointers. So I leave in the example how to get the memory address of a variable at runtime.

For any questions you can ask.



Code:
'************************************************
'Working with list.
'Assignment of pointers to variables.
'12/01/2023, By COS, PSI V4.34.
'************************************************
Include "_FuncionesListas.bas"
'String Variables.
Dim m1 As String
Dim m2 As String
Dim m3 As String
Dim m4 As String
'Declares vector of vectors (list).
Dim m0(51) As Byte
'Pointer variables, two bytes long.
Dim p_m0 As Word
Dim p_m1 As Word
Dim p_m2 As Word
Dim p_m3 As Word
Dim p_m4 As Word
'Aux. variables.
Dim n0 As Byte
Dim n1 As Byte
Dim n2 As Byte
Dim n3 As Byte
Dim n4 As Byte
Dim p_aux As Word
'Assign values.
m1 = "0123456789"
m2 = "9876543210"
m3 = "ABCDE"
m4 = "FGHIJKLMN"
'Pointer:
Dim _ADDRESS As Word  'Variable de paso
Symbol _Address_HB = _ADDRESS.HB
Symbol _Address_LB = _ADDRESS.LB
'Pointer assignment.
ASM:        LFSR 2,m0
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m0 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m1
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m1 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m2
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m2 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m3
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m3 = _ADDRESS
'Asignación puntero
ASM:        LFSR 2,m4
ASM:        MOVFW FSR2H
ASM:        MOVWF _Address_HB
ASM:        MOVFW FSR2L
ASM:        MOVWF _Address_LB
p_m4 = _ADDRESS
'*************************************************
Call _vstrformat(p_m0, 51)  'Format the list.
n0 = _vstrlong(p_m0)  'Number of ascii characters that the list can contain.
n1 = _vstrfree(p_m0)  'Number of free characters.
Call _vstradd(p_m0, p_m1)  'Add string
Call _vstradd(p_m0, p_m2)  'Add string
Call _vstradd(p_m0, p_m3)  'Add string
Call _vstradd(p_m0, p_m4)  'Add string
n3 = _vstrlong(p_m0)  'List lengts.
n4 = _vstrfree(p_m0)  'Number of free characters.
p_aux = _vstrcmp2(p_m0, p_m2)  'Search string
If p_aux > 0 Then Call _vstrsub(p_aux)  'Delete string and update list.
End
Hi D,
I'm very interested in this, but I'm busy just now, I'll watch your thread, and try to join in later.
Cheers, C.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top