Tutorial 09 - Assembler General Questions (LO3 & LO4)
Tutorial 09 - Assembler General Questions (LO3 & LO4)
A client who is using a biogas plant has requested you to develop a gas pressure controlling
system. The digester and collector of the proposed biogas plant is connected with some PVC
tubes. Here digester has 3 electronically controllable water valves BW1, BW2 and BW3. The
complete system has 4 electronically controllable gas valves namely GV1, GV2, GV3 and GV4.
Digester tank is fitted with two water level detecting sensors namely Sensor 1 and Sensor 2.
Sensors would trigger a logic HIGH when the water level is above the sensor position and it
gives a logic LOW when the water level is below the sensor position. Electronically controllable
gas valves will be opened or switched ON when they have been given a logic HIGH, and will be
switched closed or OFF with logic LOW. Client needs a controller to be designed to perform all
the tasks given in Table 2.1. Here, you are supposed to use Assembly language (with comments)
and PIC16F877A as the controller device.
Sensor Valve
HIGH HIGH ON ON ON ON
Solution
; PIC16F877A Configuration Bit Settings
; 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
;---------end initialising-------------
BCF STATUS, 6 ;
BSF STATUS, 5 ; Select Bank 1
MOVLW 0b01100000
MOVWF PORTB
;Initialising
MAIN:
BTFSC PORTB, 1; sensor 2 high
GOTO BUTTON0
GOTO MAIN
BUTTON0:
BTFSC PORTB, 0; sensor 1 high
GOTO FIRST_ONE
GOTO SECOND_ONE
FIRST_ONE:
BSF PORTB, 2 ;1
BSF PORTB, 3 ;1
BSF PORTB, 4 ;1
BSF PORTB, 5 ;1
GOTO MAIN
SECOND_ONE:
BCF PORTB, 2 ;0
BCF PORTB, 3 ;0
BCF PORTB, 4 ;0
BSF PORTB, 5 ;1
GOTO MAIN
END start