Tutorial 01_Assembler Port programming_(LO3 & LO4)
Tutorial 01_Assembler Port programming_(LO3 & LO4)
a) Design a Simple multi vibrator using MPLAB for PIC16F877A, (blink a LED connected to portB
pin.
b) Interface a two way switch with PIC16F877A, show the state change using LED’s.
;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN
;---------end initialising-------------
BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1
MOVLW 0X01
MOVWF TRISB ; Set PORTB as output
MOVLW 0X00
MOVWF TRISC ; Set PORTB as output
MAIN:
BTFSC PORTB, 0
GOTO MAIN2
BCF PORTB,1
GOTO MAIN
MAIN2:
BSF PORTB,1
END start
; CONFIG
CONFIG FOSC = EXTRC ; Oscillator Selection bits (RC oscillator)
CONFIG WDTE = OFF ; Watchdog Timer Enable bit (WDT disabled)
CONFIG PWRTE = OFF ; Power-up Timer Enable bit (PWRT disabled)
CONFIG BOREN = OFF ; Brown-out Reset Enable bit (BOR disabled)
CONFIG LVP = OFF ; Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is
digital I/O, HV on MCLR must be used for programming)
CONFIG CPD = OFF ; Data EEPROM Memory Code Protection bit (Data EEPROM code protection
off)
CONFIG WRT = OFF ; Flash Program Memory Write Enable bits (Write protection off; all program
memory may be written to by EECON control)
CONFIG CP = OFF ; Flash Program Memory Code Protection bit (Code protection off)
;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN
;---------end initialising-------------
BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1
one:
BSF PORTB, 1
MAIN:
BTFSC PORTB, 0
goto one
BCF PORTB, 1
GOTO MAIN
END start