lab 2 report

6
ENGR 270 Lab # 2 Input/Output and Watchdog Timer Options Joseph Liguid Team: Ron Cotton Ivan Cruz Date Completed: 7/21/15

Upload: keith

Post on 11-Feb-2016

226 views

Category:

Documents


0 download

DESCRIPTION

From ENGR LAB 270

TRANSCRIPT

Page 1: Lab 2 Report

ENGR 270Lab # 2

Input/Output and Watchdog Timer Options

Joseph Liguid

Team: Ron CottonIvan Cruz

Date Completed:7/21/15

Page 2: Lab 2 Report

Experiment 1In this experiment, using the PICmicro and MPLab IDE we implemented and tested a two-bit adder.

Disassembled Code

MPASM 5.62 /HOME/RONC/MPLABXPROJECTS/LAB2/L 7-18-2015 18:53:03 PAGE 1

LOC OBJECT CODE LINE SOURCE TEXT VALUE

00001 ;------------------------------------------------------------------------------- 00002 ; FILE: main.asm 00003 ; DESC: Lab 2 - Input/Output and Watchdog Timer Operation 00004 ; DATE: 7/17/2015 00005 ; AUTH: Lab Group #18 Ron Cotton, Ivan Cruz, Joseph Liguid - ENGR 270 00006 ; DEVICE: PICmicro (PIC18F1220) 00007 ;------------------------------------------------------------------------------- 00008 00009 list p=18F1220 ; default processor target 00010 radix hex ; set default radix to hexCF 0F 1E 80 81 03 C0 000011 config WDT=OFF, LVP=OFF ; disable watchdog timer and LVP 3 E0 03 40 00012 ; Info: 00013 ; Port B, Pin 11 - Low Voltage Programming 00014 ; Other ways to disable WDT: 00015 ; instruction CLRWDT - Clear watchdog 00016 ; or bit 0 of CONFIG2H = 0 00017 00018 #define PORTB 0xF81 00019 #define TRISB 0xF93 00020 #define ADCON1 0xFC1 00021 00000080 00022 OP1 equ 0x080 ; OP1 --- Operand 1 - Input 1 (RB0 & RB1) 00000081 00023 OP2 equ 0x081 ; OP2 --- Operand 2 - Input 2 (RB2 & RB3) 00000082 00024 LAST equ 0x082 ; LAST --- Temporary WREG - Used for 00025 ; Resultant Value and to detect Input 00026 ; Change 00027 000000 00028 org 0x000 ; Program code starts at 0x000 00029 00030 ; BEGIN Initialization 00031 000000 6A81 00032 CLRF PORTB ; PORTB Values to Zero000002 0E7F 00033 MOVLW 0x7F ; 0111 1111 value for ADCON1000004 6EC1 00034 MOVWF ADCON1 ; set A/D PINS to digital000006 0E0F 00035 MOVLW 0x0F ; 0000 1111 value for TRISB000008 6E93 00036 MOVWF TRISB ; Set TRISB - 1 = Input, 0 = Output 00037 ; Set RB0 - RB3 Input & RB4 - RB7 Output 00038 00039 ; END Initialization 00040 ; ------------------------------------------00000A 00041 Start: 00042 ; BEGIN Clear Variables 00043 00000A 6B80 00044 CLRF OP1 ; OP1 = 000000C 6B81 00045 CLRF OP2 ; OP2 = 000000E 6B82 00046 CLRF LAST ; LAST = 0 00047 00048 ; END Clear Variables 00049 ; ------------------------------------------ 00050 ; BEGIN Get Switch Input 00051 000010 CF81 F080 00052 MOVFF PORTB, OP1 ; Set OP1 = PORTB

Page 3: Lab 2 Report

MPASM 5.62 /HOME/RONC/MPLABXPROJECTS/LAB2/L 7-18-2015 18:53:03 PAGE 2

LOC OBJECT CODE LINE SOURCE TEXT VALUE

