KidE:
Like i said:
PORT0 has 31 PIN’s / BITS I/O and 1 PIN/BIT only O (PIN 32) P0.0/P0.31
PORT1 has 16 PIN’s (32 BIT’s??) I/O P1.16/P1.31
Starting from 0 port0 has 31 pins I/O and 1 pin only O (pin 32)
This depends on the function as i look in the manual
Ah, I see what you were getting at. Ok then. I agree. :mrgreen:
If i look at the schematic i see port1 is bussed to JTAG but at the connector i see pins P1.16/P1.25 breaking out again while P1.26/P1.31 are connected to the JTAG connector
That's so you can use them for General Purpose I/O when the JTAG isn't being used. If you really need those pins then you're going to have to bootload your code.
Lets take PORT0 as an example:
All pins (except 31) have multiple functions which you can select with PINSEL to tell the chip which function that pin has. right?
Correct.
All functions have 4 registers for controlling the “active” function of that pin. right?
Correct.
But only one thing i don’t (not yet at least) understand is where do i find that bit 0x00000800 belongs to that LED and that specific pin?
Looking at the manual i dont find it
For that you look at the schematic. On this board there happens to be LEDs on pins P0.10 and 11. (On other boards those pins might go to other things). P0.10 is bit-10 of Port0, and P0.11 is bit-11 of Port0 (counting from zero always). Each of the 32 pins corresponds to one bit of an int (32-bits). So to make it easy just scribble this out on paper. In Port0 there are four bytes (32-bits)
4 3 2 1
7654 3210 : 7654 3210 : 7654 3210 : 7654 3210
The bits are numbered as follows. Again, I’ve separated the bytes for clarity:
31 30 29 28 27 26 25 24 : 23 22 21 20 19 18 17 16 : 15 14 13 12 11 10 09 08 : 07 06 05 04 03 02 01 00
Each of those bits corresponds to one pin of P0:0 to P0:31.
Each byte is 8 bits as above. In a byte there are two nybbles of 4 bits each. Like this:
3210
The values of those 4 bits are as follows:
8421
Add those four values up if all bits are set and you get 0xf for the nybble. Put two nibbles together with all bits set and you get 0xff. You can use this as a quick way to convert binary to hex in your head.
Another quick example. A byte:
0110 1010
Quick conversion to hex goes like this. The top nybble has the 2 and 4 bits set. It’s 0x6. The low nybble has the 8 and 2 bits set. That’s 0x0a (10 decimal). The whole byte’s value is 0x6a. Simple, right? :mrgreen:
So anyway, 0x00000800 means that the 8 bit of the second from lowest byte of Port0 is set, or bit-11. Count from the right starting at zero. 0 1 2 3 4 5 6 7. That’s the lowest byte. Then into the second byte with 8 9 10 11 (but think the values of the bits in the nybble, which are 1 2 4 8 ). The 8 bit in the low nybble of that second byte is set. Thus P0.11, or 0x00000800.
Let’s diagram that out. 0x00000800 would be like this:
31 30 29 28 27 26 25 24 : 23 22 21 20 19 18 17 16 : 15 14 13 12 11 10 09 08 : 07 06 05 04 03 02 01 00
See the red bit? That’s our 8 position in that nybble (bit 3 of the byte).
Confused yet? You will be. You WILL be. But then it will all make sense. To program computers you MUST be able to think in hexadecimal and binary and translate back and forth without having to think too much about it. A hex/binary/decimal converter calculator can be a help sometimes too.
Don’t be offended if I go too newb on ya. I don’t know for sure what you know or don’t know. I err on the side of ultra newbness. :mrgreen: