Electgpl

PIC - POV Mensaje ASM

Dec 2nd, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     LIST    p=16f648a       ; tell assembler what chip we are using
  2.     include "P16f648a.inc"      ; include the defaults for the chip
  3.     __config 0x3f18         ; sets the configuration settings (oscillator type etc.)
  4.  
  5. PC  equ     0x02
  6. ;
  7.     cblock  0x20            ; start of general purpose registers
  8.     counta              ; used in the delay routine
  9.     countb              ; used in the delay routine
  10.     low_address             ; stores the eproms low address (first 8bits)
  11.     high_address            ; stores the eproms high address (last 8bits)
  12.     pixel_counter           ; stores the total number of horizontal pixels
  13.     frame_counter           ; stores the total number of times to repeat each frame
  14.     total_frames            ; stores the total number of frames in our animation
  15.     endc
  16. ;
  17.     org     0x0000          ; org sets the origin, 0x0000 for the 16F628,
  18. ;
  19.     movlw   0x07
  20.     movwf   CMCON           ; turn comparators off
  21. ;
  22.     bsf     STATUS,RP0      ; select bank 1
  23.     movlw   b'00000000'         ; set PORTB all outputs
  24.     movwf   TRISB           ;
  25.     movlw   b'00100000'         ; set PORTA all outputs except for bit 5
  26.     movwf   TRISA           ;
  27.     bcf     STATUS,RP0      ; select bank 0
  28. ;
  29. setup   movlw   d'178'          ; defines how many frames we have -
  30.     movwf   total_frames        ; in our animation loop
  31.     movlw   b'10011000'         ; turns led outputs OFF, disables
  32.     movwf   PORTA           ; led latches and opens the address latches
  33.     clrf    PORTB           ; sets the sixteen bit address to 00 hex
  34.     bcf     PORTA,3         ; disables low address latch
  35.     bcf     PORTA,4         ; disables high address latch
  36.     clrf    low_address         ; clear the low_address variable
  37.     clrf    high_address        ; clear the high_address variable
  38. frame_again
  39.     movlw   d'02'           ; sets it up to repeat each frame however many times
  40.     movwf   frame_counter       ; you want (the higher the number, the slower the animation.)
  41. ;
  42. draw_again
  43.     movlw   d'85'           ; sets it up for 85 pixels horizontaly - this number is perfect
  44.     movwf   pixel_counter       ; because 85x3 = 255 which is our lower address bus limit!
  45.     clrf    low_address         ; reset the low_address variable back to 00 hex
  46.     clrf    PORTB           ; clears PORTB and then
  47.     bsf     PORTA,3         ; resets the low address back to 00 hex
  48.     bcf     PORTA,3         ; I had colour sync problems without this...
  49. ;
  50. ; upto this point the leds are all OFF, the eeprom has 00000000 00000000 on its address bus
  51. ; and all latches are now in their disabled or closed state.
  52. ; This next section is the main DRAWING part of the program, it basically grabs
  53. ; all the colour data - red, green then blue and then outputs the data to the leds
  54. ; it repeats this process untill all 85 columns are drawn, then it will repeat that
  55. ; same frame for however many times we stated in the above code. and finally it will
  56. ; move onto each successive frame in our animation sequence untill we reach the end.
  57. ; then it will reset itself and start all over again!
  58. ;
  59. begin   bsf     PORTA,0         ; outputs 8bits to the red latch and holds it
  60.     bcf     PORTA,0         ; closes the red latch
  61.     call    inc_address         ; increment to the next eprom address
  62.     bsf     PORTA,1         ; outputs 8bits to the green latch and holds it
  63.     bcf     PORTA,1         ; closes the green latch
  64.     call    inc_address         ; increment to the next eprom address
  65.     bsf     PORTA,2         ; outputs 8bits to the blue latch and holds it
  66.     bcf     PORTA,2         ; closes the blue latch
  67.     call    inc_address         ; increment to the next eprom address
  68.     bcf     PORTA,7         ; enables all led latch outputs which turns on the leds
  69.     call    delay           ; hold the leds on for just a while...
  70.     bsf     PORTA,7         ; disables all led latch outputs which turns off the leds
  71.     decfsz  pixel_counter,1     ; decrements the pixel counter from 85 until 0
  72.     goto    begin           ; if its not yet zero, keep drawing until 0
  73. wait    btfss   PORTA,5         ; Check to see if we are at the sensor check point -
  74.     goto    wait            ; If not, keep checking until we are there BEFORE we start drawing the next frame.
  75.     decfsz  frame_counter,1     ; now decrement the frame counter
  76.     goto    draw_again      ; if the frame_counter is not zero go back and draw it again
  77.     call    inc_frame       ; call the routine so we can move to the next frame of animation
  78.     decfsz  total_frames,1      ; decrement the total frames counter by one, reset if it is 0
  79.     goto    frame_again         ; displays this next frame for however many times we specified.
  80.     goto    setup           ; start again!
  81. ;
  82. ; This next routine increments the low 8-bits of the address bus by one.
  83. ;
  84. inc_address
  85.     incf    low_address,f       ; increment the low_address variable by one
  86.     movf    low_address,w       ; copy it to w register
  87.     movwf   PORTB           ; now output it to PORTB
  88.     bsf     PORTA,3         ; latch it to the low address of the eeprom
  89.     bcf     PORTA,3         ; now close the latch
  90.     return              ; back to the main program
  91. ;
  92. ; This next bit just increments to the next frame in the animation
  93. ;
  94. inc_frame
  95.     incf    high_address,f      ; increment the high_address variable by one
  96.     movf    high_address,w      ; copy it to the w register
  97.     movwf   PORTB           ; now output it to PORTB
  98.     bsf     PORTA,4         ; latch it to the high address of the eprom
  99.     bcf     PORTA,4         ; now close the latch
  100.     return              ; back to the main program
  101. ;
  102. ; Heres a nice and simple delay routine
  103. ;
  104. delay   movlw   d'55'
  105.     movwf   counta
  106. again_a decfsz  counta,1
  107.     goto    again_a
  108.     return
  109. ;
  110.     end
Advertisement
Add Comment
Please, Sign In to add comment