User manual
176
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
To correct the problem in the code, insert a delay after each PORTB.Bx = 1 line, or modify the entire PORTB register
in a single line PORTB = 0b00000011.
This problem can be avoided by using LATx register when writing to ports, rather than using PORTx registers.
Writing to a LATx register is equivalent to writing to a PORTx register, but readings from LATx registers return the
data value held in the port latch, regardless of the state of the actual pin.
For example, lets analyze the following example:
LATB.B0 = 1
LATB.B1 = 1
The rst line, LATB.B0 = 1 will be decoded in this way:
READ LATB is read:
STORE Data is stored inside a temporary internal
register in the MCU:
Actual voltage levels on MCU pins are no longer relevant when using LATx for output
MODIFY Data is modied to set the RB0 bit:
WRITE LATB is written with the modied data.
The output driver for RB0 turns on, and the
capacitor starts to charge: