Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Tutorial 04_Assembler port programming and button press detection (LO3 & LO4)

The document provides an assembly programming tutorial for a PIC/MSP430 microcontroller, detailing how to toggle LED 1 based on sequential button presses and control LED 2 based on the even or odd number of presses of SW 1. It includes configuration settings for the microcontroller and a code snippet with comments explaining the functionality. The code ensures that other pins and ports remain unaffected during operation.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Tutorial 04_Assembler port programming and button press detection (LO3 & LO4)

The document provides an assembly programming tutorial for a PIC/MSP430 microcontroller, detailing how to toggle LED 1 based on sequential button presses and control LED 2 based on the even or odd number of presses of SW 1. It includes configuration settings for the microcontroller and a code snippet with comments explaining the functionality. The code ensures that other pins and ports remain unaffected during operation.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Tutorial 04 Assembler port programming and button press detection

(LO3 & LO4)

Figure 1 shows a PIC/MSP430 Microcontroller interfaced with buttons and LEDs. A client has
requested to program this microcontroller to toggle LED 1 when SW 1 and SW 2 is pressed one
after the other in a sequential order and for any other combination LED 1 should be in off state.
In addition, for all SW 1 even number (for any condition of SW 2) of presses, LED 2 should be
switched ON. Furthermore, LED 2 should be switched OFF for all odd number of SW 1 presses.
Write the assembly code with comments to simulate the above request. Please note that, you are
not allowed to distract the operation of the other pins and ports of the microcontroller.

Figure 01

; 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

button_press equ 0x20


//delay2 equ 0x21

PSECT CODE, DELTA=2

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

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

MOVLW 0XFF
MOVWF TRISB ; Set PORTB as input

MOVLW 0X00
MOVWF TRISC ; Set PORTB as output

BCF STATUS, 5 ; Bank0


CLRF PORTB
CLRF PORTC

MAIN:
BTFSC PORTB, 0
GOTO MAIN1
BCF PORTC,0
GOTO MAIN
MAIN1:
INCF button_press
BTFSS button_press, 0
GOTO MAIN3
BCF PORTC,1
TEMP:

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

MAIN2:
BSF PORTC,0
CLRF PORTB
GOTO MAIN

MAIN3:
BSF PORTC,1
GOTO TEMP
// END start

You might also like