MShift Function | Port | I/O | turn ON | turn OFF | to READ | NOTES |
Brake Sense | PAD07 | I | -- | -- | (PORTAD0 & 0x80) | digital input |
Paddle DOWN | PAD06 | I | -- | -- | (PORTAD0 & 0x40) | on/off |
non-CAN MAP/TPS/MAF | PAD05 | I | -- | -- | ATD0DR5 | ADC count |
line pressure sensor | PAD04 | I | -- | -- | ATD0DR4 | ADC count |
switchC | PAD03 | I | -- | -- | ATD0DR3 | ADC count (0-1024) |
Temp Sensor | PAD02 | I | -- | -- | ATD0DR2 | ADC count (0-1024) |
switchB | PAD01 | I | -- | -- | ATD0DR1 | ADC count (0-1024) |
switchA | PAD00 | I | -- | -- | ATD0DR0 | ADC count (0-1024) |
Spare Output1 | PT7 | O | *pPTTpin[7] |= 0x80; | *pPTTpin[7] &= ~0x80; | --- | on/off |
Paddle UP | PT6 | I | -- | -- | (PTT & 0x40) | digital input |
ISS | PT5 | I | --- | --- | Interrupt ISS_timer() | interrupt service rotuine called on edge |
Speedo Output | PT4 | O | PWMDTY4 = 0; | PWMDTY4 = PWMPER4; | PWMDTY4 | 0 < PWMDTY4 < PWMPER4 |
TCC | PT3 | O | PWMDTY3 = 0; | PWMDTY3 = PWMPER3; | PWMDTY3 | 0 < PWMDTY3 < PWMPER3 |
PC | PT2 | O | PWMDTY2 = 0; | PWMDTY2 = PWMPER2; | PWMDTY2 | 0 < PWMDTY2 < PWMPER2 |
Sol32 | PT1 | O | PWMDTY1 = 0; | PWMDTY1 = PWMPER1; | PWMDTY1 | 0 < PWMDTY1 < PWMPER1 |
VSS | PT0 | I | --- | --- | Interrupt VSS_timer() | interrupt service called on edge |
LED4 | PB4 | O | PORTB |= 0x10; | PORTB &= ~0x10; | --- | on/off |
LED3 | PM5 | O | *pPTMpin[5] |= 0x20; | *pPTMpin[5] &= ~0x20; | --- | on/off |
LED1 | PM4 | O | *pPTMpin[4] |= 0x10; | *pPTMpin[5] &= ~0x10; | --- | on/off |
LED2 | PM3 | O | *pPTMpin[3] |= 0x08; | *pPTMpin[5] &= ~0x08; | --- | on/off |
Sol B | PM2 | O | *pPTMpin[2] |= 0x04; | *pPTMpin[5] &= ~0x04; | --- | on/off |
Sol A | PE4 | O | PORTE |= 0x10; | PORTE &= ~0x10; | --- | on/off |
4WD input | PE1 | I | -- | -- | (PORTE & 0x02) | digital input |
Spare Output2 | PA0 | O | PORTA |= 0x01; | PORTA &= ~0x01; | --- | on/off |
Port DDR (data direction register) Configuration
Many of the I/O port pins on the 9S12C64 processor can be configured as either an input or an output. The way you tell the processor which should be what is by filling zeros or ones in the data direction registers.
0=input, 1=output, x=not assigned (default is input)
For the MegaShift, for example, we want:
Bit | 76543210 | decimal | hexadecimal |
PA | xxxxxxx1 | = 01 | DDRA= 0x0001 |
PB | xxx1xxxx | = 16 | DDRB= 0x0010 |
PE | xxx1xxx1 | = 16 | DDRE= 0x0011 |
PM | xx1111xx | = 60 | DDRM= 0x003C |
PT | 10011110 | =158 | DDRT= 0x009E |
BTW, these user configurable input/output ports are called "general purpose I/O" ports which is where the GPIO board gets its name.
Examples:
PORTE is defined in hcs12def.h and is memory addresss (*((volatile unsigned char*)(0x0008))) where "volatile unsigned char" means that this is an 8 bit postive only value (unsigned char) that might be changed externally to the code logic ("volatile"), such as by an interrupt.
By 'ANDing' PORTE with 0x10, we are comparing PTT to 0x10 (which is hex, the binary is 00010000 - 8 bits). This compares the current values bit by bit with 00010000, and set the corresponding PTT bit to 1 if the bits in both are 1, otherwise it is set to zero. Operations like this are called 'bitwise'.
The net result is that since bit 4 (they are numbered 0 to 7 from left to right) is one it will be ANDed to 1 if bit 4 in PORTE is one, since the rest of the ANDs will be zero (anything ANDed with zero is zero). So the result is true (==1) if bit 4 is 'on', and false (==0) if bit 4 is 'off'.
Note that we can AND or OR. AND is usually used to check a bit state. Both AND and OR are used to set bit states.
For example, if we want to set port B pin 3 high, we would use:
PORTB |= 0x08; //(i.e., if either PORTB or 000001000 are bitwise one, set that bit to one)
To turn the same bit off, we use:
PORTB &= ~0x08; // (i.e., if both PORTB and ~00001000 == 11110111 are one, set to one, set to zero otherwise. Since the #3 bit of ~0x08 is never one, this sets the corresponding PORTB bit to zero)