Blink2 vs Rotate
-
Upload
violeta-macovei -
Category
Documents
-
view
215 -
download
0
Transcript of Blink2 vs Rotate
-
8/8/2019 Blink2 vs Rotate
1/3
; *******************************************************************
; PICkit 3 Lectia 2 - "Clipire"
;
; Acest program aprinde si stinge alternativ LED-ul 0 al
; sistemului de dezvoltare PICKIT3.
;
; *******************************************************************
; * Cititi platforma de laborator pentru informatii suplimentare *
; *******************************************************************
; * NOTA: Microcontrolerul utilizat este PIC18F45K20 *
; *******************************************************************
#include
config FOSC = INTIO67
config WDTEN = OFF, LVP = OFF, MCLRE = OFF
org 0
cblock 0x20
Delay1 ; Define two file registers for the
Delay2 ; delay loop
endc
org 0
Start:
movlw 0x7C
movwf OSCCON
bcf TRISD,0 ; make IO Pin B.0 an output
MainLoop:
bsf PORTD,0 ; turn on LED D0
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per
loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3
instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M
instructions per second = 0.197 sec.
; call it a two-tenths of a second.
bcf PORTD,0 ; Turn off LED C0
OffDelayLoop:
decfsz Delay1,f ; same delay as above
goto OffDelayLoop
decfsz Delay2,f
goto OffDelayLoop
goto MainLoop ; Do it again...
end
-
8/8/2019 Blink2 vs Rotate
2/3
#include
; prima etapa - configurarea microcontrolerului
config FOSC = INTIO67 ; oscilator intern
config WDTEN = OFF, LVP = OFF, MCLRE = OFF ; nu folosim watchdog timer,
LVD, MCLRE
org 0 ; programul este asamblat de al adresa 0
cblock 0x20
Delay1 ; Assign an address to label Delay1
Delay2
Display ; define a variable to hold the diplay
endc
org 0
Start:
movlw 0x5C
movwf OSCCON
movlw 0xFF
movwf TRISA ; Make PortA all input
clrf TRISD ; Make PortD all output
movlw 0x10 ; A2D Clock Fosc/8movwf ADCON1
movlw 0xF7 ; we want all Port A pins Analog, except RA3
movwf ANSEL
movlw 0x01
movwf ADCON0 ; configure A2D for Channel 0 (RA0), Left
justified, and turn on the A2D module
movlw 0x80
movwf Display
MainLoop:
movf Display,w ; Copy the display to the LEDs
movwf PORTD
nop ; wait 8uS for A2D amp to settle and capacitor
to charge.
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
nop ; wait 1uS
bsf ADCON0,GO ; start conversion
btfss ADCON0,GO ; this bit will change to zero when the
conversion is completegoto $-1
movf ADRESH,w ; Copy the display to the LEDs
addlw 1
movwf Delay2
A2DDelayLoop:
decfsz Delay1,f ; Waste time.
goto A2DDelayLoop ; The Inner loop takes 3 instructions per loop
* 256 loopss = 768 instructions
-
8/8/2019 Blink2 vs Rotate
3/3
decfsz Delay2,f ; The outer loop takes and additional 3
instructions per lap * 256 loops
goto A2DDelayLoop ; (768+3) * 256 = 197376 instructions / 1M
instructions per second = 0.197 sec.
; call it a two-tenths of a second.
movlw 0x13 ; Delay another 10mS plus whatever was above
movwf Delay2
TenmSdelay:
decfsz Delay1,f
goto TenmSdelay
decfsz Delay2,f
goto TenmSdelay
Rotate:
bcf STATUS,C
rrcf Display,f
btfsc STATUS,C ; Did the bit rotate into the carry?
bsf Display,7 ; yes, put it into bit 7.
goto MainLoop
end