0% found this document useful (0 votes)
2 views4 pages

Tutorial 05 – Assembler Programming, OddEven button presses (LO3 & LO4)

The document provides a tutorial on assembler programming for a microcontroller system, specifically the PIC16F877A, to handle odd and even button presses. It outlines the configuration settings and includes a code segment that sets PORTB bits based on the number of button presses, with odd presses resulting in bit 0 HIGH and bit 1 LOW, and even presses the opposite. The code also incorporates a delay function and checks the button state to increment the count accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
2 views4 pages

Tutorial 05 – Assembler Programming, OddEven button presses (LO3 & LO4)

The document provides a tutorial on assembler programming for a microcontroller system, specifically the PIC16F877A, to handle odd and even button presses. It outlines the configuration settings and includes a code segment that sets PORTB bits based on the number of button presses, with odd presses resulting in bit 0 HIGH and bit 1 LOW, and even presses the opposite. The code also incorporates a delay function and checks the button state to increment the count accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

Tutorial 05 – Assembler Programming, Odd/Even button presses (LO3 &

LO4)

A microcontroller based system comes with a push button for mode selection. For all the odd
presses of the button, PORTB bit 0 should be logic HIGH and bit 1 should be logic LOW. For all
even presses, PORTB bit 0 should be logic LOW and bit 1 should be logic HIGH. Write a code
segment in assembler to accommodate these requirements.

You may assume the following:


 You are free to choose any clock frequency for the microcontroller.
 All port pins may be used as general purpose digital I/O.
 State any assumptions you make in your answer.
 Microcontroller – PIC16F877A

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


delay2 equ 0x21
count equ 0x22

PSECT CODE, DELTA=2

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

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

;MOVLW 0x06 ; Configure all pins as digital


;MOVWF ADCON1 ; set all pins as digital inputs

BCF TRISB,0 ; Set RA<3:0> as output


BCF TRISB,1 ; Set RA<3:0> as output
BSF TRISB, 2 ;as input

BCF STATUS, 5 ; Bank0

MAIN:

BTFSC PORTB, 2 ;IF ZERO NORMAL BLINKING


GOTO NEXT ;IF ONE MOVE TO NEXT

BSF PORTB, 1
BCF PORTB, 0

call delay_start

BCF PORTB, 1
BSF PORTB, 0

call delay_start

GOTO MAIN

NEXT:
INCF count
NEXT1:
BTFSC count, 0
goto notzero ; ODD press
BCF PORTB, 0 ; EVENpress
BSF PORTB, 1
GOTO TESTBUTTON
goto NEXT1

notzero:
BSF PORTB, 0
BCF PORTB, 1
GOTO TESTBUTTON

goto NEXT1

delay_start:
DECFSZ delay1
goto delay_start
MOVLW 0XFF
MOVWF delay1

DECFSZ delay2
goto delay_start
MOVLW 0XFF
MOVWF delay2

return

TESTBUTTON:
BTFSC PORTB, 2
GOTO INCRIMENT
GOTO TESTBUTTON

INCRIMENT:
INCF count
GOTO NEXT1

END start

You might also like