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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/08/09 07:02
Read: times


 
#164474 - Unnecessarily complicated!
Responding to: ???'s previous message
Mahesh Joshi said:
xdata unsigned char at 0x4000 MY_8255_BASE[4];

//MY_8255_BASE[4] represents Port-A, Port-B, Port-C & Control Registor of 8255
 

Exactly:
Accessing MY_8255_BASE[0] accesses the Port-A Register of the 8255;
Accessing MY_8255_BASE[1] accesses the Port-B Register;
Accessing MY_8255_BASE[2] accesses the Port-C Register;
Accessing MY_8255_BASE[3] accesses the Control Register.

The array alone gives you access to all the registers!

So what is the point of adding a pointer:
unsigned char *ptr_8255;

void init_8255(unsigned char control_word)
{
	ptr_8255 = MY_8255_BASE;
	*(ptr_8255 + 3) = control_word;
}
 

It just adds an unnecessary level of indirection - to no benefit!

Wouldn't it be far simpler & clearer to just write:
void init_8255(unsigned char control_word)
{
        MY_8255_BASE[3] = control_word;

}
 


You could also make it clearer by defining symbolic names for the array indexes; eg,

enum
{
   PPI_PORT_A  = 0, // Index for Port-A
   PPI_PORT_B  = 1, // Index for Port-B
   PPI_PORT_C  = 2, // Index for Port-C
   PPI_CONTROL = 3  // Index for the Control register
}

 

And then have:

void init_8255(unsigned char control_word)
{
	MY_8255_BASE[ PPI_CONTROL ]  = control_word;
}
 

Which doesn't even really need to be in a function call...


List of 25 messages in thread
TopicAuthorDate
How to access memory mapped 8255 with SDCC?            01/01/70 00:00      
   also asked here:            01/01/70 00:00      
   8255 with SDCC            01/01/70 00:00      
   Wrong question?            01/01/70 00:00      
      It's C            01/01/70 00:00      
         not on the 8051            01/01/70 00:00      
            Oh yes it is!            01/01/70 00:00      
   Use XBYTE macro            01/01/70 00:00      
      Isn't there a problem with that?            01/01/70 00:00      
         Oops. I used a wrong example            01/01/70 00:00      
            Portability            01/01/70 00:00      
               like this...            01/01/70 00:00      
   How about a macro in ASM, callable from 'C'?            01/01/70 00:00      
      This is HOW I will Prefer            01/01/70 00:00      
         LST output of my previously posted code            01/01/70 00:00      
            Try the comparison            01/01/70 00:00      
         Unnecessarily complicated!            01/01/70 00:00      
            NOT UNNECESSARILY            01/01/70 00:00      
               You are mistaken            01/01/70 00:00      
               Array or pointer similar            01/01/70 00:00      
      That should not be necessary            01/01/70 00:00      
         SFRX(...,. ..) worked            01/01/70 00:00      
            SFRX - presumably, that's an SDCC extension?            01/01/70 00:00      
               Found it!            01/01/70 00:00      
                  RE: Found it!            01/01/70 00:00      

Back to Subject List