News:

Let's find out together what makes a PIC Tick!

Main Menu

Nextion HMI boards

Started by JohnB, Jun 14, 2022, 01:55 AM

Previous topic - Next topic

top204

#20
The new PIC18FxxQ83 devices that are in the coming compiler "upgrade", have 12,800 bytes of RAM, and most of the newer 18F types have approx 8K of RAM, so memory is not going to be a big problem. :-) This will be the normal amount with most new 18F devices, and the enhanced 14-bit core types are also increasing their RAM size.

The use of global variables or SFRs (Special Function Registers) being used as aliases of parameters in a library's procedures is why I added the feature to the compiler, so they can be placed in specific areas when created. i.e. Access or Heap. This gives a lot more control over the code's operation, and makes it more compact and faster to operate.

For example, let's say we have a library to control LEDs. The specific global variables that will be used repeatedly within the library's procedures can have the prefix of "LED_" added to them, so they do not get duplicated in other libraries:

Dim LED_bAlwaysUsed1 As Byte
Dim LED_bAlwaysUsed2 As Byte


Proc LED_Light(pNum As LED_bAlwaysUsed1), LED_bAlwaysUsed2




JohnB

@top204
I suggested aliasing the global to a local variable in order to make the code more readable.
For example taken from an existing program:

'---------------------------------------------------------------------------------------------------
' Deletes an Event and frees up an ECB slot in the Events list providing no task is waiting on the
' event. Sets the eventID back to OSNO_EVENT.

      Proc OSDestroyEvent(ByRef EventId As Word)
        Dim EventIdx As OSPW0
        Dim NextTask As OSPW1

        EventIdx = Ptr16(EventID)
        If EventIdx <= LastEvent Then                      ' if its a valid EventID
          NextTask = 0
          Do                                               ' Check if any task is waiting on event
            If Tasks[NextTask] > OSTCB_DESTROYED Then        ' Skip empty or destroyed TCBs
              If Tasks[NextTask + _EventID] = EventIdx Then  ' Is it connected to an event
                If Tasks[NextTask] = OSTCB_TASK_WAITING Then ' and is it waiting on it
                  $ifdef OSENABLE_ERROR_HANDLER
                    OS_RaiseError(OSDESTROYEVENT_ERROR, TASK_WAITING_ON_EVENT)
                  $else
                    Return
                  $endif
                EndIf
              EndIf
            EndIf
          NextTask = NextTask + TCBSize                     ' on to next task
          Loop Until NextTask >= LastTask
          ' to reach here there must be no tasks waiting on the event.
          ECBs[EventIdx] = OSECB_EVENT_NOEVENT              ' set the ecb to empty
          ECBs[EventIdx + _SEMCOUNT] = 0                    ' Clear to not signalled
          ECBs[EventIdx + _SEMISR] = 0                      ' and ISR queue
          Ptr16(EventID) = OSNO_EVENT                       ' clear the EventID to no event
        $ifdef OSENABLE_ERROR_HANDLER
        Else
          OS_RaiseError(OSDESTROYEVENT_ERROR, INVALID_EVENTID)
        $endif
        EndIf
      EndProc

Using a meaningful name makes the code a lot easier to read.  I agree the original examples didn't warrant the  the use of aliasing.

I take your point about using ByRef, just shows how rusty my Positron skills are.
JohnB

top204

I must get into your excellent RTOS more John.

There are a few colour graphic LCD games I want to create that the RTOS will be brilliant with.

joesaliba

Thanks for the explanations.

Joe

John Drew

#24
Quote from: top204 on Jun 18, 2022, 08:11 AMThe new PIC18FxxQ83 devices that are in the coming compiler "upgrade", have 12,800 bytes of RAM, and most of the newer 18F types have approx 8K of RAM, so memory is not going to be a big problem. :-) This will be the normal amount with most new 18F devices, and the enhanced 14-bit core types are also increasing their RAM size.

The use of global variables or SFRs (Special Function Registers) being used as aliases of parameters in a library's procedures is why I added the feature to the compiler, so they can be placed in specific areas when created. i.e. Access or Heap. This gives a lot more control over the code's operation, and makes it more compact and faster to operate.

For example, let's say we have a library to control LEDs. The specific global variables that will be used repeatedly within the library's procedures can have the prefix of "LED_" added to them, so they do not get duplicated in other libraries:

Dim LED_bAlwaysUsed1 As Byte
Dim LED_bAlwaysUsed2 As Byte


Proc LED_Light(pNum As LED_bAlwaysUsed1), LED_bAlwaysUsed2




Les, should that last line be
Proc LED_Light(pNum as LED_bAlwaysUsed1, pNum2 as LED_bAlwaysUsed2)
John

Pablo

Hi All just seen this post....
this is what i use to communicate with a nextion display... text and numbers
if you are only using one page on the nextion display it will always be page 0 or if you rename the page within the nextion editor use the name of the page.

To just send static text to display:-



HRSOut "page0.t5.txt="  'page0 =  nextion screen page.... t5.txt = name of text box on page0 to display info
HRSOut 0x22              ' hex out start of info to display
HRSOut "your text here"  'display the text in the quotes
HRSOut 0x22              ' hex out end of info to display
HRSOut "ÿÿÿ"  tell display this is the end of the message

i have used the following for updating numbers in this case display battery voltage
        BatV = Bvolts *16.2/1023          '
        DelayUS 50
        HRSOut "page0.t1.txt="      this time text box t1           
        HRSOut 0x22
        HRSOut Dec1 BatV
        HRSOut 0x22
        HRSOut "ÿÿÿ"

and to change colours of displayed text / numbers used the following
        HRSOut "page0.t1.pco=65535"
        HRSOut "ÿÿÿ"
        HRSOut "status.t1.bco=63488"
        HRSOut "ÿÿÿ"
all the above called as subroutines when required... and then updates the display may be not the best use but works for me !!!

or to change the page to display on the nextion screen just use
        HRSOut "page 0"                  ' load page 0 screen on nextion display
        HRSOut "ÿÿÿ"

or to change to page 2

        HRSOut "page 2"                  ' load page 2 screen on nextion display
        HRSOut "ÿÿÿ"

then send your info
BatV = Bvolts *16.2/1023          '
        DelayUS 50
        HRSOut "page2.t1.txt="      this time on page 2 write to text box t1           
        HRSOut 0x22
        HRSOut Dec1 BatV              display the dec value of the battery voltage
        HRSOut 0x22
        HRSOut "ÿÿÿ"

hope this is useful to any one?

joesaliba

I always add the page name. The first project I did with a Nextion I only used one page. After some alteration I ended up with six pages and had to alter all code. So from now on, I add pages for future expansion.

Joe

top204

In the example snippet, "LED_bAlwaysUsed2" is used as the procedure's return variable, which can also be an alias to a global variable or SFR. So if the procedure sees something like: Result = 10, it is actually performing the code: LED_bAlwaysUsed2 = 10




John Drew

Quote from: top204 on Jun 18, 2022, 04:38 PMIn the example snippet, "LED_bAlwaysUsed2" is used as the procedure's return variable, which can also be an alias to a global variable or SFR. So if the procedure sees something like: Result = 10, it is actually performing the code: LED_bAlwaysUsed2 = 10




You're right, I overlooked the closing bracket and imagined a comma not a full stop. Two lessons for me:
1) write on the black board "John must read more carefully" twenty times.
2) don't use phone for looking at code

Sorry to waste your time.
All the best Les,
John

Sommi

Quote from: top204 on Jun 18, 2022, 08:11 AMThe new PIC18FxxQ83 devices that are in the coming compiler "upgrade", have 12,800 bytes of RAM, and most of the newer 18F types have approx 8K of RAM, so memory is not going to be a big problem. :-) This will be the normal amount with most new 18F devices, and the enhanced 14-bit core types are also increasing their RAM size.

The use of global variables or SFRs (Special Function Registers) being used as aliases of parameters in a library's procedures is why I added the feature to the compiler, so they can be placed in specific areas when created. i.e. Access or Heap. This gives a lot more control over the code's operation, and makes it more compact and faster to operate.

For example, let's say we have a library to control LEDs. The specific global variables that will be used repeatedly within the library's procedures can have the prefix of "LED_" added to them, so they do not get duplicated in other libraries:

Dim LED_bAlwaysUsed1 As Byte
Dim LED_bAlwaysUsed2 As Byte


Proc LED_Light(pNum As LED_bAlwaysUsed1), LED_bAlwaysUsed2





Hi!

Is there a schedule when these pics (PIC18FxxQ83) will be supported?
Kind regards Sommi
KISS - keep it simple and stupid

top204

The "upgrade" with the new devices is something I am planning on finalising ASAP, but other commitments have gotten in the way.