background image

 Port Initialization

and Direction Control

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

Semiconductor Group

6 of 7

AP164601   1998-02

However, the following sequence is not recommended:

BSET P3.13

; set P3.13/WR#/SCLK to ’1’

BSET DP3.13

; set direction of P3.13 to output

BSET P3.10

; set P3.10/TxD0 to ’1’

CAUTION: P3.13 is not yet switched to output when this instruction reads P3
;

(pipeline effect)

; ==> P3.13 value read from pin, maybe undefined
; ==> P3.13 SFR value may be overwritten with pin value by this instruction
; ==> no WR# strobe or shift clock may be output

BSET DP3.10

; set direction of P3.10 to output

...

Therefore, when several pins are to be initialized with single bit instructions on the same
port (and this port does not have bit protection), it is important that an instruction which
does not access this port is placed between two BSET Px / BSET DPx instruction pairs,
and in general after each instruction which has modified the port direction, as follows:

BSET P3.13

; set P3.13/WR#/SCLK to ’1’

BSET DP3.13

; set direction of P3.13 to output

NOP

; or other instruction which does not access P3

BSET P3.10

; set P3.10/TxD0 to ’1’

BSET DP3.10

; set direction of P3.10 to output

NOP

; or other instruction which does not access P3

Or, on C level:

_pubit (P3,13);
_pubit (DP3,13);
_nop();
_pubit (P3,10);
_pubit (DP3,10);
_nop();

When several pins in different bytes of a port (without bit protection) are to be initialized
with Bit Field instructions, also care must be taken that subsequent instructions will read
the correct port status, e.g.

BFLDH P3,#24h,#24h

; set P3.13/WR#/SCLK and P3.10/TxD0 to ’1’

BFLDH DP3,#24h,#24h

; switch P3.13 and P3.10 to output

NOP

; or other instruction which does not access P3

BFLDL P3,#0Ah,#0Ah

; set P3.1/T6OUT and P3.3/T3OUT to ’1’

BFLDL DP3,#0Ah,#0Ah

; switch P3.1 and P3.3 to output

NOP

; or other instruction which does not access P3

Summary of Contents for AP164601

Page 1: ...ntrol This Application Note discusses various aspects of the initialization of port pins as outputs effects of single Bit and Bit Field BFLDL H instructions ports with bit protection initialization of alternate output functions effects of interrupts during port initialization and bitfield function in C compilers Author Christoph Meinhold HL DC AT ...

Page 2: ...ration as General Purpose Outputs 3 2 2 Configuration of Alternate Output Function 5 2 3 Configuration of CAPCOM Pins 5 3 Initialization of several Port Pins on the same Port 5 AP164601 ApNote Revision History Actual Revision Rel 1 0 Previous Revison Rel 0 0 Page of Actual Rel Page of prev Rel Subjects changes since last release 7 7 Example for bit field function in C added ...

Page 3: ...ardware All other pins have to be configured by software when they are to be used as outputs 2 Initialization of Single Port Pins as Outputs 2 1 Configuration as General Purpose Outputs When a port pin is to be used as general purpose output first the initial output value should be written to the port data register and then the direction of this pin should be set to output to achieve a defined tra...

Page 4: ... are modified by the on chip periperal units from unintentionally being overwritten by a bit read modify write sequence via Bit and Bit Field instructions see section Protected Bits and Bit Handling and Bit Protection in respective User s Manual e g C167 Derivatives User s Manual V2 0 p 2 17 and p 4 9 It is therefore advised to always set the port data register and the port direction register at l...

Page 5: ...l will appear at the pin For P3 13 WR of 8xC166 microcontrollers in particular this low level will be regarded as write strobe by external memory devices and unexpected results may occur 2 3 Configuration of CAPCOM Pins When a Port 2 pin is to be used as compare signal output alternate function for the CAPCOM unit of 8xC166 microcontrollers respectively Port 7 and Port 8 for CAPCOM2 unit on other ...

Page 6: ...T Px BSET DPx instruction pairs and in general after each instruction which has modified the port direction as follows BSET P3 13 set P3 13 WR SCLK to 1 BSET DP3 13 set direction of P3 13 to output NOP or other instruction which does not access P3 BSET P3 10 set P3 10 TxD0 to 1 BSET DP3 10 set direction of P3 10 to output NOP or other instruction which does not access P3 Or on C level _pubit P3 13...

Page 7: ...A 0x240A This instruction sequence may result in the following assembler instruction sequence BFLDH P3 24h 24h set P3 13 WR SCLK and P3 10 TxD0 to 1 BFLDL P3 0Ah 0Ah set P3 1 T6OUT and P3 3 T3OUT to 1 CAUTION P3 13 and P3 10 are still inputs when this instruction reads P3 P3 13 and P3 10 values read from pin maybe undefined P3 13 and P3 10 SFR values may be overwritten with pin values no WR strobe...

Reviews: