Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 27, 2024, 10:29:36 10:29


Login with username, password and session length


Pages: [1]
Print
Author Topic: Active assignment of mnemonic to pins  (Read 11821 times)
0 Members and 2 Guests are viewing this topic.
weazuul
Guest
« on: February 17, 2006, 12:37:51 12:37 »

I want to assign a name to 2 pins on a PIC 12F629. The problem is that I want to assign the same name to those pins (but not at the same time) and while the program is running. Here is some code to give you an idea - i know it isnt correct cuz it usses precompile directives but this explains the best what i mean cuz those pragmas can be used in the begining to assign a name to a certain pin. I use CC5X as a compiler but i dont think that other compilers give a solution to this (one that i know of) . I wanted to use pointers but you just cant have pointers to bit variables  Sad
Code:

bit test_bit;

void funtion(void)
{
    if(test_bit == 0)
    {
      #pragma bit PIN1 @ GPIO.1
    }
    else
    {
      #pragma bit PIN1 @ GPIO.2
    }
}


Ty for help
Logged
parallaxis
Junior Member
**
Offline Offline

Posts: 77

Thank You
-Given: 3
-Receive: 3


« Reply #1 on: February 17, 2006, 01:33:38 13:33 »

There is one big error...

#pragma is a pre-processor directive, i.e. PRAGMAs are evaluated BEFORE compiling. Everywhere and always.

So it's impossible to name pin this way in C language. You cannot assign COMPILER SYMBOLIC NAME during RUN TIME - it's possible in interpreted languages, not in compiled.

So remember: ALL directives begins with # in C are evaluated BEFORE compiling the main code (#include, #if, #endif, #pragma, #define, #ifdef etc.)
Logged
weazuul
Guest
« Reply #2 on: February 17, 2006, 03:33:36 15:33 »

I saied that is not correct, i just used tht so i can explain better what i need
Quote
Here is some code to give you an idea - i know it isnt correct cuz it usses precompile directives but this explains the best what i mean cuz those pragmas can be used in the begining to assign a name to a certain pin.

I need to know how i can do that assignment within a program function, while the program is running. Or any tipe of refereance to those 2 pins with the same variable/pointer something like that
« Last Edit: February 17, 2006, 03:53:07 15:53 by weazuul » Logged
parallaxis
Junior Member
**
Offline Offline

Posts: 77

Thank You
-Given: 3
-Receive: 3


« Reply #3 on: February 18, 2006, 01:12:13 01:12 »

Sorry, my mistake... Sad

The best way is to use mask variable, like this:
 
Code:
 bit test_bit;
byte mask;
void funtion(void)
{
    if(test_bit == 0)
    {
      mask=0b00000001;
    }
    else
    {
      mask=0b00000010;
    }
}

and testing/setting values this way:

Set:
 
Code:
 GPIO |= mask;

Clear:
 
Code:
 GPIO &= ~mask;


Read value:
value=(GPIO & mask)?1:0;
or simplier - if (GPIO & mask) {...}

I don't know the CC compiler syntax, but in MCHP C I'm using constructions like "PORTB |= mask;" (or "LATC=PORTC|mask;" with C18)

If you need to use two different ports, you must use pointer to memory area where desired port is mapped...

I apologize for my mistake once more, hope this helps...
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC