I am having a tough time understanding how registers work. I am working specifically with the MSP430g2231 from the LaunchPad. I know Port 1 has 8 pins. If I look at the memory map from the data sheet it says Port 1 is 8 bits (at least I think). Therefore each pin seems as if it should be one bit. This would make sense. If the were all 0 you would have 0b00000000 or all ones 0b11111111.
However when I look further I see that Port 1 has 8 registers the most important being P1IN, P1OUT and P1DIR. Each of these registers has a memory location 0x20, 0x21, and 0x22 respectively. 0x20 is 0b00100000. If I understand it correctly each one of these registers has an effect on each of the 8 pins. This makes me believe that each register is one byte.
If I look at it from the top down I get confused. I thought I had a Port which is 8 bits in size giving me one byte. Then I look at the registers P1IN etc and I think I have 8 registers each being 8 bits so then I would have 8 bytes. Obviously this makes my thoughts on Port 1 being 8 bits seem wrong. If I continue to try and make sense of it I get really confused. I am going to try and explain. If I use register P1IN as an example which is at memory location 0x20 this seems like it should be 1 bit. In binary it is 0b00100000. However I realize each pin can be set by each register. So this would mean that 0x20 was a byte and I can change its 8 bit to one's or zeros. If I were to type
P1IN = 0x00;
this sets everything to 0. So if P1IN is at memory location 0x20 or 0b00100000 (I thought a bit) how can I set something below it to all 0's. I thought 0x20 was the bit.
Clearly I am confused. I hope this makes sense to someone who can help me out. If you could possibly go from the top down explaining what a Port is (byte or bits or what ever), then a register, on to the pins it would be greatly appreciated. Maybe I have the order wrong. I am not sure.
Take care,
Jon