cfag12864b-TMI-V VB initialization code

spadusa

New member
alright. i got my CFAG12684b-TMI-V up and working beautifully...however...i would really like to program it with VB6...its interfaced to the parallel port using the schematic from liquid-mp3's website. im having much trouble intializing it and writing to it...if anyone could post some code it would be much appreciated...even a shove in the right direction would be good
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

spadusa

New member
no...i had to buy a new display. i went from a ...wgh-n to a ..tmi-v. C will work i guess...now i have to go and learn C...thanks...if anyone has sample VB...ill be very grateful
 

spadusa

New member
i ran the release of the test thing you sent me...i get only half of the LCD to display...it looks like a controller is bad...however...when i use liquid mp3 with winamp...everything works fine...any suggestions??? and none of the functions will display except the tracter thing
 

CF Tech

Administrator
They probably have different pin assignments (different schematic). That can be your first C task, redefining the port macros to make the test program work with your schematic. :)
 

spadusa

New member
i cant find the port definitions anywhere...i found...

Code:
#define CLR_CS1 (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)));(Sleep(1))
#define FCLR_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)))
#define SET_CS1 (DlPortWritePortUchar(CONT_ADDR,(control&=~0x02)))
  
//straight at the port
#define SET_RS (DlPortWritePortUchar(CONT_ADDR,(control|=0x04)))
#define CLR_RS (DlPortWritePortUchar(CONT_ADDR,(control&=~0x04)))

//inverted at the port
#define CLR_CS2 (DlPortWritePortUchar(CONT_ADDR,(control|=0x08)))
#define SET_CS2 (DlPortWritePortUchar(CONT_ADDR,(control&=~0x08)))

//inverted at the port
#define CLR_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x01)))
#define SET_E (DlPortWritePortUchar(CONT_ADDR,(control&=~0x01)))


#define DATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)));(Sleep(1))
#define FDATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)))
i have no idea what
Code:
control&=~0x08
means...please help...im getting frusrated...now i know why i didnt want to learn C :confused: ;)
 

spadusa

New member
im getting real pissed off...in the code up above...what is the value of control...i cant find it anywhere i do see

ubyte
control;

but i cant find the value of control

thanks
 

CF Tech

Administrator
Don't panic. Just a little C shorthand there my friend.

control is just an unsigned character (one byte).

control holds the last value that was written out to CONT_ADDR by DlPortWritePortUchar.

Let's say you wanted to make a certain bit high in control. For instance, the least significant bit. That would be 1. Then you might do something like:

control = 1;

but if another bit in control was high, it just went low because you wrote the 1 to control (the lowest bit) and also the other 7 higher bits, which are zeros.

So instead, to set one bit high you need to do something like:

control = (control OR 1)

In C, the bitwise OR is signified by the "pipe" character: |

So that becomes:

control = (control | 1)

Part of C's goal as a language is to allow cryptic syntax, so C allows you to rewrite statements like this:

A = A (operator) B

as

A(operator)=B

So now it becomes:

control|=1

C people usually use hex for bit manipulation, since it is easier to visualize the set bits. So now it becomes:

control|=0x01; //Set the lsb

To clear a bit, you need to write a single 0 bit. This can be done using the "bitwise invert" operator: ~
and the "bitwise and" operator: &

control&=~0x01; //Clear the lsb

So all that "control&=~0x08" means is to clear the 3rd bit in control. By the way, the bits in a byte are numbered 0 to 7.

So hopefully that will explain a bit.

After initialization, the display will typically be blank (but that is not guaranteed). You would then write your image to the display.
 

spadusa

New member
alright...C was really kicking me in the butt with errors so i decided to switch back to visual basic...with your explanation above i was able to translate the below code into visual basic...from there i went to the OnInitialize part of the C code and just wrote that all in visual basic...then i translated the OnCheckerboard part of the C code into VB...now...my problem...when i run the code this is what happens:

if the LCD was just plugged in with nothing on the screen:

