Advertisement
jack96013

ex923

Jan 4th, 2021
3,378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 1.00 KB | None | 0 0
  1. ;##############################################
  2. ;Title  : ex923 ADC
  3. ;Description : CDS 高於 N LED亮
  4. ;Date   : 2021 / 01 / 04
  5. ;##############################################
  6. list p=16F877A
  7. #include <p16f877A.inc> ; Include file locate at defult directory
  8. ; CONFIG
  9. ; __config 0xFF7A
  10.  __CONFIG _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
  11.  
  12.  
  13. addr_delay equ 0x20
  14.  
  15. org 0x0
  16. Setup:
  17.     banksel TRISA
  18.    
  19.     clrf ADCON1 ;向左靠
  20.     clrf TRISD
  21.  
  22.     banksel PORTA
  23.     movlw b'11000001'
  24.     movwf ADCON0
  25.  
  26. ADCONVERT:
  27.     call delay
  28.     bsf ADCON0,GO
  29. ADWAIT:
  30.     nop
  31.     btfss PIR1,ADIF
  32.         goto ADWAIT
  33.     bcf PIR1,ADIF
  34.  
  35.     movlw .100
  36.     subwf ADRESH,w
  37.     btfss STATUS,C
  38.         goto DARK
  39.    
  40.     clrf PORTD
  41.     goto ADCONVERT
  42.  
  43.  
  44. DARK:
  45.     movlw 0xFF
  46.     movwf PORTD
  47.     goto ADCONVERT
  48.  
  49. delay:
  50.     movlw .24
  51.     movwf addr_delay
  52.  
  53.     delay_loop:
  54.         decfsz addr_delay,f
  55.             goto delay_loop
  56.         return
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement