0
\$\begingroup\$

For the initialisation of an I/O in the pic the datasheet indicates to clear set the TRIS correctly and clear both PORT and LAT bits. I thought I understood why and the program works. When looking at the disassembly however the PORT clearing and LAT clearing generate the same instructions. I did not look further but I think that the PORT bits are cleared as a result of the LAT bits clearing.

Is there a specific reason that the datasheet (asm) indicated to clear both PORT and LAT and in C it boils down to one action only on LAT.

C code example lead both to identical asm after compilation:

PORTAbits.RA0 = 0;
LATAbits.LATA0 = 0;
\$\endgroup\$
6
  • \$\begingroup\$ What is the C code and what is the assembly generated? \$\endgroup\$
    – Eugene Sh.
    Commented May 17, 2017 at 18:39
  • \$\begingroup\$ Samples of C included \$\endgroup\$
    – Decapod
    Commented May 17, 2017 at 18:45
  • \$\begingroup\$ Still, it is incomplete without the assembly generated.. BTW, can you look around your headers ans see the exact definition of PORTA and LATA ? Could it be that they are just the same register? \$\endgroup\$
    – Eugene Sh.
    Commented May 17, 2017 at 18:49
  • \$\begingroup\$ Reason found. In the lib used there was a macro with a typo leading to this behaviour. After correcting this both registers are handled the same way as in the specsheet \$\endgroup\$
    – Decapod
    Commented May 17, 2017 at 19:07
  • \$\begingroup\$ Is it the vendor provided macro or some homebrew/thirparty? \$\endgroup\$
    – Eugene Sh.
    Commented May 17, 2017 at 19:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.