| Swordfish Code Snippet - Structures |
|
|
| Saturday, 04 April 2009 10:09 | |
|
Structures are a powerful addition to the Swordfish arsenal, and here's a quick example of how to use them;
Structure TTime Hours As Byte Minutes As Byte Seconds As Byte End Structure The declaration above informs the compiler that TTime contains three Byte fields (Hours, Minutes and Seconds). We can now create a variable of Type TTime, in exactly the same way as you would any other compiler type, such as Byte or Float,
Dim Time As TTime
Access To an individual field within the variable Time is achieved by using the dot (.) notation, Time.Hours = 9 Time.Minutes = 59 Time.Seconds = 30
Here's an example in full context (note that the Timer setup procedure 'Setup_Timer' has been removed for ease of explanation);
Device = 18F452 Clock = 20 Structure TTime Hours As Byte Minutes As Byte Seconds As Byte Milli_Seconds As Word End Structure Dim Time As TTime Interrupt TMR_Interrupt() Inc(Time.Milli_Seconds) If Time.Milli_Seconds = 1000 Then Time.Milli_Seconds = 0 Time.Seconds = Time.Seconds + 1 If Time.Seconds = 60 Then Time.Seconds = 0 Time.Minutes = Time.Minutes + 1 If Time.Minutes = 60 Then Time.Hours = Time.Hours + 1 EndIf EndIf EndIf End Interrupt Setup_Timer Enable(TMR_Interrupt) While True Wend
Comments (3)
Joomla components by Compojoom
|
|
| Last Updated ( Tuesday, 14 April 2009 10:52 ) |
Whos Online
- dha
- ta1dr
- Jon Chandler
Forum Activity
Credit Where Credit's Due - jon chandler Tuesday, 16 March 2010 12:01 - [9 replies]
Marching LEDs - mrdeb Saturday, 13 March 2010 22:54 - [7 replies]
USB 8 Channel Servo Controller - andyo Saturday, 13 March 2010 01:19 - [2 replies]
Dedicated Servo Controller - graham Friday, 12 March 2010 17:58 - [0 replies]
Must have....delta temperature glowies! - graham Friday, 12 March 2010 17:31 - [3 replies]
A 'throw-away" PIC board - jon chandler Friday, 12 March 2010 13:41 - [31 replies]
iHID - graham Friday, 12 March 2010 02:04 - [5 replies]
Recent Comments
- 2010-03-18 05:40:21 azuga...
Gamers ought to know link:http://www.buyazugagold.com [azuga gold[/u...]
- 2010-03-17 22:58:18 Jon C...
Graham, Thanks for fixing the spacing on the array. This is how i...
- 2010-03-17 21:14:34 ASDne...
Thanks Graham, It is a problem with Flowcode because the demo wa...
- 2010-03-17 19:50:32 Graha...
Looks like you've pretty much solved every minor issue that was enc...
- 2010-03-17 11:42:03 Jon C...
The low-cost servo does have one other feature. The origina...
- 2010-03-17 10:56:44 Graha...
I am not familiar with flowcode, though did you try powering the bo...
- 2010-03-15 21:47:55 ASDne...
Hello there, I am still trying to get the LCD to work but I am pro...
- 2010-03-15 13:16:38 Graha...
Hi Hop, I've finally got some time this weekend to delve into the ...



Is Swordfish that much more user friendly as this appears to be so logical in format.
Keep up the Great Work Graham!