Structure of a Byte Variable


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818

    Default Structure of a Byte Variable

    Thanks to the code posted below by Darrel
    in http://www.picbasic.co.uk/forum/showthread.php?t=9134
    Code:
    TimeCmpFlags  VAR BYTE
      PastStart   VAR TimeCmpFlags.0
      PastStop    VAR TimeCmpFlags.1
      NextDay     VAR TimeCmpFlags.2
      ProgON      VAR TimeCmpFlags.3
    
    
    CheckTimes:
      TimeCmpFlags = 0  ; clear flags first
    
         ; if the Start and Stop times are the same, then Always OFF 
      if (Stop_H=Start_H) AND _       
         (Stop_M=Start_M) AND _
         (Stop_S=Start_S) then AlwaysOFF                      
    
         ; is it past the Start time?
      if (Hours>Start_H) OR _              
         (Hours=Start_H AND Minutes>Start_M) OR _
         (Hours=Start_H AND Minutes=Start_M AND Seconds>=Start_S) then PastStart=1
    
         ; is it past the Stop time?
      if (Hours>Stop_H) OR _                
         (Hours=Stop_H AND Minutes>Stop_M) OR _
         (Hours=Stop_H AND Minutes=Stop_M AND Seconds>=Stop_S) then PastStop=1
    
         ; does the period end the following day?
      if (Stop_H< Start_H) OR _           
         (Stop_H=Start_H AND Stop_M < Start_M) OR _
         (Stop_H=Start_H AND Stop_M=Start_M AND Stop_S < Start_S) then NextDay=1
        
      ;---------------
      if !NextDay then                               ; same day, use AND
          if PastStart AND !PastStop then ProgON = 1
      else                                           ; next day, use OR
          IF PastStart OR !PastStop then ProgON = 1
      endif
        
      AlwaysOFF:
    return
    I will never think of a BYTE variable the same way again. I always thought of a BYTE as a container which holds a number from 0-255, but the code above struck me this way, a BYTE is a BIT Array! where 8 bits all share the same variable name. All in how you look at things I guess, I saved this as an example for some future need. Thanks Darrel.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    All in how you look at things I guess
    Exactly!

    Thanks for fishing Joe.
    <br>
    DT

Similar Threads

  1. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  2. Memory use - how much do you use?
    By keymuu in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 10th June 2009, 22:39
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts