Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/01/02 17:36
Read: times


 
#22377 - RE: passing port pin to a function
In the end, you cannot pass a register as pointer to a function. That's just life. What you can do is enumerate the port pins with meaningful names or write functions with meaningful names. E.g.
sfr  r_ledPort  = 0x80; /* Port 0 */
sfr  r_crtlPort = 0x90; /* Port 1 */
sbit r_greenLed = r_port0 ^ 5;
sbit r_extReset = r_port1 ^ 7;

enum OurPins
{
    GREEN_LED,
    EXTERNAL_RESET,
    NUM_PINS
};

bit setPortPin(enum OurPins pin)
{
    bit failure = 0;
 
    switch (pin)
    {
        case GREEN_LED:
            r_greenLed = 1;
            break;
      
        case EXTERNAL_RESET:
            r_extReset = 1;
            break;

        default:
            failure = 1;
            break;
    }
 
   return failure;
}

bit clrPortPin(enum OurPins pin)
{
    bit failure = 0;
 
    switch (pin)
    {
        case GREEN_LED:
            r_greenLed = 0;
            break;
      
        case EXTERNAL_RESET:
            r_extReset = 0;
            break;

        default:
            failure = 1;
            break;
    }
 
   return failure;
}
The beauty of this method is you could port upper level code to another processor easily. Just re-write the set/clr functions for the new chip.

List of 25 messages in thread
TopicAuthorDate
passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin (to Bert)            01/01/70 00:00      
RE: passing port pin (to Bert)            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin (to Mahmood) J.            01/01/70 00:00      
RE: passing port pin (to Mahmood) J.            01/01/70 00:00      
RE: passing port pin (to Mahmood) J.            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin to a function            01/01/70 00:00      
RE: passing port pin (to Mahmood)            01/01/70 00:00      

Back to Subject List