screen turns white but there are a few random pixels that are still blue....sometimes its cleared completely...checkerboard code does not draw a checkerboard

if the LCD has something on it already from liquidMP3:

absolutely nothing happens...doesnt clear....even when i execute the checkerboard code nothing happens

so as you can see...im completly stuck in programming my own LCD screens...if you can help with anything its greatly appreciated....thank you in advanced
Code:
#define CLR_CS1 (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)));(Sleep(1))
#define FCLR_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x02)))
#define SET_CS1 (DlPortWritePortUchar(CONT_ADDR,(control&=~0x02)))
  
//straight at the port
#define SET_RS (DlPortWritePortUchar(CONT_ADDR,(control|=0x04)))
#define CLR_RS (DlPortWritePortUchar(CONT_ADDR,(control&=~0x04)))

//inverted at the port
#define CLR_CS2 (DlPortWritePortUchar(CONT_ADDR,(control|=0x08)))
#define SET_CS2 (DlPortWritePortUchar(CONT_ADDR,(control&=~0x08)))

//inverted at the port
#define CLR_E (DlPortWritePortUchar(CONT_ADDR,(control|=0x01)))
#define SET_E (DlPortWritePortUchar(CONT_ADDR,(control&=~0x01)))


#define DATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)));(Sleep(1))
#define FDATA(x) (DlPortWritePortUchar(DATA_ADDR,(x)))
 

CF Tech

Administrator
What does your VB code look like that is supposed to set a line to high?

What does your VB code look like that is supposed to clear a line to low?
 

spadusa

New member
Code:
Function control() As Byte
    control = DlPortReadPortUchar(890)
End Function
Function old_value() As Byte
    old_value = DlPortReadPortUchar(&H378)
End Function
Public Sub DATA(bytValue As Byte)
    DlPortWritePortUchar 888, Val(bytValue)
    Sleep (1)
End Sub
Public Sub FDATA(bytValue As Byte)
    DlPortWritePortUchar 888, bytValue
End Sub
Public Sub CLR_CS1()
Call DlPortWritePortUchar(890, control Or &H2)
Sleep (1)
'control = control Or &H2
End Sub
Public Sub FCLR_E()
DlPortWritePortUchar 890, control Or &H2
'control = control Or &H2
End Sub
Public Sub SET_CS1()
DlPortWritePortUchar 890, control And (Not &H2)
'control = control And (Not &H2)
End Sub
Public Sub SET_RS()
DlPortWritePortUchar 890, control Or &H4
'control = control Or &H4
End Sub
Public Sub CLR_RS()
DlPortWritePortUchar 890, control And (Not &H4)
'control = control And (Not &H4)
End Sub
Public Sub CLR_CS2()
DlPortWritePortUchar 890, control Or &H8
'control = control Or &H8
End Sub
Public Sub SET_CS2()
DlPortWritePortUchar 890, control And (Not &H8)
'control = control And (Not &H8)
End Sub
Public Sub CLR_E()
DlPortWritePortUchar 890, control Or &H1
'control = control Or &H1
End Sub
Public Sub SET_E()
DlPortWritePortUchar 890, control And (Not &H1)
'control = control And (Not &H1)
End Sub
those are the subs i translated...i was experimenting with different ways to set control as the last value set on the port...then i have my initialize code

Code:
Dim row As Integer, col As Integer, data1 As Byte
    CLR_E
    CLR_RS
    CLR_CS1
    CLR_CS2
    DATA (&H3F)
    SET_E
    CLR_E
    Sleep (10)
    DATA (&HC0)
    SET_E
    CLR_E
    Sleep (10)
thats my project so far....i have one sub that i translated from C and i think its suppose to draw a checkerboard...thats next
Code:
data1 = &HAA
   CLR_CS1
   CLR_CS2
   For row = 0 To 7
        DATA (&HB8 Or row)
        SET_E
        CLR_E
        Sleep (1)
        DATA (&H40)
        SET_E
        CLR_E
        Sleep (1)
        SET_RS
        For col = 0 To 63
            FDATA (data1)
            SET_E
            Sleep (1)
            data1 = data1 Xor &HFF
        Next
        CLR_RS
    Next
