Sie sind auf Seite 1von 7

Microcontoller Setup

; Microcontroller Header File

#include <p16F84A.inc>

; Chip Specific Configurations

__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.


; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

; VARIABLE DEFINITIONS

w_temp EQU 0x0C ; variable used for context saving


status_temp EQU 0x0D ; variable used for context saving

mark30 equ 0x10


post80 equ 0x11
sec5 equ 0x12

; Start Place

ORG 0x000 ; processor reset vector


goto start ; go to beginning of program
ORG 0x004 ; interrupt vector location

;**********************************************************************
;SubRoutine

Init CLRF STATUS ; Bank0


CLRF PORTA ; Initialize PORTB by clearing output
CLRF PORTB ; data latches
BSF STATUS, RP0 ; Select Bank1
MOVLW b'00000' ; Select PortA Ports
MOVWF TRISA ;
MOVLW b'00000000' ; Select PortB Ports
MOVWF TRISB ;
BCF STATUS, RP0 ; Bank0

CLRWDT ; Clear WDT and prescaler


BSF STATUS, RP0 ; Bank1
MOVLW b'00000111' ; Select TMR0, new prescale
MOVWF OPTION_REG ; value and clock source
BCF STATUS, RP0 ; Bank0

movlw d'30' ; sets up marker


movwf mark30 ;

movlw d'80' ; sets up first postscaler


movwf post80 ;

movlw d'5' ; sets up five second counter


movwf sec5 ;

retlw 0 ;Skips Init Second Time


;**********************************************************************
;Program Start

start call Init

main movfw mark30 ; takes the number out of Mark30


subwf TMR0, w ; subtracts this number from the number
in
; TMR0, leaving the result in the
working
; register (and leaving TMR0
unchanged)
btfss STATUS, Z ; tests the Zero Flag - skip if set, i.e. if
the result
; is zero it will skip the next
instruction
goto main ; if the result isn't zero, it loops back to
'Loop'
;***
movlw d'30' ; moves the decimal number 30 into the working
addwf mark30, f ; register and then adds it to 'Mark30'

decfsz post80, f ; decrements 'Post80', and skips the next

; instruction if the result is


zero
goto main ; if the result isn't zero, it loops back to
'Loop'
; one second has now passed
;***

movlw d'80' ; resets postscaler


movwf post80 ;

;***

comf PORTA, f ; toggles LED state

decfsz sec5, f ; has five seconds passed?


goto main ; no, loop back

;***

movlw d'5' ; resets 5 second counter


movwf sec5 ;

goto main ; loops back to start

END
LIST P=16f84

#INCLUDE"P16f84.INC" ; all the system EQUATES are in this file


; It is located in Mpasm open it and have
a look
; its complicated but it will make sense
one day

cblock 0x0c ; user registers


d1
d2
d3
COUNT
endc

;----------------------------------------------------------------------------
-----------------------
banksel TRISA ; Moving from 'Bank 0' to 'Bank 1'.
movlw b'00000' ; Move adress 00000 to 'w' register .
movwf TRISA ; move value of W into TRISA. It designate all bit
output

banksel 0 ; Move back to 'Bank 0'.

;----------------------------------------------------------------------------
-----------------------
start
movlw b'00000001' ; load W to turn on Porta, bit 0
movwf PORTA ; Move value in W to POORTA to turn on led on RA0

call Delay5SEC ;Call delay function

movlw b'00000000' ; Load W to turn off Portabit 0


movwf PORTA ; Move value in W to POORTA to turn off led on RA0

call Delay5SEC ; call delay function.

GOTO start ; COMPLETE LOOP

;----------------------------------------------------------------------------
-----------------------

; SUBROUTINE CALLED DELAY

;4999993 cycles
Delay5SEC movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0

;3 cycles
goto $+1
nop

;4 cycles (including call)


return ; SPECIFIES THE END OF A
SUBROUTINE
;----------------------------------------------------------------------------
-----------------------

end

LIST P=16f84

#INCLUDE"P16f84.INC"

;----------------------------------------------------------------------------
-----------------------
;EQUATES

TRM0 equ 01h ;Address of TIMER0. It runs at 1/4 of


;clock speed. If clock is of 32,768 HZ
;then it is 8,192 pulses per second.
STATUS equ 03h ;Address of Status Register.
PORTA equ 05h ;Adress of PORTA.
TRISA equ 85h ;Address of TRISA.To Designate I\O
;of PORTA. Specify Which Port is
;input or output.
OPTION_R equ 81h ;Address of Option Register. IT is used to
;reduce the pulse rate by factor 2, 4,8,....
; 256. here 256 is used.
COUNT equ 08h

cblock 0x0c
d1
d2
d3
endc
;----------------------------------------------------------------------------
-----------------------
bsf 03h,5 ; Moving from 'Bank 0' to 'Bank 1'.
movlw b'00000' ; Move adress 00000 to 'w' register .
movwf 85h ; move value of W into TRISA. It designate all bits
as
;output

bcf 03h,5 ; Move back to 'Bank 0'.


;----------------------------------------------------------------------------
-----------------------
start
movlw b'00001' ; means 2 in decimal, 00010 in decimal. logic 1 to
2nd bit.
movwf 05h ; move logic 1 to 2nd Bit of PORTA. It let to on LED
connected to 2nd bit i.s A1.

call Delay ;Call delay function


; call Delay_0
movlw 00h ; to send 0 at w.
movwf 05h ; to get off lED.

call Delay
; call Delay_0 ; call delay function.

GOTO start ; COMPLETE LOOP

;----------------------------------------------------------------------------
-----------------------

; SUBROUTINE CALLED DELAY

;4999993 cycles
Delay movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0

;3 cycles
goto $+1
nop

;4 cycles (including call)


return
;----------------------------------------------------------------------------
-----------------------
end

;EQUATES

TRM0 equ 01h ;Address of TIMER0. It runs at 1/4 of


;clock speed. If clock is of 32,768 HZ
;then it is 8,192 pulses per second.
STATUS equ 03h ;Address of Status Register.
PORTA equ 05h ;Adress of PORTA.
TRISA equ 85h ;Address of TRISA.To Designate I\O
;of PORTA. Specify Which Port is
;input or output.
OPTION_R equ 81h ;Address of Option Register. IT is used to
;reduce the pulse rate by factor 2, 4,8,....
; 256. here 256 is used.
COUNT equ 08h
cblock 0x0c
d1
d2
d3
endc
;----------------------------------------------------------------------------------
-----------------
bsf 03h,5 ; Moving from 'Bank 0' to 'Bank 1'.
movlw b'00000' ; Move adress 00000 to 'w' register .
movwf 85h ; move value of W into TRISA. It designate all bits as
;output

bcf 03h,5 ; Move back to 'Bank 0'.

;----------------------------------------------------------------------------------
-----------------
start
movlw b'00001' ; means 2 in decimal, 00010 in decimal. logic 1 to 2nd bit.
movwf 05h ; move logic 1 to 2nd Bit of PORTA. It let to on LED connected to 2nd bit
i.s A1.

call Delay ;Call delay function


call Delay_0
movlw 00h ; to send 0 at w.
movwf 05h ; to get off lED.

call Delay
call Delay_0 ; call delay function.
;----------------------------------------------------------------------------------
-----------------

;4999993 cycles
Delay movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0

;3 cycles
goto $+1
nop

;4 cycles (including call)


return
;----------------------------------------------------------------------------------
-----------------
end

Das könnte Ihnen auch gefallen