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
Site Tutorial Index 16F PIC Examples 18F PIC Examples LED's Switches 7 Segment Displays LCD's 7 Segment Displays ADC ADC (Another Example) EEPROM's DS1307 RS232 and UART DS18B20 External ADC Hall Effect Sensor Pulse Width Modulation (PWM) Infrared UART Swordfish Modules Code Snippets SF Libraries 18F Transition Guide Internal Oscillator PLL Structures Multi Tasking Internal Timers Interrupts Handy Tips