| 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
- Jon Chandler
- andyo
Forum Activity
REALISTIC LED candle flicker - mrdeb Wednesday, 10 March 2010 05:48 - [0 replies]
the LCD demo hello world - mrdeb Wednesday, 10 March 2010 05:41 - [29 replies]
USB problem - jon chandler Tuesday, 09 March 2010 11:31 - [3 replies]
Servo Module - andyo Tuesday, 09 March 2010 03:39 - [3 replies]
pic to ps2 communication - roshan Friday, 05 March 2010 01:30 - [7 replies]
Way Off Topic: Worldwide Ignite Week - jon chandler Wednesday, 03 March 2010 20:33 - [4 replies]
PIC USB with C and Visual C++ Project - hop Tuesday, 02 March 2010 21:49 - [0 replies]
Recent Comments
- 2010-03-05 13:24:23 mrpse...
I was thinking of battery with powered routers or powered for every...
- 2010-03-05 12:17:40 andyo
50 rooms - wow. The XBee modules are very easy to use but I'm not ...
- 2010-03-05 11:46:37 mrpse...
Thanks AndyO. What I have to do is design a device to monitor temp...
- 2010-03-05 03:08:58 andyo
The circuit used for the remote sensor can be found here: [url]http...
- 2010-03-04 07:19:06 renno
plz i need help do u know from where i could download it or how cou...
- 2010-03-04 07:16:05 renno
hello everyone i'm trying to finish my final project and i want to ...
- 2010-03-04 02:49:38 Saira...
Thanks that was helpful
- 2010-03-04 02:35:35 Jon C...
There is a BlueTooth module available. If you used this, you can s...



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