i have no idea what im doing wrong so ANY help is greatly appreciated....thanks again
 

CF Tech

Administrator
I do not see anything obviously wrong.

You can simplify a bit by doing the logic first, then the port write:

Code:
Dim control As Byte

Public Sub DATA(bytValue As Byte)
  DlPortWritePortUchar 888, Val(bytValue)
  Sleep (1)
End Sub

Public Sub FDATA(bytValue As Byte)
  DlPortWritePortUchar 888, bytValue
End Sub

Public Sub CLR_CS1()
 control = control Or &H2 
 Call DlPortWritePortUchar(890, control)
 Sleep (1)
End Sub

Public Sub FCLR_E()
  control = control Or &H2
  DlPortWritePortUchar( 890,control)
End Sub

Public Sub SET_CS1()
  control = control And (Not &H2)
  DlPortWritePortUchar(890,control)
End Sub

Public Sub SET_RS()
  control = control Or &H4
  DlPortWritePortUchar(890,control)
End Sub

Public Sub CLR_RS()
  control = control And (Not &H4)
  DlPortWritePortUchar(890,control)
End Sub

Public Sub CLR_CS2()
  control = control Or &H8
  DlPortWritePortUchar(890, control)
End Sub

Public Sub SET_CS2()
  control = control And (Not &H8)
  DlPortWritePortUchar(890,control)
End Sub

Public Sub CLR_E()
  control = control Or &H1
  DlPortWritePortUchar(890, control)
End Sub

Public Sub SET_E()
  control = control And (Not &H1)
  DlPortWritePortUchar(890, control)
End Sub

>> your code starts here

Dim row As Integer, col As Integer, data1 As Byte
  control=0
  CLR_E
  CLR_RS
  CLR_CS1
  CLR_CS2
  DATA (&H3F)
  SET_E
  CLR_E
  Sleep (10)
  DATA (&HC0)
  SET_E
  CLR_E
  Sleep (10)

  data1 = &HAA
  CLR_CS1
  CLR_CS2

  For row = 0 To 7
    DATA (&HB8 Or row)
    SET_E
    CLR_E
    Sleep (1)
    DATA (&H40)
    SET_E
    CLR_E
    Sleep (1)
    SET_RS
    For col = 0 To 63
      FDATA (data1)
      SET_E
      Sleep (1)
      data1 = data1 Xor &HFF
    Next
    CLR_RS
  Next
You need the control variable in there, otherwise the bit writes will not "stick".


Is the BASIC "Not" operator logical or bitwise? If you are not sure you might try &HFD instead of (Not &H2). Are the And and Or operators bitwise?
 

spadusa

New member
The NOT, AND and OR operators ARE bitwise (i looked it up on google). I tried using your smiplified version and i got the same thing

absolutely nothing works...i try it in C and i cant even build the code you gave me...untouched...because of errors....so i cant even modify the code you gave me...im so frustrated right now...i bought this LCD to program my own application for this...and of course...nothi9ng ever works for me...ANYONE with any info on how to program this stubborn display in BASIC is greatly welcomed to post on this thread

i cant think of anything else to do...i translated your code into BASIC and it wont work...and now that i think of it...it doesnt work with your executable either....


i downloaded your C code and ran the release version you provided with it. i got the Crystal Fontz title thingy to appear on half of the display...the other half was blank...after that i pushed some of the buttons and the only thing that would display anything was the tractor thingy and the V-Scroll or whatever...so maybe the way i wired my display is causing your code not to work? i dont know...anything at this point will help me...thank you for all your help CF Tech...im looking forward to an answer...;)
 

CF Tech

Administrator
Well, if the EXE is not working, then the basic will not work either.

I would advise to study your hardware until the executable from the C code works, then take on the VB stuff.

Can you verify that each pin you control in VB makes it to the correct pin on the LCD in the correct polarity?
 
Top