[dcpu16] SE1

Viewer

  1. ;**********************************************************
  2. ;*  SE1.asm
  3. ;**********************************************************
  4. ;*  Microchip Technology Incorporated
  5. ;*  17 March 2003
  6. ;*  Assembled with MPASM V3.20 and MPLINK v3.20
  7. ;**********************************************************
  8. ;*  This assembly language program that reads the analogue voltage generated by 
  9. ;*  potentiometer R16 on the Minimal Board, converts it to a 4-bit number, and 
  10. ;*  writes that number to the PortB LEDs to give a light bar bit pattern as 
  11. ;*  the potentiometer is turned. The light bar is to have 4 states, 
  12. ;*  corresponding to the numbers 0, 1, 3 and 7.
  13. ;*    
  14. ;*  By Vishant Prasad (470416309)
  15. ;**********************************************************
  16.  
  17.     #include "p18cxxx.inc"         ;wrapper for all PIC18 symbols
  18.     
  19.     ; if building for PIC18F452
  20.     #include "ConfigRegsPIC18f452.inc"     ;set Configuration Registers
  21.     
  22.     ;Start at reset adress - declares code section 'RST'
  23.     RST code 0x0000
  24.         goto Setup
  25.        
  26.         ;Declares code section
  27.         code 0x0030
  28.        
  29. Setup:
  30.     clrf    PORTD           ;Clear PORTD
  31.     clrf    TRISD           ;Set PORTD to Output
  32.     
  33.     movlw   B'01000001'      ;Enable the A/D - Timing: FOSC/8 (Internal Clock)
  34.     movwf   ADCON0               ;Enable the A/D Control Register
  35.     movlw   B'00001110'      ;Analog Channel - take VDD & VSS as references             
  36.     movwf   ADCON1           
  37.     movlw   B'11000111'      ;Timer 0 ON - 1:256 prescaler
  38.     movwf   T0CON
  39.     
  40. Main:
  41.     btfss   INTCON, TMR0IF  ;Detect Timer 0
  42.     goto    Main
  43.     bcf         INTCON, TMR0IF
  44.     
  45.     bsf         ADCON0, GO         ;Trigger the A/D Conversion
  46.     goto    ADConversion
  47.     
  48. ClearBit:
  49.     btfsc   ADRESH, 6       ;Check if bit is clear through comparison     
  50.     goto    LED_I1              ;Set LED to 01
  51.     movlw   B'00000000'      ;Set LED to 00 otherwise
  52.     
  53.     movwf   PORTD                ;LED values set from WREG
  54.     goto    Main            
  55.     
  56. LED_I1:
  57.     movlw   B'00000001'      ;Set LED to 01
  58.     movwf   PORTD                ;LED values set from WREG to PORTB
  59.     goto    Main
  60.     
  61. SetBit:
  62.     btfsc   ADRESH, 6       ;Check if bit is clear through comparison             
  63.     goto    LED_I2              ;Set LED to 11
  64.     movlw   B'00000011'      ;Set LED to 10 otherwise
  65.  
  66.     movwf   PORTD                ;LED values set from WREG
  67.     goto    Main
  68.     
  69. LED_I2:
  70.     movlw   B'00000111'      ;Set LED to 11
  71.     movwf   PORTD                ;LED values set from WREG
  72.     goto    Main
  73.     
  74. ADConversion:
  75.     btfss   PIR1, ADIF      ;Wait for flag bit from A/D conversion
  76.     goto    ADConversion    
  77.     swapf   ADRESH, W       ;Swap A/D conversion result 
  78.     andlw   0x0f         ;Remove last 4 bits
  79.     btfsc   ADRESH, 7       ;Check if bit is clear through comparison
  80.     goto    SetBit              ;Set bit if clear
  81.     goto    ClearBit        ;Otherwise clear bit
  82. end

Editor

You can edit this paste and save as new:


File Description
  • SE1
  • Paste Code
  • 26 Sep-2021
  • 2.81 Kb
You can Share it: