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

Tutorial 01_Assembler Port programming_(LO3 & LO4)

The document provides a tutorial for programming the PIC16F877A microcontroller using MPLAB, focusing on two tasks: creating a simple multivibrator to blink an LED connected to PORTB and interfacing a two-way switch to show state changes with LEDs. It includes detailed assembly code for both tasks, including configuration settings and initialization procedures. The code demonstrates how to manipulate PORTB for output and read the state of the switch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Tutorial 01_Assembler Port programming_(LO3 & LO4)

The document provides a tutorial for programming the PIC16F877A microcontroller using MPLAB, focusing on two tasks: creating a simple multivibrator to blink an LED connected to PORTB and interfacing a two-way switch to show state changes with LEDs. It includes detailed assembly code for both tasks, including configuration settings and initialization procedures. The code demonstrates how to manipulate PORTB for output and read the state of the switch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Tutorial 01 – Assembler Port programming I (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.

Solution Part (a)


; PIC16F877A Configuration Bit Settings
; Assembly source line config statements
; 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)

// config statements should precede project file includes.


#include <xc.inc>

;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN

delay1 equ 0x20 // no need


delay2 equ 0x21 // no need

PSECT CODE, DELTA=2

;---------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

BCF STATUS, 5 ; Bank0


CLRF PORTB

MAIN:
BTFSC PORTB, 0
GOTO MAIN2
BCF PORTB,1

GOTO MAIN
MAIN2:
BSF PORTB,1

END start

Solution Part (b)

; PIC16F877A Configuration Bit Settings

; Assembly source line config statements

; 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)

// config statements should precede project file includes.


#include <xc.inc>

;--------initialising-------------
PSECT start, CLASS = CODE, DELTA=2
start:
PAGESEL MAIN
GOTO MAIN

memo20 equ 0x20


memo21 equ 0x21

PSECT CODE, DELTA=2

;---------end initialising-------------

BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1

CLRF TRISB ; Set RA<3:0> as OUT


BSF TRISB, 0

BCF STATUS, 5 ; Bank0


CLRW
MOVWF PORTB

one:
BSF PORTB, 1

MAIN:
BTFSC PORTB, 0
goto one

BCF PORTB, 1
GOTO MAIN

END start

You might also like