Advertisement
Guest User

PIC16f84A

a guest
Jul 13th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 3.63 KB | None | 0 0
  1. ;******************************************************************************
  2. ;PICMicro3
  3. ;By Daniel 2017
  4. ;8-Bit stopwatch BCD Display with start stop and up down buttons
  5. ;******************************************************************************
  6. ;MPASM  Assembler Init
  7.  list       p=16f84a
  8.  #include   <p16f84a.inc>
  9.  errorlevel -302
  10.  __CONFIG   _CP_OFF &   _WDT_OFF    &   _PWRTE_ON   &   _XT_OSC
  11. ;******************************************************************************
  12. ;Custom Port names
  13.  #define    b1    PORTB,7
  14.  #define    b2    PORTB,4
  15. ;******************************************************************************
  16. ;Variables
  17.  cblock     0x20
  18.         Cntd1
  19.         CntByt1
  20.         CntByt2
  21.         LoByt1
  22.         HiByt1     
  23.  endc
  24. ;Starting Vector
  25.  org 0x0000
  26.  goto Init
  27. ;******************************************************************************
  28. ;Delay Block
  29. Delay1          ;1ms
  30.     movlw   D'247'
  31.  
  32. VarDel1
  33.     movwf   Cntd1
  34.  
  35. Loopd1
  36.     nop
  37.     decfsz Cntd1,f
  38.     goto   Loopd1
  39.     return
  40. ;******************************************************************************
  41. LpCnt1          ;200ms
  42.     movlw   D'200'
  43.  
  44. VarCnt1
  45.     movwf   CntByt1
  46.  
  47. LoopBlk1
  48.     call    Delay1
  49.     decfsz  CntByt1,f
  50.     goto    LoopBlk1
  51.     return
  52. ;******************************************************************************
  53. LpCnt2          ;500ms
  54.     movlw   D'2'
  55.  
  56. VarCnt2
  57.     movwf   CntByt2
  58.  
  59. LoopBlk2
  60.     call    LpCnt1
  61.     decfsz  CntByt2,f
  62.     goto    LoopBlk2
  63.     return
  64. ;******************************************************************************
  65. ;Increment 2Bytes Block
  66. Inc2By
  67.     incf    LoByt1,f
  68.     movlw   d'10'       ;Lower byte upper limit +1
  69.     xorwf   LoByt1,w    ;XOR into w to test if equal
  70.     btfss   STATUS,Z    ;Skip if not equal (Z=0)
  71.     goto    Disp2Byt
  72.     movlw   b'00000000'
  73.     movwf   LoByt1
  74.     incf    HiByt1,f
  75.     movlw   d'10'
  76.     xorwf   HiByt1,w
  77.     btfss   STATUS,Z
  78.     goto    Disp2Byt
  79.     movlw   b'00000000'
  80.     movwf   HiByt1
  81.     goto    Disp2Byt
  82. ;Decrement 2Bytes Block
  83. Dec2By
  84.     decf    LoByt1,f
  85.     movlw   b'11111111'
  86.     xorwf   LoByt1,W
  87.     btfss   STATUS,Z
  88.     goto    Disp2Byt
  89.     movlw   b'00001001'
  90.     movwf   LoByt1
  91.     decf    HiByt1,f
  92.     movlw   b'11111111'
  93.     xorwf   HiByt1,W
  94.     btfss   STATUS,Z
  95.     goto    Disp2Byt
  96.     movlw   b'00001001'
  97.     movwf   HiByt1
  98. ;Display Block
  99. Disp2Byt
  100.     movf    LoByt1,W        ;Load byte in w
  101.     movwf   PORTA       ;Upper nibble is ignored
  102.     movf    HiByt1,W    ;Swap upper and lower nibble
  103.     movwf   PORTB       ;Load upper nibble into B
  104.     return
  105. ;******************************************************************************
  106. ;Stop/Start button block
  107. Stopb1
  108.     movlw   d'50'
  109.     call    VarCnt1
  110.     btfss   b1
  111.     goto    Startb1
  112.    
  113. Startb1
  114.     movlw   d'50'
  115.     call    VarCnt1
  116.     btfsc   b1
  117.     goto    Stopb1
  118.    
  119. Runb1  
  120.     movlw   d'50'
  121.     call    VarCnt1
  122.     btfss   b1
  123.     goto    Runb1
  124.     return
  125. ;******************************************************************************
  126. ;Init Block
  127. Init
  128.     bsf STATUS,RP0  ;Select Bank1
  129.     clrf    TRISA       ;Write 0 to TRISA to set as outputs
  130.     movlw   b'11110000' ;4 inputs and 4 outputs
  131.     movwf   TRISB       ;Make the upper nibble inputs
  132.     movlw   b'00001000' ;Move 1 into OPTION register
  133.     movwf   OPTION_REG
  134.     bcf STATUS,RP0  ;Select Bank0
  135.     movlw   b'00000000' ;Default state for PORTA
  136.     movwf   PORTA
  137.     movlw   b'10010000' ;Default state for PORTB
  138.     movwf   PORTB
  139.    
  140.     movlw   b'00000000'
  141.     movwf   LoByt1      ;Resets Counter
  142.     movwf   HiByt1
  143.    
  144.     goto    Start
  145.    
  146. ;******************************************************************************
  147. ;Main Program
  148. Start
  149.     call    LpCnt1      ;Wait 200ms
  150.    
  151.     btfss   b1      ;Test if B1 is pressed
  152.     call    Stopb1      ;Goto Idle button routine
  153.    
  154.     btfss   b2      ;Test if B2 is pressed
  155.     call    Dec2By      ;Decrement count if b2 is held down
  156.     btfss   b2
  157.     goto    Start
  158.    
  159.     call    Inc2By      ;Else increment count
  160.    
  161.     goto    Start
  162.  
  163.     end
  164. ;******************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement