Pic 18 Microcontroller Notes
Pic 18 Microcontroller Notes
; Perform multiplication
CLRF REG4 ; Clear reg4
CLRF REG5 ; Clear reg5
MOVLW 08H ; Load loop counter with value 08H
MOVWF REG3 ; Store loop counter in reg3
LOOP:
RRF REG2,F ; Right shift reg2 to get the next bit
BTFSC STATUS,C ; Check carry flag
ADDWF REG4,F ; Add reg1 to reg4 if carry flag is set
RLF REG1,F ; Left shift reg1
DECFSZ REG3,F ; Decrement loop counter and skip next instruction if it is zero
GOTO LOOP ; Jump to LOOP label if loop counter is not zero
; Terminate program
END ; End of program
; Define constants
LED_PIN equ PORTB,1 ; LED connected to RB1
DELAY_TIME equ 62500 ; 1 second delay at 4MHz
; Delay routine
delay:
movlw .61 ; Load high byte of delay time
movwf TMR0H ; Set Timer0 high byte
movlw .28 ; Load low byte of delay time
movwf TMR0L ; Set Timer0 low byte
bsf INTCON,T0IF ; Clear Timer0 interrupt flag
bsf T0CON,TMR0ON ; Turn on Timer0
delay_loop:
btfss INTCON,T0IF ; Check for timer interrupt
goto delay_loop ; Wait for timer interrupt
bcf T0CON,TMR0ON ; Turn off Timer0
retlw 0 ; End of delay routine
Prescaler is a name for the part of a microcontroller which divides oscillator clock before it will reach logic that increases timer status. The range of the prescaler id is from 1 to 256 and the value of the Prescaler can be set using the OPTION
Register (The same one that we used for pull up resistors). For example if the value of prescaler is 64, then for every 64th pulse the Timer will be incremented by 1.
As the timer increments and when it reaches to its maximum value of 255, it will trigger an interrupt and initialize itself ot 0 back again. This interrupt is called as the Timer Interrupt. This interrupt informs the MCU that this particular time has
lapped.
From <https://circuitdigest.com/microcontroller-projects/pic-microcontroller-timer-tutorial>