Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
Initializing the Port pins to a specific value in the Boot.tpl file
Question: The code which runs prior to the execution of main( ) initializes the Port pins to a default value, which is LOW. How do I make the default state of the pin to be HIGH after reset?
This can be done by modifying the boot.tpl code.
In the boot.tpl file, just before the call to LoadConfigInit, write a 1 to the corresponding bits of the Port data registers (PRTXDR). For example, to initialize P1 and P1 to a HIGH state after power up, add the following code in boot.tpl before the call to LoadConfigInit.
mov reg[PRT1DR], 0xA0
When the pin's drive mode gets configured in LoadConfigInit function, the pin state will change to HIGH.
Further, note that it is always advisable to add a comment in the beginning of main.c about the modification in boot.tpl. This is because, in the future versions of the designer, the Boot.tpl file might be updated and if the user decides to upgrade to the new Boot.tpl file, then the modifications done to the Boot.tpl file will be lost.
So, it is always advisable to have a record of the change in the main.c file. A solution for that is to keep the drive mode of the pin as High Impedance Analog in device editor view and in the application code area, assign a default state to the pin and then configure the drive mode.