VARIABLES IN FC7

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

VARIABLES IN FC7

Post by SILVESTROS9 »

Hello to all !
I would like to use the following subroutine (in picbasicpro) in a FC7 code...

1. for gl_y= $1027 to $1528 step $28
2. gl_ad1= gl_y.BYTE1
3. gl_ad2= gl_y.BYTE0
4. gl_k= %11000001
5. num_1 =1
6. num_2 =1
7. gosub ln1
8. next

about lines 2,3, gl_y. BYTE1 is 8bit msb , gl_y.BYTE0 is 8bit lsb of 16bit variable gl_y ...how can I do that in FC7 code?
for line 4, how can I do that with a calculation command ?

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: VARIABLES IN FC7

Post by mnf »

Like most everything in programming there are many ways to do this:

One would be:
Capture.JPG
Capture.JPG (25.98 KiB) Viewed 5663 times
Note that in the picbasic code the

Code: Select all

gosub ln1
(on line 7) will cause the program to crash... I've omitted it here.

The code doesn't do anything useful - and could be improved - for example num_1 and num_2 are repeatedly assigned the value of 1 - and this could be done (once) before the loop.
It's a matter of style whether you have multiple assignments in one calculation box - or multiple calculation boxes.
It's also a preference whether you have the '& 255' when assigning to a byte value (I usually omit it, as it is an unnecessary instruction - but care is needed if gl_ad1 etc changed to >8 bit values)
Binary values have a '0b' prefix in FC (% in picbasic)
FC loops work as 'while' or 'repeat until' or 'for' loops - and provide great flexibility on whether the test is at start or end of loop or as a for loop using an auto_generated (byte only in FC7) or user_defined loop variable.

I don;t know picbasic - but if $ indicates a hex number then add 0x before the literal values.

Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: VARIABLES IN FC7

Post by SILVESTROS9 »

Martin ,
I would like to thank you, for the info...
another problem with following subroutine that I try to convert to FC7.

1. busy_chk:
2. glcd_ce = 1
3. glcd_tris= %11111111
4. glcd_cd = 1
5. glcd_wr = 1
5 glcd_ce = 0
6. glcd_rd = 0
7. pauseus GL_PAUSE
8. if (glcd_sta0 <> 1) AND (glcd_sta1 <> 1) then busy_chk
9. glcd_rd = 1
10. glcd_ce = 1
11. glcd_tris = %00000000
12. return

The above simply check the status of 2 pins ( B.0 = STA0, B.1=STA1 ) of PORTB...initially PORTB set as input with command 3, then with cmd 8 check if B.0, B.1 are 1 , and after that, PORTB.0 set as output to write data at glcd...I tried in FC7 to switch PORTB but the program stops in cmd 8. how can i do that in FC7 ?

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: VARIABLES IN FC7

Post by mnf »

Can you post the Flowcode you have so far.

I'm going to assume that commands such as

Code: Select all

glcd_ce=1
are setting pins to write to a display.
You can use Flowcode input/output macros to read/write pins or define the pins in the program properties and assign to/from them.
How have you coded line 8 - you could make the routine into a loop or use a goto command - if you have made this routine into a macro then calling it recursively will cause bad things to happen.

However, one further thought, does Flowcode have a component to drive the LCD you are using? If it does then you can save yourself a lot of work by using it instead. If not - how is the display connected, you might be able to use the i2c or SPI components (or ask nicely and Ben/Leigh might be able to tweak one of the existing components )

Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: VARIABLES IN FC7

Post by SILVESTROS9 »

I send you the FC7 that I've made so far..also the code that I try to convert , and some info for glcd controller T6963C....the code after a cycle stops at status sub. i think the problem is maybe at set portB as input/output....my goal is to send a text to a glcd 240x128 with T6963C controller..I've tried to do that with FC7 component , but no work....so I try to convert a code in PBP that works to FC7..
Attachments
t6963.pdf
(228.92 KiB) Downloaded 215 times
glcd_demo_01.txt
(12.53 KiB) Downloaded 221 times
GLCD_240x128_DEMO-02.fcfx
(42.5 KiB) Downloaded 224 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: VARIABLES IN FC7

Post by mnf »

Hi,
Capture.JPG
Capture.JPG (20.79 KiB) Viewed 5603 times
Is why it stops in status - STA0 and STA1 will stay their initial values and are never re-read.

I would suggest making the pins for the display into properties - that way assignment is easier - and although it will be some work now, you'll thank me when you try to re-use the display later....

For example:
properties.JPG
properties.JPG (25.18 KiB) Viewed 5603 times
ToggleCE.JPG
ToggleCE.JPG (18.08 KiB) Viewed 5603 times
Note that you can also assign a complete port this way (define a property as a digital port).

Note that Status is also called a lot of times - making it as fast as possible would be good - is it necessary to read this before every instruction?

Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: VARIABLES IN FC7

Post by SILVESTROS9 »

Martin,
many thanks for your help....yes, according to T6963 data sheet must be read the status of pin STAO, STA1 before each instruction , data or command...PORTB works as I/O between mcu and glcd....I'll make some changes and try again....in your opinion how can I test if the glcd is initialized correct because I think that is the most important part of code ?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: VARIABLES IN FC7

Post by Benj »

Hello,
how can I test if the glcd is initialized correct
The easiest way is it will switch on and start showing pixel data. GLCDs can be hard as they will do nothing and then when you have almost given up they will spring into life and work fine. Start with trying to initialise and then set and clear a single pixel. Once you can do this it gets a lot easier.

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: VARIABLES IN FC7

Post by mnf »

Have you made any progress?

I suggest changing from toggle switches to try and read the status bits - they add a lot of overhead and add such things as debounce - which is good for mechanical switches but not so much here. Probably should just be a pin read....

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: VARIABLES IN FC7

Post by mnf »

As a direct translation of the picbasic:
properties.JPG
properties.JPG (38.81 KiB) Viewed 5563 times
- I've set up the pins as properties so can read and write them directly.

Some questions for the PIC experts out there:

Can the tris register be set like this or does it need some C?

Does the tris register need to be set or does reading the port do this (move '.status = glcd_port' to ?)
- I'm assuming the delay is needed before the port can be read - is it possible to set chip enable, pause, read the port then disable?

Martin

Post Reply