Exploring STC MCU part 3.5 – bug explained

The bug I encountered on STC15W4K61S4 is resolved: this chip, being much more complicated than the traditional 8051 my textbooks was written for, have a bit of quirks that can break code compatibility between them.

STC chips comes with true bidirectional I/O pins instead of the classic quasi-bidirectional pins found on older 8051 products. Although most of the pins default to quasi-bidirectional mode upon boot, there are a few pins on STC15W4K61S4 that starts in high-impedance input mode, with P2.7 being one of them. Code have to be present to switch the port into either quasi-bidirectional or push-pull output mode.

The reason that this issue is masked during debug is because the OCD monitor program have initialized the port for me.

The following is the modified blinky code that have the appropriate initialization code:

#include "system.h"

int main(void)
{
	systick_init();
	P2M1 = 0; // Switch P2.[4..7] to push-pull output.
	
	for (;;)
	{
		P27 = !P27;
		delay(500);
	}
}

Leave a Reply