Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;##############################################
- ;Title : ex923 ADC
- ;Description : CDS 高於 N LED亮
- ;Date : 2021 / 01 / 04
- ;##############################################
- list p=16F877A
- #include <p16f877A.inc> ; Include file locate at defult directory
- ; CONFIG
- ; __config 0xFF7A
- __CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
- addr_delay equ 0x20
- org 0x0
- Setup:
- banksel TRISA
- clrf ADCON1 ;向左靠
- clrf TRISD
- banksel PORTA
- movlw b'11000001'
- movwf ADCON0
- ADCONVERT:
- call delay
- bsf ADCON0,GO
- ADWAIT:
- nop
- btfss PIR1,ADIF
- goto ADWAIT
- bcf PIR1,ADIF
- movlw .100
- subwf ADRESH,w
- btfss STATUS,C
- goto DARK
- clrf PORTD
- goto ADCONVERT
- DARK:
- movlw 0xFF
- movwf PORTD
- goto ADCONVERT
- delay:
- movlw .24
- movwf addr_delay
- delay_loop:
- decfsz addr_delay,f
- goto delay_loop
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement