No announcement yet.

Driving uLCD-24PTU using Proton Basic

  • Filter
  • Time
  • Show
Clear All
new posts

  • Driving uLCD-24PTU using Proton Basic

    Hello all,

    I’m new with the 4D System. I bought a ULCD-24PTU and love the way it can be setup with Visi-Genie.

    Where I am stuck is on how to send simple data to the unit using the serout and serin and particularly how the data are structured. I have read a lt of documentation and getting confuse because the are either in C or Arduino.

    If I want to send a data byte to my Leddigit2 or read my winbutton0 have been press or not how do I write the serial

    Serout port , 9600 [ OutputData ]


    Rpin , 9600, { Timeout
    , Tlabel
    , } [ InputData ]

    How do I enter my outputdata or inputdata. When I get this understood, I’m sure I will figure all the rest I just need a push start here. Many thanks,



  • #2

    Use GTX to play with your program, that shows you the hexcodes that are sent and received from the display. You just need to emulate that in your program. Once you have looked at a few exchanges the codes in the Genie Reference manual should make more sense.


    • #3

      Thanks Mark,
      But frankly is there is any one that can make a veryconcrete and simple example on how to write a serial command to write a string of for example "hello Word" using the serout command? The visi genie reference manual said that you have to write a CMD, object ID, object index and chksum. Where on earth do I find all these? Please I need help to get started. Many thanks.



      • #4

        I don't understand, it's all in the ViS-Genie reference manual.

        P11 is " Write String (ASCII) Message" and says

        It then goes on to describe what each of those values are. STR-INDEX is the Genie String number, the first string object is called 'String0' so its index is 0.

        If I use GTX and click 'Send' on the strings object and type in 'Hello World' I get

        Set String Text Value 08:02:41.464 [02 00 0B 48 65 6C 6C 6F 20 57 6F 72 6C 64 29]
        ACK 08:02:41.526 [06]
        In the detail window.

        If I open up Terminal and click 'Send Hex' and type in 02000B48656C6C6F20576F726C6429 and then click send I get an ACK back and 'Hello World' is shown on the display.

        Have you read app note P4001 here? It doesn't cover strings, but it does work you through a few examples in a bit more detail and also pulls bits and pieces from the reference manual.


        • #5

          Hello Mark,

          Many thanks for your answer above. In fact even though I thought I downloaded most of the appnotes I have missed the P4001. There is something that baffle me is everything has to be written in hexadecimal mode and that is quite a pain and bring me back to the stone age of computing, particularly when it comes to write a string. I will have thought an "intelligent" display processor would decode a string like "Hello word" in human characters. Is there is any trick to get it more palatable than something like [02 00 0B 48 65 6C 6C 6F 20 57 6F 72 6C 64 29]?




          • #6

            Well the trick is whatever it is in the language of your system....

            "Hello word" is "48 65 6C 6C 6F 20 57 6F 72 6C 64 29" in hex you don't need to translate and/or write anything in hex code except for the actual command codes and if you use the header / include files you don't even need to do that.

            In your basic it might be simply

            Serout port , 9600, 2,0,'hello world',$29

            You'll need to check


            • #7

              Hello Mark,

              I'm slowly getting to understand the phylosophy of the comcept and the P4001 app note did help a lot. There is one thing though I am not too sure how it is done, it is how do you calculate the checksum. I know the manual says that you have to XOR all the values in the strings in cluding the commands but how is it actually done? Like for example the following string: [02 00 0B 48 65 6C 6C 6F 20 57 6F 72 6C 64 29] how one compute the results to be 29 ?
              Many thankd for your time.



              • #8

                In (long winded) 4DGL this would print 29

                HTML Code:
                func main()
                    var cs  ;
                    cs := 0 ;
                    cs := cs ^ 0x02 ;
                    cs := cs ^ 0x00 ;
                    cs := cs ^ 0x0B ;
                    cs := cs ^ 0x48 ;
                    cs := cs ^ 0x65 ;
                    cs := cs ^ 0x6C ;
                    cs := cs ^ 0x6C ;
                    cs := cs ^ 0x6F ;
                    cs := cs ^ 0x20 ;
                    cs := cs ^ 0x57 ;
                    cs := cs ^ 0x6F ;
                    cs := cs ^ 0x72 ;
                    cs := cs ^ 0x6C ;
                    cs := cs ^ 0x64 ;
                    print([HEX2] cs) ;
                (^ is the XOR operator)
                You can also do it in a for next loop for the ASCII part


                • #9

                  Thanks but this checksum thing is a real pain and unusual practice. I suppose on each sending category one just have the actual data to XORE with the constant commands but these still clog up the code. In addition you have acknowledge every send commands. I wish there was a way around the checksum data. The 4D displays may be very good at the IDE setup but not very user friendly for us that are not using your much supported Arduino and PI systems



                  • #10

                    The checksum was mandated by users that insisted it be put there.

                    Um, generally I just call a subroutine to write all the data and calculate the CS at that point and append it to the data.

                    5-6 lines of code, max.

                    Actually here's a Delphi example

                    cs := 0 ;
                    for i := 1 to length(cmd) do cs := cs xor ord(cmd[i]) ;
                    cmd := cmd + ansichar(cs) ;

                    3 lines.


                    • #11


                      There is a Checksum for a reason, as Mark has outlined. XOR is actually very common.

                      If you don't wish to use our protocol, you are welcome to use the ViSi environment instead, and define your own protocol.
                      You will find you have a lot more work ahead of you.
                      If you don't want a Checksum or you dont want to ACK each thing, then ViSi is an option for you, just define what you want. However if you get corrupt data then you are on your own, and you will have to deal with the consequences. You can define whatever protocol you want.

                      The reason Arduino and Pi systems have a ViSi Genie library from us, is because they have a very large target audience and they were demanded. I am not aware of anyone who has developed with Proton Basic personally.
                      You are welcome to write your own library if you want.



                      • #12

                        Thanks James and Mark for you helpful advises. your recommendations are well noted and I think I will have to comply to the visi genie protocol. I'm new with this product but I'm sure when I will have fully understood it I will look back and wonder what was all the fuzz all about.



                        • #13
                          hello Yves here alain from belgium also use use picbasic or proton here i write a little code for use with 9600bds to a 43pct and 70dt works fine after a mess send i have a ack return here the code for picbasic from melab buth will works also fine if you declare the vars in a other version


                          • #14
                            DEFINE OSC 4 '4 MHz crystal snelheid
                            INCLUDE "modedefs.bas" ' Include mode
                            ADCON1 = 15 ' zet PORT A en PORT E digitaal
                            TRISB.5 = 0 'zet portb tot 5 op output
                            LED VAR PORTB.1 ' led op poort b.1
                            Reset var PORTB.0
                            displayout var PORTC.6 ' tx port van pic
                            displayin VAR PORTC.7 ' rx port van pic
                            controleled VAR BYTE [$6] 'Receive de controle byte van 4dsystems
                            LOW RESET 'reset pin op scherm laag voor reset
                            PAUSE 20 'tijd voor reset
                            HIGH RESET 'continue hoog op reset pin
                            LED = 0 'led op uit
                            pause 2300 ' tijd voor cls en programma opstart
                            MAIN: 'hoofdprogramma
                            serout2 displayout , 84 ,[$04,$06,$02]
                            'serout2 displayout , 84 ,[$01,$0f,$00,$00,$01,$0f]
                            serout2 displayout , 84 ,[$01,$13,$00,$00,$01,$13] 'led 0 aan
                            pause 500
                            serout2 displayout , 84 ,[$01,$13,$01,$00,$01,$12] ' led 1 aan
                            pause 500
                            serout2 displayout , 84 ,[$01,$13,$02,$00,$01,$11] 'led 2 aan
                            pause 500
                            serout2 displayout , 84 ,[$01,$13,$00,$00,$00,$12] 'led 0 uit
                            pause 500
                            serout2 displayout , 84 ,[$01,$13,$01,$00,$00,$13] 'led 1 uit
                            pause 500
                            serout2 displayout , 84 ,[$01,$13,$02,$00,$00,$10] ' led 2 uit
                            'gosub controlebit 'na 8 instructies ga naar controlebite $6
                            ' serout2 displayout , 84 ,[$01,$0f,$00,$00,$01,$0f] 'zet getal 001 op display
                            pause 500

                            serout2 displayout , 84 ,[$04,$04,$00]

                            gosub controlebit

                            SERIN2 displayin,84,[controleled] 'serial in voor opvraag controle byte
                            if controleled = $6 then
                            high led 'aan van led
                            pause 500 'wacht 0/5 sec
                            low led 'led bij portb.5
                            pause 1000
                            'terug naar main progr
                            gosub main

                            this switch the contrast and set the 3 leds on off
                            greetings alain or cardan