Lister - HW5

3
;=============================================================================== ;Name: Julio Sanchez with changes by Peter Seid ;Class: AME 487 ;Date: 04/25/2015 ;Exercise: Homework 5 - The Digital Clock ;Description: Create a Digital Clock ;MCU: PIC16F84A ;References: See Homework_5.pdf for further information ;=============================================================================== ;=========================== ; switches ;=========================== ; Switches used in __config directive: ; _CP_ON Code protection ON/OFF ; * _CP_OFF ; * _PWRTE_ON Power-up timer ON/OFF ; _PWRTE_OFF ; _WDT_ON Watchdog timer ON/OFF ; * _WDT_OFF ; _LP_OSC Low power crystal oscillator ; * _XT_OSC External parallel resonator/crystal oscillator ; _HS_OSC High speed crystal resonator (8 to 10 MHz) ; Resonator: Murate Erie CSA8.00MG = 8 MHz ; _RC_OSC Resistor/capacitor oscillator (simplest, 20% error) ; | ; |_____ * indicates setup values processor 16f84A include <p16f84A.inc> __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF ;===================================================== ; variables in PIC RAM ;===================================================== ; Declare variables at 3 memory locations used for delay loop j equ 0x0c k equ 0x0d i equ 0x0e ;======================================================== ; m a i n p r o g r a m ;======================================================== org 0 ; start at address 0 goto main ;============================= ; space for interrupt handler ;============================= org 0x04 ;============================= ; main program ;============================= main: ; Initialize all lines in port B for output (bits 0-6 are for 7 segment display) movlw B'00000000' ; w = 00000000 binary tris PORTB ; Set up port B for output ; Make sure 7-Segment displays 'zero' from the start movlw B'01101111' movwf PORTB ; Initialize all lines in port A for output movlw B'00000000' ; w = 00000000 binary tris PORTA ; Set up port A for output ; Make sure both LEDs start OFF movlw B'00000000' movwf PORTA minuteLoop: ; Display 0 on 7 segment for 5 seconds movlw B'01101111' ; Byte for #0

description

A great assembly code for PIC MCUs. Should be sufficient enough for beginners to understand.

Transcript of Lister - HW5

Page 1: Lister - HW5

;===============================================================================;Name: Julio Sanchez with changes by Peter Seid;Class: AME 487;Date: 04/25/2015;Exercise: Homework 5 - The Digital Clock;Description: Create a Digital Clock;MCU: PIC16F84A;References: See Homework_5.pdf for further information;===============================================================================;===========================; switches;===========================; Switches used in __config directive:; _CP_ON Code protection ON/OFF; * _CP_OFF; * _PWRTE_ON Power-up timer ON/OFF; _PWRTE_OFF; _WDT_ON Watchdog timer ON/OFF; * _WDT_OFF; _LP_OSC Low power crystal oscillator; * _XT_OSC External parallel resonator/crystal oscillator; _HS_OSC High speed crystal resonator (8 to 10 MHz); Resonator: Murate Erie CSA8.00MG = 8 MHz; _RC_OSC Resistor/capacitor oscillator (simplest, 20% error); |; |_____ * indicates setup values

processor 16f84Ainclude <p16f84A.inc>__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF

;=====================================================; variables in PIC RAM;=====================================================; Declare variables at 3 memory locations used for delay loopj equ 0x0ck equ 0x0di equ 0x0e

;========================================================; m a i n p r o g r a m;========================================================

org 0 ; start at address 0goto main

;=============================; space for interrupt handler;=============================

org 0x04;=============================; main program;=============================main:; Initialize all lines in port B for output (bits 0-6 are for 7 segment display)

movlw B'00000000' ; w = 00000000 binarytris PORTB ; Set up port B for output

; Make sure 7-Segment displays 'zero' from the start movlw B'01101111' movwf PORTB

; Initialize all lines in port A for outputmovlw B'00000000' ; w = 00000000 binarytris PORTA ; Set up port A for output

; Make sure both LEDs start OFF movlw B'00000000' movwf PORTA

minuteLoop:; Display 0 on 7 segment for 5 seconds movlw B'01101111' ; Byte for #0

Page 2: Lister - HW5

movwf PORTB ; Set port B pins to display #0 call wait5Seconds

; Display 1 on 7 segment for 5 seconds movlw B'00000110' ; Byte for #1 movwf PORTB ; Set port B pins to display #1 call wait5Seconds

; Display 2 on 7 segment for 5 seconds movlw B'00111011' ; Byte for #2 movwf PORTB ; Set port B pins to display #2 call wait5Seconds

; Display 3 on 7 segment for 5 seconds movlw B'00011111' ; Byte for #3 movwf PORTB ; Set port B pins to display #3 call wait5Seconds

; Display 4 on 7 segment for 5 seconds movlw B'01010110' ; Byte for #4 movwf PORTB ; Set port B pins to display #4 call wait5Seconds

; toggle second LED to indicate 1 hour has passed btfss PORTA,1 ; if second LED is already on, skip this call toggleOn ; otherwise, turn it on

btfsc PORTA,1 ; if second LED is already off, skip this call toggleOff ; otherwise, turn it off

goto minuteLoop ; start the cycle over infinitely

;==========================================================; 5 second delay routine while flashing first LED on/off;==========================================================wait5Seconds: movlw B'00000001' ; turn first LED on for 1 second movwf PORTA call delay

movlw B'00000000' ; turn first LED off for 1 second movwf PORTA call delay

movlw B'00000001' ; turn first LED on for 1 second movwf PORTA call delay

movlw B'00000000' ; turn first LED off for 1 second movwf PORTA call delay

movlw B'00000001' ; turn first LED on for 1 second movwf PORTA call delay

movlw B'00000000' ; turn first LED off movwf PORTA

return

;================================; turn second LED on;================================toggleOn: movlw B'00000010' movwf PORTA return

Page 3: Lister - HW5

;================================; turn second LED off;================================toggleOff: movlw B'00000000' movwf PORTA return

;================================; 1 second delay sub-routine;================================delay: movlw .8 ; w = 8 decimal movwf i ; i = w movlw .204 ; w = 204 decimal movwf j ; j = w

iloop: movwf j ; j = wjloop: movwf k ; k = w

kloop: decfsz k,f ; k = k-1, skip next if zero goto kloop decfsz j,f ; j = j-1, skip next if zero goto jloop decfsz i,f ; i = i-1, skip next if zero goto iloop return

end