Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pic 16 4.74 KB | None | 0 0
  1.     list p=16F684           ; list directive to define processor
  2.     #include <p16f684.inc>  ; processor specific variable definitions
  3.     __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
  4.     radix dec               ; default radix is decimal
  5.     errorlevel -302         ; suppress warnings when accessing SFRs in bank 1
  6. ;****************************** Assignment Statements ****************************
  7. ; Set up two counters to count down a delay
  8. COUNT1 EQU 20h  ; Available GPR at address 20h used for storing COUNT1
  9. COUNT2 EQU 21h  ; Available GPR at address 21h used for storing COUNT2
  10. ;******************************* #define Preprocessor statements *****************
  11. ; Define the 'direction' TRISA configuration for all leds
  12. #define TRISA_D01   B'00001111' ; D1 connected between RA4 and RA5 
  13. #define TRISA_D23   B'00101011' ; D2 connected between RA4 and RA5 
  14. #define TRISA_D45   B'00011011' ; D4 connected between RA4 and RA5 
  15. #define TRISA_D67   B'00111001' ; D7 connected between RA4 and RA5 
  16.  
  17. ;6427717
  18. ; Define the 'data output' PORTA setting for switching ON the LEDs D2 to D3
  19. #define LED_D0_ON   B'00010000' ; Sending HIGH to D0
  20. #define LED_D1_ON   B'00100000' ; Sending HIGH to D1
  21. #define LED_D2_ON   B'00010000' ; Sending HIGH to D2
  22. #define LED_D3_ON   B'00000100' ; Sending HIGH to D3
  23. #define LED_D4_ON   B'00100000' ; Sending HIGH to D4
  24. #define LED_D5_ON   B'00000100' ; Sending HIGH to D5
  25. #define LED_D6_ON   B'00000100' ; Sending HIGH to D6
  26. #define LED_D7_ON   B'00000010' ; Sending HIGH to D7
  27.  
  28. ;****************************** Start of Program- Initial configuration
  29.         org     0x000       ; Processor reset vector
  30.         bcf     STATUS,RP0  ; Bank 0 selected
  31.         movlw   07h         ; Set RA<2:0> to digital and
  32.         movwf   CMCON0      ; Comparators turned OFF
  33.         bsf     STATUS,RP0  ; Bank 1 selected
  34.         clrf    ANSEL       ; Digital I/O selected
  35.         movlw   B'00111111' ; Move in W - 0x3F - Set all I/O pins as digital inputs
  36.         movwf   TRISA       ; Configure I/O ports      
  37.         clrf    INTCON      ; Disable all interrupts, clear all flags  
  38.         bcf     STATUS,RP0  ; Bank 0 selected
  39.         clrf    PORTA       ; Clear all outputs
  40.         movlw   0xff        ; First load a value of say, F0h in the W register
  41.         movwf   COUNT2      ; Now move it to COUNT2 register
  42.  
  43. START  
  44.         bsf     STATUS,RP0      ; Bank 1 selected
  45.         movlw   TRISA_D67       ; Configure LEDs D6 and D7 in TRISA
  46.         movwf   TRISA
  47.         bcf     STATUS, RP0 ; Bank 0 selected
  48.         movlw   LED_D6_ON   ; Write '1' for D6 into Working Register
  49.         movwf   PORTA       ; Send '1' through PORTA to light up LED D6
  50.         call    DELAY
  51.         clrf    PORTA       ; Clear PORTA
  52.         call    DELAY
  53.         bsf     STATUS, RP0 ; Bank 1 selected
  54.         movlw   TRISA_D45       ; Configure LEDs D4 and D5 in TRISA
  55.         movwf   TRISA
  56.         bcf     STATUS, RP0 ; Bank 0 selected
  57.         movlw   LED_D4_ON   ; Write '1' for D4 into Working Register
  58.         movwf   PORTA       ; Send '1' through PORTA to light up LED D4
  59.         call    DELAY
  60.         clrf    PORTA       ; Clear PORTA
  61.         call    DELAY
  62.         bsf     STATUS, RP0 ; Bank 1 selected
  63.         movlw   TRISA_D23       ; Configure LEDs D2 and D3 in TRISA
  64.         movwf   TRISA
  65.         bcf     STATUS, RP0 ; Bank 0 selected
  66.         movlw   LED_D2_ON   ; Write '1' for D2 into Working Register
  67.         movwf   PORTA       ; Send '1' through PORTA to light up LED D2
  68.         call    DELAY
  69.         clrf    PORTA       ; Clear PORTA
  70.         call    DELAY
  71.         bsf     STATUS, RP0 ; Bank 1 selected
  72.         movlw   TRISA_D67       ; Configure LEDs D6 and D7 in TRISA
  73.         movwf   TRISA
  74.         bcf     STATUS, RP0 ; Bank 0 selected
  75.         movlw   LED_D7_ON   ; Write '1' for D7 into Working Register
  76.         movwf   PORTA       ; Send '1' through PORTA to light up LED D7
  77.         call    DELAY
  78.         clrf    PORTA       ; Clear PORTA
  79.         call    DELAY
  80.         movlw   LED_D7_ON   ; Write '1' for D7 into Working Register
  81.         movwf   PORTA       ; Send '1' through PORTA to light up LED D7
  82.         call    DELAY
  83.         clrf    PORTA       ; Clear PORTA
  84.         call    DELAY
  85.         bsf     STATUS, RP0 ; Bank 1 selected
  86.         movlw   TRISA_D01       ; Configure LEDs D0 and D1 in TRISA
  87.         movwf   TRISA
  88.         bcf     STATUS, RP0 ; Bank 0 selected
  89.         movlw   LED_D1_ON   ; Write '1' for D1 into Working Register
  90.         movwf   PORTA       ; Send '1' through PORTA to light up LED D1
  91.         call    DELAY
  92.         clrf    PORTA       ; Clear PORTA
  93.         call    DELAY
  94.         bsf     STATUS, RP0 ; Bank 1 selected
  95.         movlw   TRISA_D67       ; Configure LEDs D6 and D7 in TRISA
  96.         movwf   TRISA
  97.         bcf     STATUS, RP0 ; Bank 0 selected
  98.         movlw   LED_D7_ON   ; Write '1' for D7 into Working Register
  99.         movwf   PORTA       ; Send '1' through PORTA to light up LED D7
  100.         call    DELAY
  101.         clrf    PORTA       ; Clear PORTA
  102.         call    DELAY
  103.  
  104.         goto   START    ; loop again - Loop forever - blink continuously
  105. DELAY
  106. LOOP1  
  107.         decfsz   COUNT1,1   ; Decrement COUNT1 and skip next instruction if zero
  108.         goto     LOOP1      ; else loop back to LOOP1
  109.         decfsz   COUNT2,1   ; Decrement COUNT2 and skip next instruction if zero
  110.         goto     LOOP1      ; else loop back to LOOP1
  111.         movlw    0xff       ; Reload the second counter for the next iteration
  112.         movwf    COUNT2
  113.         return
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement