SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     list p=18F1220 ; Set processor type
  2.     radix hex ; Sets the default radix for data exp.
  3.     config WDT=OFF, LVP=OFF, OSC = INTIO2 ; Disable Watchdog timer, Low V. Prog, and RA6 as a clock
  4.  
  5.  
  6. #define ADCON1 0xFC1
  7. #define PORTB 0xF81
  8. #define TRISB 0xF93
  9. #define WREG 0xFE8
  10.  
  11.    
  12. LAST equ 0x80
  13. CURR_A equ 0x81
  14. RESULT equ 0x82
  15.  
  16.     org 0x00
  17.      
  18.    
  19.     ; this is just a bunch of dumb setup
  20.     CLRF PORTB
  21.     CLRF TRISB
  22.    
  23.     ; what does this do? nobody knows
  24.     MOVLW 0x7F
  25.     MOVWF ADCON1
  26.    
  27.     ; in binary this is 0001 1111
  28.     ; means that pins RB0-RB5 are inputs, rest are outputs
  29.     ; why 5 pins? it works
  30.     MOVLW 0x1F
  31.     MOVWF TRISB
  32.  
  33.     CLRF LAST
  34.     CLRF CURR_A
  35.  
  36. Loop:
  37.     ; Put the value from PORTB into WREG
  38.     MOVF PORTB, 0
  39.    
  40.     ; Check and see if it's different from the last value
  41.     XORWF LAST, 0
  42.    
  43.     ; If it is different, branch over to CalcSum
  44.     BNZ CalcSum
  45.    
  46.     ; Redo the loop
  47.     GOTO Loop
  48.  
  49. CalcSum:
  50.    
  51.     ; Grab the value of A and put it into CURR_A
  52.     MOVF PORTB, 0
  53.     ANDLW 0x3 ; W = A
  54.     MOVWF CURR_A
  55.    
  56.     ; Grab the value of B and put it in WREG
  57.     ; (we have to shift it to the right and AND it
  58.     ; to ensure we have ONLY the bits we want)
  59.     MOVF PORTB, 0
  60.     RRNCF WREG
  61.     RRNCF WREG
  62.     ANDLW 0x3 ; W = B
  63.  
  64.     ; Add the value in WREG (aka B) with the value
  65.     ; in CURR_A (aka A), and put the result in WREG
  66.     ADDWF CURR_A, 0
  67.  
  68.     ; Put the sum of A and B in RESULT for easy debuggin'
  69.     MOVWF RESULT
  70.    
  71.     ; Shift WREG to the left a bunch so that it fits
  72.     ; correctly in PORTB
  73.     RLNCF WREG
  74.     RLNCF WREG
  75.     RLNCF WREG
  76.     RLNCF WREG
  77.     MOVWF PORTB
  78.  
  79.     ; Set the last PORTB to this PORTB. This way,
  80.     ; we can tell in the future if the inputs change.
  81.     MOVFF PORTB, LAST
  82.    
  83.     ; Go back to the main loop
  84.     GOTO Loop
  85.    
  86.     END
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top