Advertisement
Guest User

Untitled

a guest
Sep 13th, 2015
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include "p16F870.inc"
  2.  
  3. ; CONFIG
  4. ; __config 0xFFBA
  5. __CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _CP_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _WRT_ALL
  6.  
  7.  
  8. cblock 0x20
  9. d1
  10. d2
  11. endc
  12.  
  13. RES_VECT CODE 0x0000 ; processor reset vector
  14. GOTO INIT ; go to beginning of program
  15.  
  16. ; TODO ADD INTERRUPTS HERE IF USED
  17.  
  18. MAIN_PROG CODE ; let linker place main program
  19.  
  20. INIT
  21.  
  22. BANKSEL PR2 ;Define PWM frequency
  23. movlw b'11111001'
  24. movwf PR2
  25.  
  26. BANKSEL CCP1CON ;Enable PWM
  27. movlw b'00001100'
  28. movwf CCP1CON
  29.  
  30. BANKSEL TRISC ;Define PC2 as Output
  31. clrf TRISC
  32.  
  33. BANKSEL T2CON ;enable TMR2
  34. movlw b'00000100'
  35. movwf T2CON
  36.  
  37.  
  38. BANKSEL ADCON1
  39. BCF ADCON1, 7 ;left justified
  40.  
  41. BANKSEL ADCON0
  42. BSF ADCON0, 0 ;A/D is on
  43.  
  44. BCF ADCON0, 5 ;Select Channel0 / RA0
  45. BCF ADCON0, 4
  46. BCF ADCON0, 3
  47.  
  48. BSF ADCON0, 7 ;Set Conversion Clock
  49. BCF ADCON0, 6
  50.  
  51.  
  52. Main
  53. BSF ADCON0, 2 ;start ADC
  54. loop
  55. BTFSC ADCON0, 2 ;ADC Ready?
  56. GOTO loop ;check again
  57.  
  58. movfw ADRESH ;get upper 8 bit
  59. movwf CCPR1L ;output as PWM
  60. call _delay_15ms ;wait 15 ms
  61.  
  62.  
  63. goto Main
  64.  
  65.  
  66. _delay_15ms
  67. ;37493 cycles
  68. movlw 0x4A
  69. movwf d1
  70. movlw 0x1E
  71. movwf d2
  72. _delay_15ms_0
  73. decfsz d1, f
  74. goto $+2
  75. decfsz d2, f
  76. goto _delay_15ms_0
  77.  
  78. ;3 cycles
  79. goto $+1
  80. nop
  81.  
  82. ;4 cycles (including call)
  83. return
  84.  
  85. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement