Thread: Using Variable Names When Calling a MC PIN High or Low

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    8

    Using Variable Names When Calling a MC PIN High or Low

    I haven't tried to run my program yet, but maybe I will save some trouble if I ask this question first.

    I am using MC PIC16F690, and I could make a pin high or low by writing RCx = 1 or 0, where x is the pin in the C port. However, I want to use the counter variable from a for() loop as the pin number. Will RC(variablename) = 1 work, or is there another syntax?

    Thanks....

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    No it wont.
    If they are separate variables, and you have no say in that matter (which is probably the case), then use a switch statement.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You could look to see how RCx is defined.

    If it's something like
    #define RC1 port |= (1<<1)

    Then you can just ignore all that and write in your code loop
    port |= (1<<loopVar)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Variable names starting with _
    By edesign in forum C Programming
    Replies: 3
    Last Post: 06-05-2009, 03:47 AM
  2. Variable object names
    By Rider in forum C++ Programming
    Replies: 4
    Last Post: 11-02-2006, 01:48 AM
  3. i j k variable names
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 10-12-2006, 04:25 PM
  4. Variable Names based on Variable Values
    By mrpickle in forum C++ Programming
    Replies: 6
    Last Post: 01-27-2003, 10:33 AM
  5. variable names
    By trekker in forum C Programming
    Replies: 3
    Last Post: 03-16-2002, 03:37 AM