| ??? 05/02/02 06:34 Read: times |
#22404 - RE: passing port pin to a function |
Hi Mahmood,
this is the big disadvantage of C programming, that none of the guys read the damned processor instruction set. Only every assembler programmer know, that it was impossible to access bits indirect on the 8051 architecture. I assume it was also impossible on all architectures. So its no question, that also no compiler support it. But if program space and execution time was not critical, it can be simulated with a big switch statement: sbit P0_0 = P0^0; sbit P0_1 = P0^1; // etc. sbit P3_7 = P3^7; void setbit( char bit_no, char bit_state ) { switch( bit_no ){ case 0x80: P0_0 = (bit_state != 0); break; case 0x81: P0_1 = (bit_state != 0); break; case 0x82: P0_2 = (bit_state != 0); break; // etc. case 0xB7: P3_7 = (bit_state != 0); break; } } But the usage of such a function to build e.g. UART, I2C, SPI, 1-wire interfaces may be impossible or can reduce the overall speed dramatically. On reentrant functions you must use char instead bit, since bits also not can be pushed. Peter |



