Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

constant name instead of pin address

Status
Not open for further replies.

rezaf

Advanced Member level 4
Joined
Apr 11, 2009
Messages
106
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
Montagram
Activity points
2,147
Hi;
how can I give separate name to every pin, instead of repeating it's address (in C language and in mikroC pro for PIC compiler)?
for example led1=1; instead of PORTB0_bit=1; .
 

You can use #define for a constant or a macro

#define led1 PORTB0_bit

After that whenever you write led1 it will be the same as PORTB0_bit

Another macro you can use is

#define led1on PORTB0_bit=1;
#define led1off PORTB0_bit=0;

in that case all you need to write is led1on to set the bit (PORTB0_bit=1) and led1off to clear the bit (PORTB0_bit=0)

You can take a look at
Tutorials - C Preprocessor Tricks - Cprogramming.com
 

    V

    Points: 2
    Helpful Answer Positive Rating
Very thanks, the second method you said worked but the first method give error in compiler . I written :
Code:
#define tx_l RB7_bit;

void stop(){
 tx_l = 1;
 UART1_Write(0x53);
 tx_l = 0;
}
void main(){
}
with this code, the compiler give error in tx_l = 1; line. what is wrong?
 

Is RB7_bit defined and what does it represent?

In the previous post you asked about PORTB0_bit , are you sure that they can both be used?

If you use RB7_bit=0; in your code does it work?
 

you have a ; on the end of
Code:
#define tx_l RB7_bit;
which will replace occurances of tx_l with RB7_bit; giving
Code:
void stop(){
 RB7_bit; = 1;
 UART1_Write(0x53);
 RB7_bit; = 0;
}
void main(){
}
remove the ;
 
  • Like
Reactions: rezaf

    rezaf

    Points: 2
    Helpful Answer Positive Rating
sorry I wrongly written PORTB0_bit . in mikroc pro has TRISB0_bit and RB0_bit.
yes if I use RB7_bit=0; it takes this pin to low state.

yes horace1 the ; was wrong at end of line and with deleting it the problem resolved.

Thanks "alexan_e" and "horace1" for yor answers. you very helped me.
I go to test my program.
Best Regards.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top