Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
STATUS
Z
MAIN
equ
3
equ
2
call
DELAY_1MS
; Test stub calling up delay subroutine
sleep
; *****************************************************************
; * FUNCTION: Delays for 1ms with a 4MHz crystal
*
; * ENTRY : None
*
; * EXIT : Flags and W altered
*
; *****************************************************************
N
equ
d'249' ; Delay parameter computed in the text
DELAY_1MS
movlw N
; Set up loop
1~
; LOOP -----------------------------------------------------------D_LOOP
addlw -1
; Decrement count
N~
btfss STATUS,Z
; Check: Is it zero?
N+1~
goto D_LOOP
; IF not THEN repeat
2*(N-1)~
; ----------------------------------------------------------------return
end
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DELAY_100MS
STATUS
Z
MAIN
equ
equ
call
3
2
DELAY_100MS ; Test stub calling up delay subroutine
sleep
; *****************************************************************
; * FUNCTION: Delays for nominally 100ms with a 4MHz crystal *
; * ENTRY : None
*
; * EXIT : Flags and W altered. File h'30' zero
*
; *****************************************************************
COUNT1
equ
h'30' ; Use File h'30' as a loop counter
N
equ
d'249' ; Delay parameter computed in the text
DELAY_100MS movlw d'100' ; Initialize outer loop count to 100
movwf COUNT1
; Outer loop -----------------------------------------------------DELAY_1MS
movlw N
; Set up loop
; Inner loop -----------------------------------------------------D_LOOP
addlw -1
; Decrement count
btfss STATUS,Z
; Check: Is it zero?
goto D_LOOP
; IF not THEN repeat
; ----------------------------------------------------------------decfsz COUNT1,f
; Decrement outer loop count
goto DELAY_1MS
; and repeat until zero
; -----------------------------------------------------------------
return
end
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DELAY_K_100_MS
STATUS equ
3
Z
equ
2
MAIN movlw d'50'
; 50 x 0.1s gives five seconds
call
DELAY_K100MS ; Test stub calling up delay subroutine
sleep
;*****************************************************************
; * FUNCTION: Delays for around K x 100ms @ 4MHz
*
; * EXAMPLE : K = 100, delays 10 seconds
*
; * ENTRY : K in W, range 1 - 256
*
; * EXIT : Flags and W altered. Files h'30:31' zero
*
;*****************************************************************
COUNT1
K
N
equ
equ
equ
h'30'
h'31'
d'249'
DELAY_K100MS
movwf K
; DO 100ms delay -------------------------------------------------DELAY_100MS movlw d'100' ; Initialize outer loop count to 100
movwf COUNT1
DELAY_1MS
movlw N
; Set up loop
D_LOOP
addlw -1
; Decrement count
btfss STATUS,Z
; Check: Is it zero?
goto D_LOOP
; IF not THEN repeat
decfsz COUNT1,f
; Decrement 100 loop count
goto DELAY_1MS
; and repeat until zero
; Decrement K ----------------------------------------------------decfsz K,f
; WHILE K > 0 ----------------------------------------------------goto DELAY_100MS ; Repeat 100ms delay WHILE K > 0
FINI
return
End
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7 Segment
MAIN movlw 6
; Test decimal six
call
SVN_SEG
; Convert it
sleep
; Stop
; **********************************************************
; * FUNCTION: Returns byte[N] in table
*
; * FUNCTION: where N is the contents of W
*
; * EXAMPLE : IF W = 06 THEN returns code b'01111101' *
; * ENTRY : N range 00 - 09 in W
*
; * EXIT : Table entry N in W
*
; **********************************************************
PCL equ 2
; Low byte of PC is at File 2
SVN_SEG addwf PCL,f
; Add W to PCL, giving PC + N
;
xgfedcba
retlw b'00111111' ; Code for 0; Returned if N = 0
retlw b'00000110' ; Code for 1; Returned if N = 1
retlw b'01011011' ; Code for 2; Returned if N = 2
retlw b'01001111' ; Code for 3; Returned if N = 3
retlw b'01100110' ; Code for 4; Returned if N = 4
retlw b'01101101' ; Code for 5; Returned if N = 5
retlw b'01111101' ; Code for 6; Returned if N = 6
retlw b'00000111' ; Code for 7; Returned if N = 7
retlw b'01111111' ; Code for 8; Returned if N = 8
retlw b'01101111' ; Code for 9; Returned if N = 9
end
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BUZ_OFF
bsf PORTB,7
goto CHECK
end
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Timer
count equ h'20
org 0x00
goto main
org 0x04
goto isr
main
movlw d'6'
movwf TMR0 ;start with 6. overflow after 250 increments
movlw b'10100000'
movwf INTCON ;enable timer0 interrupts
clrf count
bsf STATUS,RP0
movlw b'00000001'
;prescaler to 1
movwf OPTION_REG
;update timer after every 4 instruction cycles
bcf STATUS,RP0
goto $
isr
movlw d'6'
movwf TMR0
;preset timer counter again & again
incf count
;updated in every 1 milli second
bcf INTCON,TMR0IF
retfie
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A2D conversion
Implementation
main
bsf STATUS,RP0
movlw 0x8e
movwf ADCON1
bcf STATUS,RP0
movlw 0x01
movwf ADCON0
read_ad
call DELAY_20us
bsf ADCON0,2
loop2
;enable A/D
;reference pins
btfsc ADCON0,2
goto loop2
bsf STATUS,RP0
movf ADRESL,W
movwf _ADRESL
bcf STATUS,RP0
movf ADRESH,W
movwf _ADRESH
goto read_ad
DELAY_20us
movlw d'5'
movwf COUNT
loop1
decfsz COUNT,f
goto loop1
return
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||