embedded c and the 8051 microcontroller

Viewed 1206

Upon reset of the 8051 microcontroller, all the port-pin latches are set to values of ‘1’. Now I am reading this book "Embedded C" and it states thr problem with the below code is that it can lull the developer into a false sense of security:

// Assume nothing written to port since reset
// – DANGEROUS!!!
Port_data = P1;

If, at a later date, someone modifies the program to include a routine for writing to all or part of the same port, this code will not generally work as required:

unsigned char Port_data;
P1 = 0x00;
. . .
// Assumes nothing written to port since reset
// – WON’T WORK BECAUSE SOMETHING WAS WRITTEN TO PORT ON RESET
Port_data = P1;

Anyone with knowledge of embedded c can explain to me why this code won't work? All it does is assign 0 to a char variable.

2 Answers
Related