Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pic 16 6.29 KB | None | 0 0
  1. INCLUDE     "P16F877.inc"
  2.             List P=16F877
  3. ;************************************
  4. d1              equ         0x20
  5. d2              equ         0x21
  6. d3              equ         0x22
  7. w_temp              equ         0x23
  8. status_temp         equ         0x24
  9. ASCI                equ         0x25
  10. var_a               equ         0x26
  11. var_b               equ         0x27
  12. ganger              equ         0x28
  13. EN              equ         0x01
  14. rad             equ         0x29
  15. counter             equ         0x30
  16. state               equ         0x31
  17. dioder              equ         0x32
  18. d11             equ         0x33
  19. d21             equ         0x34
  20. letterCounter   equ     0x35
  21. radByte             equ         0x36
  22. rowNumber           equ         0x37
  23. dioder_temp         equ         0x38
  24. ;************************************
  25.                 org     0x00
  26.                 clrf        STATUS
  27.                 movlw       0x00
  28.                 movwf       0x0A
  29.                 goto        init
  30. ;************************************
  31.                 org     0x04
  32.                 goto        avbrott
  33. ;************************************
  34. avbrott             movwf       w_temp
  35.                 swapf       STATUS,0
  36.                 movwf       status_temp
  37.                 ;***
  38.                 ;hämtar tecken från receive reg
  39.  
  40.                 movf        RCREG,0
  41.                 movwf       ASCI
  42.                
  43.                 ;if lettercounter = 16 byt rad
  44.                 movlw       0x10
  45.                 subwf       letterCounter,0
  46.                 btfss       STATUS,2
  47.                 goto        general
  48.                 clrf        letterCounter           ;letterCounter = 0, ändrar rad
  49.                 ;om rowNumber = 00, byta till rad 2, om row number = FF clear o rad 1
  50.                 movlw       0x00                    ;byte till rad 2
  51.                 subwf       rowNumber,0
  52.                 btfss       STATUS,2
  53.                 goto        rowTwoTest
  54.                 movlw       0xFF                    ;sätter RowNumber till FF, rad 2
  55.                 movwf       rowNumber
  56.                 movlw       0xC0
  57.                 movwf       radByte
  58.                 call        change_row
  59.                 goto        done
  60. rowTwoTest          movlw       0xFF                    ;kollar rad 2
  61.                 subwf       rowNumber,0
  62.                 btfss       STATUS,2
  63.                 goto        done
  64.                 clrf        letterCounter
  65.                 ;incf       letterCounter
  66.                 call        clear_display
  67.                 clrf        rowNumber
  68. done           
  69.  
  70. general             ;skicka tecten till LCD
  71.                 movfw       ASCI
  72.                 call        Visa_LCD
  73.                 ;call       waithz
  74.                 incf        letterCounter
  75.  
  76.                 ;***
  77.                 swapf       status_temp,0
  78.                 movwf       STATUS
  79.                 swapf       w_temp,1
  80.                 swapf       w_temp,0
  81.                 retfie
  82. ;************************************
  83. change_row          movfw       radByte
  84.                 movwf       rad
  85.                 andlw       0xF0
  86.                 movwf       PORTD
  87.                 call        enable
  88.                 swapf       rad,w
  89.                 andlw       0xF0
  90.                 movwf       PORTD
  91.                 call        enable
  92.                 call        waitms
  93.                 return
  94. ;************************************
  95. clear_display           movlw       0x01
  96.                 movwf       rad
  97.                 andlw       0xF0
  98.                 movwf       PORTD
  99.                 call        enable
  100.                 swapf       rad,w
  101.                 andlw       0xF0
  102.                 movwf       PORTD
  103.                 call        enable
  104.                 call        waitms
  105.                 return
  106. ;************************************
  107. waitms              movlw       0x0a
  108.                 movwf       var_b
  109. loop2               movlw       0x64
  110.                 movwf       var_a
  111. loop1               decfsz      var_a,1
  112.  
  113.                 goto        loop1
  114.                 decfsz      var_b,1
  115. noll
  116.                 goto        loop2
  117.                 return
  118. ;************************************
  119. enable              bsf         PORTD,EN
  120.                 call        waitms
  121.                 bcf         PORTD,EN
  122.                 call        waitms
  123.                 return
  124. ;************************************
  125. LCDinit             movlw       0xff
  126.                 movwf       ganger
  127. loop3               call        waitms
  128.                 decfsz      ganger,1
  129.                 goto        loop3
  130. ;Första anrop
  131.                 movlw       0x30
  132.                 movwf       PORTD
  133.                 call        enable
  134. ;Vänta mer 4,1ms
  135.                 movlw       0x05
  136.                 movwf       ganger
  137. loop4               call        waitms
  138.                 decfsz      ganger,1
  139.                 goto        loop4
  140. ;andra anrops
  141.                 movlw       0x30
  142.                 movfw       PORTD
  143.                 call        enable
  144. ;Vänta mer än 0,1ms
  145.                 call        waitms
  146. ;tredje anrop
  147.                 movlw       0x30
  148.                 movwf       PORTD
  149.                 call        enable
  150.                 call        waitms
  151.                 movlw       0x20
  152.                 movwf       PORTD
  153.                 call        enable
  154.                 call        waitms
  155.                 movlw       0x20
  156.                 movwf       PORTD
  157.                 call        enable
  158.                 movlw       0x80
  159.                 movwf       PORTD
  160.                 call        enable
  161.                 call        waitms
  162.                 movlw       0x00        ;clearar displayen
  163.                 movwf       PORTD
  164.                 call        enable
  165.                 movlw       0x10
  166.                 movwf       PORTD
  167.                 call        enable
  168.                 call        waitms
  169.                 movlw       0x00
  170.                 movwf       PORTD
  171.                 call        enable
  172.                 movlw       0x60
  173.                 movwf       PORTD
  174.                 call        enable
  175.                 call        waitms
  176.                 movlw       0x00
  177.                 movwf       PORTD
  178.                 call        enable
  179.                 movlw       0xE0
  180.                 movwf       PORTD
  181.                 call        enable
  182.                 call        waitms
  183.                 return
  184. Visa_LCD            movwf       ASCI
  185.                 andlw       0xF0
  186.                 movwf       PORTD
  187.                 bsf     PORTD,0
  188.                 call        enable
  189.                 swapf       ASCI,w
  190.                 andlw       0xF0
  191.                 movwf       PORTD
  192.                 bsf     PORTD,0
  193.                 call        enable
  194.                 return
  195. init                movlw       0xFF
  196.                 movwf       PORTA
  197.                 movwf       PORTB
  198.                 clrf        PORTC
  199.                 clrf        PORTD
  200.                 bsf     STATUS,RP0
  201.                 movlw       0x00
  202.                 movwf       TRISA
  203.                 movwf       TRISB
  204.                 movwf       TRISD
  205.                 movlw       b'11000000'         ;tar bort RC7 o RC6 som digitala I/O för UART
  206.                 movwf       TRISC
  207.                 movlw       0x06
  208.                 movwf       ADCON1
  209.                 bcf     STATUS,RP0
  210.                 ;*** UART INSTÄLLNINGAR ***
  211.                 movlw       b'10010000'
  212.                 movwf       RCSTA
  213.                 bsf     STATUS,RP0
  214.                 movlw       b'00100110'
  215.                 movwf       TXSTA
  216.                 movlw       0x4D        ;77
  217.                 movwf       SPBRG
  218.                 bcf     STATUS,RP0
  219.                 ; *** AVBROTT INSTÄLLNINGAR ***
  220.                 bsf     STATUS,RP0
  221.                 movlw       b'00100000'
  222.                 movwf       PIE1
  223.                 bcf     STATUS,RP0
  224.                 movlw       b'11000000'
  225.                 movwf       INTCON
  226.                 call        LCDinit
  227.                 movlw       0xFF
  228.                 movwf       dioder
  229.                 bcf     dioder,0
  230.                
  231.                 bsf     STATUS,0
  232.                 clrf        counter
  233.                 movlw       0xff
  234.                 movwf       state
  235.                 clrf        letterCounter
  236.                 clrf        rowNumber
  237.                 goto        main
  238.            
  239. waithz              movlw       0x1A        ;2999995 cycles
  240.                 movwf       d1          ;Delay = 1 second
  241.                 movlw       0x8B
  242.                 movwf       d2
  243.                 movlw       0x07
  244.                 movwf       d3
  245. Delay_0
  246.                 decfsz      d1, f
  247.                 goto        $+2
  248.                 decfsz      d2, f
  249.                 goto        $+2
  250.                 decfsz      d3, f
  251.                 goto        Delay_0
  252.  
  253.                 ;5 cycles
  254.                 goto        $+1
  255.                 goto        $+1
  256.                 nop
  257.                 return
  258.  
  259. shortWait           movlw       0x5F
  260.                 movwf       d11
  261.                 movlw       0xEB
  262.                 movwf       d21
  263.                 Delay_1
  264.                 decfsz      d11, f
  265.                 goto        $+2
  266.                 decfsz      d21, f
  267.                 goto        Delay_1
  268.  
  269.                 ;2 cycles
  270.                 goto    $+1
  271.                 return
  272.  
  273. ;dioder '01111111' btfsc dioder,4
  274. ;       '1011111' btfsc dioder,3
  275.            
  276. diodFunk            btfsc       dioder,0        ;bestämmer riktning
  277.                 goto        fortsatt
  278.                 movlw       0x00
  279.                 movwf       state           ;state = 0, vill ha rotation åt vänster
  280.  
  281. fortsatt            btfsc       dioder,7
  282.                 goto        fortsatt_igen
  283.                 movlw       0xff
  284.                 movwf       state           ;state = ff, vill ha rotation åt höger
  285.  
  286. fortsatt_igen   btfsc       state,0
  287.                 goto        cont1
  288.                 RLF     dioder,f        ;roterar höger
  289. cont1               btfss       state,0         ;rotationslogic
  290.                 goto        cont2
  291.                 RRF     dioder,f        ;roterar vänster
  292. cont2               movfw       dioder          ;flyttar dioder till working
  293.                 movwf       dioder_temp     ;flyttar working till dioder_temp, det är denna som skrivs ut (och används för att inte röra till det i dioder)
  294.                 swapf       dioder_temp,f   ;swappar så att PORTA & PORTB 3210 7654 blir 7654 3210
  295.                 movfw       dioder_temp
  296.                 movwf       PORTA           ;får dioder att lysa :)
  297.                 movwf       PORTB
  298.                 return
  299.  
  300.  
  301.  
  302. main           
  303.                 call        shortWait
  304.                 call        diodFunk
  305.                 goto        main
  306. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement