0% found this document useful (0 votes)
4 views

demo

This document contains assembly code for the PIC16F887 microcontroller, which sets up the device configuration and initializes PORTB as an output. It includes a main loop that toggles an LED connected to RB0 with a delay subroutine to control the timing of the LED blinking. The delay is implemented using nested loops to create a specific timing interval.

Uploaded by

lengocminhdang04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

demo

This document contains assembly code for the PIC16F887 microcontroller, which sets up the device configuration and initializes PORTB as an output. It includes a main loop that toggles an LED connected to RB0 with a delay subroutine to control the timing of the LED blinking. The delay is implemented using nested loops to create a specific timing interval.

Uploaded by

lengocminhdang04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

LIST P=16F887

#include <P16F887.INC>

__CONFIG _CONFIG1, _FOSC_INTRC_NOCLKOUT & _WDTE_OFF &


_PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON &
_IESO_ON & _FCMEN_ON & _LVP_OFF

__CONFIG _CONFIG2, _BOR4V_BOR40V & _WRT_OFF

ORG 0x0000 ; Reset vector


GOTO START ; Jump to the start of the program

ORG 0x0004 ; Interrupt vector (not used in this example)


RETFIE ; Return from interrupt

START:
BSF STATUS, RP0 ; Bank 1
CLRF TRISB ; Set PORTB as output
BANKSEL PORTB
BCF STATUS, RP0 ; Bank 0
MAIN_LOOP:
BSF PORTB, RB0 ; Turn on LED on RB0
CALL DELAY ; Call delay subroutine
BCF PORTB, RB0 ; Turn off LED on RB0
CALL DELAY
GOTO MAIN_LOOP ; Repeat the loop
DELAY:
MOVLW 0x9 ; Load W with 9 --> Count from 0-->9 (10)
MOVWF 0x20 ; Load register 0x20 with 9
DELAY_LOOP_1:
MOVLW 0xC5 ; Load W with 197 (count 0--> 198)
MOVWF 0x21 ; Load register 0x20 with 197
DELAY_LOOP_1:
MOVLW 0xC3 ; Load W with 195 (count 0--> 196)
MOVWF 0x22 ; Load register 0x20 with 195
DELAY_LOOP_3:
DECFSZ 0x22, F ; Decrement register 0x20, skip if zero
GOTO DELAY_LOOP_3 ; Repeat until register 0x20 is zero
DECFSZ 0x21, F ; Decrement register 0x21, skip if zero
GOTO DELAY_LOOP_2 ; Repeat until register 0x20 is zero
DECFSZ 0x20, F ; Decrement register 0x21, skip if zero
GOTO DELAY_LOOP_2 ; Repeat until register 0x20 is zero
; f=4MHz --> Cycle=1MHz --> T=1usec
; estimate delay time (10*(198+2)*(196+4)=1000)
RETURN ; return from subroutine
END

You might also like