Advertisement
Guest User

Assembly

a guest
Nov 6th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.86 KB | None | 0 0
  1. #include <p16f690.inc>
  2.  
  3. __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF)
  4.  
  5. ; Setup ADC subroutine
  6.                
  7.                 ORG     0x00
  8.         pause   EQU     0x10
  9.         pause1  EQU     0x20
  10.         val1    EQU     0x21
  11.         val2    EQU     0x22
  12.         val3    EQU     0x23
  13.         val4    EQU     0x24
  14.         checkVal    EQU     0x25
  15.                 goto    main       
  16.  
  17.  
  18.         checkError
  19.         ;       return
  20.    
  21.         checkCorrect
  22.         ;       return 
  23.    
  24.         readVal1
  25.  
  26.         ;       call        readADC
  27.         ;       movlw       W, val1
  28.                            
  29.         ;       call        LED1
  30.         ;       goto        loop1      
  31.  
  32.         readVal2   
  33.        
  34.         ;       call        readADC
  35.         ;       movlw       W, val2
  36.                            
  37.         ;       call        LED1
  38.         ;       goto        loop1
  39.  
  40.         readVal3   
  41.  
  42.         ;       call        readADC
  43.         ;       movlw       W, val3
  44.                            
  45.         ;       call        LED1
  46.         ;       goto        loop1
  47.                
  48.         readVal4                   
  49.         ;       call        readADC
  50.         ;       movlw       W, val4
  51.                            
  52.         ;       call        LED1
  53.         ;       goto        loop1
  54.  
  55. ;       check   btfsc       subwf val1,1
  56.         ;       call        checkError
  57.                
  58.         ;       btfsc       subwf val2,2
  59.         ;       call        checkError
  60.                
  61.         ;       btfsc       subwf val3,3
  62.         ;       call        checkError
  63.                
  64.         ;       btfsc       subwf val4,4
  65.         ;       call        checkError
  66.                
  67.         ;       call        checkCorrect           
  68.  
  69.         ; Subroutine setSwitch
  70.        
  71.         LED1                 
  72.                 movwf       PORTC
  73.             ;   bsf         PORTC, W
  74.                 call        delay
  75.                 bcf         PORTC, W
  76.                 return
  77.        
  78.         delay
  79.                 decfsz      pause,f
  80.                 goto        delay
  81.                 decfsz      pause1,f
  82.                 goto        delay
  83.                 return
  84.        
  85.         setSwitch
  86.                 BANKSEL     TRISA   ;Select BankA
  87.                 bsf         TRISA,3 ;Set bit3 PORTA as input
  88.                 BANKSEL     PORTA   ;select bank 0     
  89.                 return
  90.        
  91.         setLEDs
  92.                 BANKSEL     TRISC
  93.                 CLRF        TRISC  
  94.                 BANKSEL     PORTC
  95.                 RETURN
  96.  
  97.  
  98.            
  99.         initTimer0
  100.                 BANKSEL     OPTION_REG
  101.                 movlw       B'10000111' ; Configure Timer0
  102.                 movwf       OPTION_REG ; Maximum prescalar
  103.                 BANKSEL     TMR0
  104.                 clrf        TMR0 ; Initialise Timer0
  105.                 movlw       B'10100000' ; Timer0 interrupt active
  106.                 movwf       INTCON
  107.                 return
  108.  
  109.         setADC
  110.                 BANKSEL     TRISA
  111.                 bsf         TRISA,0
  112.                 movlw       0x10
  113.                 movwf       ADCON1
  114.                 BANKSEL     ANSEL
  115.                 bsf         ANSEL,0
  116.                 BANKSEL     ADCON0
  117.                 movlw       B'00000001'
  118.                 movwf       ADCON0
  119.                 goto        $+1
  120.                 goto        $+1
  121.                 goto        $+1
  122.                 return
  123.  
  124.         readADC
  125.                 BANKSEL     ADCON0 ; Select bank 0
  126.                 bsf         ADCON0,GO ; Start ADC conversion
  127.         loop    btfsc       ADCON0,GO ; Check if converted
  128.                 goto        loop ; Poll (loop) until done
  129.                 movf        ADRESH,W ; Put 8-bit result in W
  130.                 return
  131.  
  132.         main
  133.                 call        setADC ; Setup Channel 0 of ADC
  134.                 call        readADC ; Read the ADC value
  135.                 call        setSwitch
  136.                 call        setLEDs
  137.         loop1   btfsc       PORTA,3
  138.                 call        pressed
  139.                 call        LED1
  140.                 goto        loop1  
  141.        
  142.         pressed call        readADC
  143.                
  144.                 sublw       val1
  145.                 btfsc       zflg
  146.                 goto        $+2
  147.                 call        readVal1
  148.                
  149.                 btfsc       val2
  150.                 goto        $+2
  151.                 call        readVal2
  152.                
  153.                 btfsc       val3
  154.                 goto        $+2
  155.                 call        readVal3
  156.                
  157.                 btfsc       val4
  158.                 goto        $+2
  159.                 call        readVal4
  160.                
  161.    
  162.                 return
  163.  
  164.                 goto        $               ; Wait here
  165.                 end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement