BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Tue Jan 23, 2018 8:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: First Attempt at a "Library" for 4D Systems-based LCDs
PostPosted: Sun Jan 05, 2014 4:12 am 
Offline
Master

Joined: Sun Jan 03, 2010 4:01 pm
Posts: 134
Location: Eau Claire, WI
Greetings all,

Disclaimer: ** This is a work in process; if there is enough interest I will create a full tutorial and I am NOT an employee of 4D Systems...just a avid fan**

Over the past two years I have experimented with the touch based LCD Displays manufactured by 4D Systems based out of Australia. Over the last year they have developed their 4D Workshop software (which is a free download) to include an element called Visi-Genie. By using Visi-Genie you can drop "widgets" (objects such as buttons, LEDs, Slide Controls as well as basic graphic/sound controls). In short it is VERY possible to create a very professional LCD display for a variety of applications. Right now I am working on my new thermostat control system (think this project is going on three winters now).

While the control of the LCD Display isn't difficult in concept the documentation from my perspective has a lot to be desired as they assume everyone is using either the Arduino or Raspberry Pi libraries :(

With that said I've post the code which if nothing else demonstrates the following basic concepts:

1) how to establish communication with a the display
2) how to check for a ACK and NAK (which must be checked after you send a command to the display)
3) how to send a value to a LEDDIGTS widget (or object)
4) how to send text

What you need to:
1) a 4D Systems LCD which cost anywhere from $60 to $170) (and their 4D USB Programmer for $24) & 2GB Card
1) connect the LCD Display to the corrects Pins that are supported by your version of a Nano Processor
2) connect the LCD Reset to P3 (which you can change)
3) download and install the 4D Workshop
4) connect the LCD to the 4D USB Programmer
5) launch 4D Workshop and select the Visi-Genie option
6) drop an widget to the display (not the index number; that is how select the object you want to communicate with)
7) save the LCD configuration
8) place the 2GB (max size) in your computer
9) compile the program which some code is stored on the LCD's flash and some code is stored on the 2GB card
10) unplug the LCD from the USB Programmer and move the 2GB Card from your computer to the LCD
11) connect the LCD to the Nano Processor
12) load up the demo code and have fun!

I've include two screens (actually they are called forms) I'm using for my thermostat:



Code:
; Library for 4D Systems LCD Displays using Visi-Genie Firmware
; NOTE: The Read Object Status Message is not included in this version
;
; Version 3.0 Build 70
; Created by Brian Schwahn
; Date: January of 2014

SEROUT S_OUT,I9600,[0,"Program starting...",13]

;Constants for I/O of Nano-28
LCD_RST         CON   P3

; Constants for Widgets (not all are listed...see Visi-Genie Manual)
DIPSWITCH      CON   $00
KNOB         CON   $01
ROCKERSWITCH   CON   $02                  
ROTARYSWITCH   CON   $03
SLIDER         CON   $04
TRACKBAR      CON   $05
WINBUTTON      CON   $06
ANGULARMETER   CON   $07
COOLGAUGE      CON   $08
CUSTOMDIGITS   CON   $09
GAUGE         CON   $0B
LED            CON   $0E
LEDDIGITS      CON $0F
METER         CON   $10
THERMOMETER      CON   $12

READ_OBJ      CON   $00
WRITE_OBJ      CON   $01
WRITE_STR      CON $02

; Variables for LCD Message
CMD            VAR BYTE
OBJ_ID         VAR   BYTE
OBJ_INDEX      VAR   BYTE
VALUE_MSB      VAR   BYTE
VALUE_LSB      VAR   BYTE
CHKSUM         VAR BYTE

STR_INDEX      VAR   BYTE
STRLEN         VAR BYTE
STRINGS         VAR   BYTE(75)

LCD_STATUS      VAR BYTE

; Variables for general program use

X            VAR   BYTE
   
CLEAR

GOSUB HSERIAL_SETUP                                 ;Setup the HSEROUT/HSERIN Baud Rates

GOSUB LCD_RESET                                  ;Reset the LCD Display                                    

CMD=WRITE_OBJ
OBJ_ID=LEDDIGITS
OBJ_INDEX=$00
VALUE_MSB=88
VALUE_LSB=88
GOSUB WRITE_OBJECT
PAUSE 1000

CMD=WRITE_STR
STR_INDEX=$00
STRLEN=11
STRINGS="Hello World",0
GOSUB WRITE_TEXT
PAUSE 1000


STOP




; *********************** Subroutine to send commands to the LCD ****************************

WRITE_OBJECT
   
   CHKSUM=CMD^OBJ_ID^OBJ_INDEX^VALUE_MSB^VALUE_LSB   
   HSEROUT [CMD,OBJ_ID,OBJ_INDEX,VALUE_MSB,VALUE_LSB,CHKSUM]
   GOSUB NAK

RETURN
   
; *************************************************************************************************


; *********************** Subroutine to send text to the LCD ****************************

WRITE_TEXT

   SEROUT S_OUT,I9600,["Writing Text!",13]
   CHKSUM=CMD^STR_INDEX^STRLEN   
   FOR X=0 TO STRLEN   
      CHKSUM=CHKSUM^STRINGS(X)   
   NEXT   
   HSEROUT [CMD,STR_INDEX,STRLEN,STR STRINGS\STRLEN\0,CHKSUM]   
   GOSUB NAK

RETURN
   
; *************************************************************************************************   


; ****** RESET THE 4D SYSTEMS DISPLAY ******

LCD_RESET

   SEROUT S_OUT,I9600,[0,"Resetting the LCD",13]
   HIGH LCD_RST
   PAUSE 250
   LOW LCD_RST
   PAUSE 100
   HIGH LCD_RST
   PAUSE 3000
   
RETURN
   
; *************************************************************************************************

   
; ******************** Subroutine to check for communication from the LCD *************************

NAK
   HSERIN [LCD_STATUS]   
   IF LCD_STATUS=$06 THEN
      SEROUT S_OUT,I9600,["LCD COM OK:",HEX LCD_STATUS,13]
   ELSE
      SEROUT S_OUT,I9600,["LCD COM Error:",HEX LCD_STATUS,13]   
   ENDIF   
   PAUSE 50
RETURN

; *************************************************************************************************

; *********************** Configure the Baud Rate for Hardware Serial ****************************
HSERIAL_SETUP

   SETHSERIAL1 H38400                        ;Maximun baud rate for a standard Nano?
   ;SETHSERIAL1 H9600                        ;Default baud rate for a standard Nano
   
RETURN
   
; *************************************************************************************************


Attachments:
Form-1.jpg
Form-1.jpg [ 40.29 KiB | Viewed 1695 times ]
Form-0.jpg
Form-0.jpg [ 32.62 KiB | Viewed 1695 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO