VARIABLES IN FC7
Moderator: Benj
-
- Posts: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
- Contact:
VARIABLES IN FC7
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 ?
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 ?
-
- 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
Like most everything in programming there are many ways to do this:
One would be:
Note that in the picbasic code the (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
One would be:
Note that in the picbasic code the
Code: Select all
gosub ln1
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
-
- Posts: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
- Contact:
Re: VARIABLES IN FC7
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 ?
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 ?
-
- 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
Can you post the Flowcode you have so far.
I'm going to assume that commands such as 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
I'm going to assume that commands such as
Code: Select all
glcd_ce=1
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
-
- Posts: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
- Contact:
Re: VARIABLES IN FC7
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 219 times
-
- glcd_demo_01.txt
- (12.53 KiB) Downloaded 225 times
-
- GLCD_240x128_DEMO-02.fcfx
- (42.5 KiB) Downloaded 227 times
-
- 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
Hi,
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: 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
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: 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
-
- Posts: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
- Contact:
Re: VARIABLES IN FC7
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 ?
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 ?
- 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
Hello,
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.how can I test if the glcd is initialized correct
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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
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
-
- 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
As a direct translation of the picbasic:
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
- 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