Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is for PIC18F1220. Please use correct asembly language. You\'ve been hired

ID: 2085459 • Letter: T

Question

This is for PIC18F1220. Please use correct asembly language.

You've been hired to implement a PIC-based system for controlling a fish tank. The tank has 2 sensors: one for LOW temperature (connected to pin 17) and one for HIGH temperature (connected to pin 8). It has 4 buttons connected to PORTA which fish can use to request different types of food, along with 4 FOOD DISPENSER mechanisms connected to PORTA The feeding logic works as follows: - when PORTA =1, you should set PORTA to 1 - when P0RTA =1, you should set PORTA to 1 - when PORTA =l, you should set PORTA to 1 - when P0RTA =1, you should set PORTA to 1 (if an input is 0, set the corresponding output to 0) The tank also has a HEATER, which is connected to pin 10. If you output a 1 to the heater, the tank will get warmer: outputting 0 turns the heater off. Your main loop should monitor PORTA and set PORTA accordingly, repeatedly. Additionally, if at any time the LOW temperature sensor outputs 1, you should turn the heater on: if the HIGH temperature sensor outputs 1, you should turn the heater off. This must be done via interrupts. Show complete code for this PIC system, including all initialization, interrupt setup, etc.

Explanation / Answer

Answer:- We have low temperature sensor at INT2 (pin 17) and high temperature sensor at INT0 (pin 8). Heater is at pin 10 i.e PORTB pin4. PORTA contains switches/buttons from 0 to 3 and food dispenser from pin 4 to pin 7. The program is written below for PIC18F1220 microcontroller.

---------------------------------------------------------------------------------------------------------------------------------------

ORG 0000H    ; starting address

GOTO MAIN    ; go to label name MAIN

ORG 0008H    ; low priority interrupt ISR location

BTFSC INTCON, RB0IF    ; is interrupt zero flag set, skip next line if clear

BRA INT0_ISR     ; goto label name INT0_ISR

RETFIE    ; return from ISR

ORG 0018H    ; low priority interrupt

BTFSC INTCON3, INT2IF    ; is interrupt zero flag set, skip next line if clear

BRA INT2_ISR     ; goto label name INT0_ISR

RETFIE    ; return from ISR

MAIN:    ; label name MAIN

BCF INTCON, INT0IF    ; clear external interrupt flag zero

BCF INTCON3, INT2IF    ; clear external interrupt flag two

BSF INTCON, INT0IE    ; enable external interrupt zero

BSF INTCON3, INT2IE    ; enable external interrupt two

BCF INTCON3, INT2IP    ; external interrupt two has low priority, INT0 has only high level priority

BSF INTCON, GIE    ; enable interrupt globally, if interrupt comes goto respective ISR

BSF STATUS, RP0 ; select bank 1

MOVLW 0xF0     ; load literal to W

MOVWF TRISA    ; make portA pin0 to pin3 as input, rest as output

MOVLW 0x10    ; load literal to W

CLRF STATUS    ; select bank zero

LOOP1:    ; label name LOOP1

SWAPF PORTA, 0    ; read portA, swap the nibbles and store in W register

MOVWF PORTA    ; write the W content to portA

GOTO LOOP1    ; jump to label LOOP1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote