0 item/s in cart
'In this program section, the variable stored in register sum is incremented every 'time the RB0 input pin is driven high (1) ... if PORTB.0 = 1 ' Check whether the RB0 pin is driven high sum = sum + 1 ' If true, the variable value is incremented by 1 end if ' If false, the program exits the if statement ...The microcontroller is able to execute this program as it knows what the sum to be incremented is and where it is stored. Similarly, each program variable must be preassigned some of the general-purpose registers.
'In this program section, registers TRISC and PORTC are changed ... TRISC = 0x00 ' a logic zero (0) is written to register TRISC (all port ' PORTC pins are configured as outputs) PORTC = %01100011 ' Logic states on all port PORTC pins are being changed ...
' When entering an assembly code section inserted in the program, the compiler ' stores data in the currently active RAM bank. It means that in this program ' section, bank selection depends on the SFRs in use. After return to the program ' section written in mikroBasic, the control bits selecting the active bank '(RP0 and RP1) must return the state they had before the assembly code ' execution. The saveBank auxiliary variable saves the state of these two bits. saveBank = STATUS and %01100000 ' Save the state of bits RP0 and RP1 ' (bits 5 and 6 of the STATUS register) asm ' Start of assembly sequence ... ... ' Assembly code ... end asm ' End of assembly sequence STATUS = STATUS and %10011111 ' Bits RP0 and RP1 return their original state STATUS = STATUS or saveBank ... ...
RETFIEinstruction, pops the address from the stack and proceeds with program execution from where it left off.
sub procedure interrupt ' Interrupt routine cnt = cnt + 1 ; ' Interrupt causes variable cnt to be incremented by 1 end sub