Dec 26, 2011 #1 R 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; .
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; .
Dec 26, 2011 #2 alexan_e Administrator Joined Mar 16, 2008 Messages 11,888 Helped 2,021 Reputation 4,158 Reaction score 2,031 Trophy points 1,393 Location Greece Activity points 64,371 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
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
Dec 27, 2011 #3 R 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 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?
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?
Dec 27, 2011 #4 alexan_e Administrator Joined Mar 16, 2008 Messages 11,888 Helped 2,021 Reputation 4,158 Reaction score 2,031 Trophy points 1,393 Location Greece Activity points 64,371 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?
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?
Dec 27, 2011 #5 H horace1 Advanced Member level 5 Joined Nov 18, 2008 Messages 2,118 Helped 596 Reputation 1,188 Reaction score 571 Trophy points 1,393 Location Norwich, UK Activity points 13,063 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 ;
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 ;
Dec 27, 2011 #6 R 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 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.
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.