Individual Variable bits


Closed Thread
Results 1 to 5 of 5
  1. #1

    Default Individual Variable bits

    Good Morning to All,
    I was wondering if I declared a variable such as, train var byte, then I had another variable, car var byte, in which if there was a car car.0[0] =1 and I wanted to send to portb the bits in train 1,2,3,4,5,6,7 to make portb pins 1-7 high or low depending on how the bits are set in train but I wanted portb.0 to be high or low depending on the value of car. In this way I could have portb pin 0 showing a car is there and portb pins 1-7 providing high or low outputs to control other things. How could I do this together? The Pic I am using is a 16f628a.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Alias...
    In the manual...
    Read and learn...

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks for steering me in the right direction. I will try it.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Here is what you need.


    http://www.picbasic.co.uk/forum/showthread.php?t=3753


    If you still have questions, post it to that thread.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by tazntex View Post
    Good Morning to All,
    I was wondering if I declared a variable such as, train var byte, then I had another variable, car var byte, in which if there was a car car.0[0] =1 and I wanted to send to portb the bits in train 1,2,3,4,5,6,7 to make portb pins 1-7 high or low depending on how the bits are set in train but I wanted portb.0 to be high or low depending on the value of car. In this way I could have portb pin 0 showing a car is there and portb pins 1-7 providing high or low outputs to control other things. How could I do this together? The Pic I am using is a 16f628a.

    If I understand you correctly, you want PORTB to be equal to bit0 from CAR and bits1-7 from TRAIN?


    Code:
    SETB VAR  BYTE
    
    ' In your program somewhere
    
    SETB = TRAIN	
    SETB.0 = CAR.0	' redefine bit0 to match that of Car's bit 0
    PORTB = SETB 	' set  PORTB equal to the desired values of bit 0 from Car and bits 1-7 from train
    This could also be easily done with boolean (bitwise) algebra if speed or program size is of importantance.
    Last edited by paul borgmeier; - 31st January 2008 at 18:29.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. PIC's ports individual bits manipulation - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 27th February 2007, 22:34
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

Members who have read this thread : 0

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