Individual Variable bits


Results 1 to 5 of 5

Threaded View

  1. #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 19: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, 08:55
  2. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 01:06
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21: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, 23:34
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 15: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