000014 0E03 00053 MOVLW 0x3 ; Set WREG = 0000 0011000016 1780 00054 ANDWF OP1 ; Set OP1 = OP1 AND WREG 00055 000018 CF81 F081 00056 MOVFF PORTB, OP2 ; Set OP2 = PORTB00001C 0E0C 00057 MOVLW 0XC ; Set WREG = 0000 110000001E 1781 00058 ANDWF OP2 ; Set OP2 = OP2 AND WREG000020 4381 00059 RRNCF OP2 ; set OP2 = OP2 (Shift Right x2)000022 4381 00060 RRNCF OP2 00061 ; END Get Switch Input 00062 ; ------------------------------------------ 00063 ; BEGIN Add Operands 00064 000024 5180 00065 MOVF OP1,0 ; Set WREG = OP1000026 2581 00066 ADDWF OP2,0 ; Set WREG = WREG + OP2000028 6F82 00067 MOVWF LAST ; Set LAST = WREG 00068 00069 ; END Add Operands 00070 ; ------------------------------------------ 00071 ; BEGIN Output Total 00072 00002A 4782 00073 RLNCF LAST ; Set LAST = (Shifted Left) LAST00002C 4782 00074 RLNCF LAST ; (repeat 5x)00002E 4782 00075 RLNCF LAST ; 000030 4782 00076 RLNCF LAST ; "Getting LAST ready for Output to000032 4782 00077 RLNCF LAST ; PORTB" 00078 000034 0EE0 00079 MOVLW 0xE0 ; Set WREG = 1110 0000000036 1782 00080 ANDWF LAST ; Set LAST = LAST AND WREG 00081 000038 C082 FF81 00082 MOVFF LAST, PORTB ; Set PORTB = LAST (Output Result to LEDS) 00083 00084 ; END Output Total 00085 ; ------------------------------------------ 00086 ; BEGIN Check Input Change 00087 00003C CF81 F082 00088 MOVFF PORTB, LAST ; Set LAST = PORTB (Set Inputs to LAST)000040 00089 Wait: 00090 000040 5081 00091 MOVF PORTB, 0 ; Set WREG = PORTB000042 1982 00092 XORWF LAST, 0 ; Set WREG = PORTB XOR LAST000044 E0FD 00093 BZ Wait ; If no change in Inputs, Move to addr Wait 000046 EF05 F000 00094 GOTO Start ; otherwise, Goto the addr Start 00095 00096 ; END Check Input Change 00097 ENDMPASM 5.62 /HOME/RONC/MPLABXPROJECTS/LAB2/L 7-18-2015 18:53:03 PAGE 3

SYMBOL TABLE LABEL VALUE

ADCON1 0xFC1LAST 00000082OP1 00000080OP2 00000081PORTB 0xF81Start 0000000ATRISB 0xF93Wait 00000040__18F1220 00000001

MEMORY USAGE MAP ('X' = Used, '-' = Unused)

0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX0040 : XXXXXXXXXX------ ---------------- ---------------- ----------------0000 : -XXX-XX-XXXXXX-- ---------------- ---------------- ----------------

All other memory blocks unused.

Program Memory Bytes Used: 85Program Memory Bytes Free: 4011

Errors : 0

Page 4: Lab 2 Report

Warnings : 0 reported, 0 suppressedMessages : 0 reported, 0 suppressed

Schematic

Page 5: Lab 2 Report

There were some issues that we had encountered during the lab:

Some of the shifting was miscalculated for OP2 resulting in errors in the return value. We had also failed to store the value of PORTB to TEMP before checking the input change. In some parts of the code the MOVFF commands were backwards. We also got “Address not found for breakpoint” warnings for breakpoints where there was no code, placed NOP in certain blocks of code to test values after commands have executed. The NOPs were removed when testing was done.

Lessons Learned

The biggest items that I had learned doing this lab involved the usage of the pins on the PIC18F1220, noticeably the TRIS, PORT, and ADCON; specifically how to use them in the circuit and their locations in the memory. It was interesting how TRISA and TRISB’s output/input ‘switch’ was determined by the value placed in their respected locations.

New Experiment

518