Advertisement
prison_lox

Lab 2 - Task 2.2 + 7 Segment

Oct 1st, 2023 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 2.58 KB | None | 0 0
  1. #include<p18F4550.inc>
  2.  
  3. CONFIG FOSC = HS ; H oscillator, HS used by USB
  4. CONFIG WDT = OFF ; HW disabled - SW Controlled ( deactivation des watchdog timer)
  5. CONFIG DEBUG = OFF
  6. CONFIG MCLRE = OFF ;
  7. CONFIG CPUDIV = OSC1_PLL2
  8. CONFIG PBADEN = OFF
  9.    
  10.  
  11. counter_value equ H'04'
  12.  
  13.    
  14. RES_VECTOR CODE 0x0000;
  15. goto init
  16.  
  17. org 0x0008 ; interrupt vector at PM address 0x0008
  18. goto irq_handle ; go to the function for the   
  19.  
  20.  INT0_interrupt
  21.     ; --- clear the TMR0 interrupt flag
  22.     ; note : it is COMPULSORY to clear the flag
  23.     bcf INTCON , INT0IF ; clear the flag
  24.     ; --- increment PORTC
  25.     incf PORTC
  26.     retfie
  27.  
  28. irq_handle ; --- interrupt routine
  29.     ; --- flag test -> is it the INT0 ?
  30.     btfsc INTCON , INT0IF
  31.     goto INT0_interrupt ; yes , it is TMR0
  32.     retfie ; --- no , return from interrupt
  33.  
  34. MAIN_PROG CODE
  35.  
  36. init
  37.     clrf TRISD ; set PORTD as output
  38.     clrf PORTD ; clear PORTD
  39.    
  40.     clrf TRISC ; set PORTC as output
  41.     clrf PORTC ; clear PORTC
  42.    
  43.     setf TRISB ;
  44.     clrf PORTB ; clear PORTB
  45.    
  46.     ; set timer mode
  47.     bsf INTCON , GIE ; activate interrupts
  48.     bsf INTCON , INT0IE ; activate external interrupt
  49.      ; set interrupt on BO
  50.     bcf INTCON, INTEDG0
  51.     goto main_loop
  52.  
  53.    
  54. main_loop
  55.     call seg_set_0
  56.     goto main_loop ; push skipped
  57.    
  58.  
  59. seg_set_0
  60.     movlw H'00'
  61.     CPFSEQ counter_value
  62.     goto seg_set_1
  63.     movlw H'3F'
  64.     movwf PORTD
  65.     return
  66.    
  67. seg_set_1
  68.     movlw H'01'
  69.     CPFSEQ counter_value
  70.     goto seg_set_2
  71.     movlw H'06'
  72.     movwf PORTD
  73.     return
  74.    
  75. seg_set_2
  76.     movlw H'02'
  77.     CPFSEQ counter_value
  78.     goto seg_set_3
  79.     movlw H'5B'
  80.     movwf PORTD
  81.     return
  82.    
  83. seg_set_3
  84.     movlw H'03'
  85.     CPFSEQ counter_value
  86.     goto seg_set_4
  87.     movlw H'4F'
  88.     movwf PORTD
  89.     return
  90.    
  91. seg_set_4
  92.     movlw H'04'
  93.     CPFSEQ counter_value
  94.     goto seg_set_5
  95.     movlw H'66'
  96.     movwf PORTD
  97.     return
  98.    
  99. seg_set_5
  100.     movlw H'05'
  101.     CPFSEQ counter_value
  102.     goto seg_set_6
  103.     movlw H'6D'
  104.     movwf PORTD
  105.     return
  106.    
  107. seg_set_6
  108.     movlw H'06'
  109.     CPFSEQ counter_value
  110.     goto seg_set_7
  111.     movlw H'7D'
  112.     movwf PORTD
  113.     return
  114.    
  115. seg_set_7
  116.     movlw H'07'
  117.     CPFSEQ counter_value
  118.     goto seg_set_8
  119.     movlw H'07'
  120.     movwf PORTD
  121.     return
  122.    
  123. seg_set_8
  124.     movlw H'08'
  125.     CPFSEQ counter_value
  126.     goto seg_set_9
  127.     movlw H'7F'
  128.     movwf PORTD
  129.     return
  130.    
  131. seg_set_9
  132.     movlw H'09'
  133.     CPFSEQ counter_value
  134.     return
  135.     movlw H'6F'
  136.     movwf PORTD
  137.     return
  138.  
  139. counter_reset
  140.     clrf counter_value
  141.     return
  142. END  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement