Advertisement
Guest User

TP2 code interrupt

a guest
Oct 30th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <p18F4550.inc>
  2. CONFIG WDT = OFF ; disablewatchdogtimer
  3. CONFIG MCLRE = ON ; MCLEAR Pin on
  4. CONFIG DEBUG = OFF ; DisableDebugMode
  5. CONFIG FOSC = HS
  6.  
  7.  
  8. org  0x0000            
  9. goto prog_init                  
  10.  
  11. org 0x0008 ; si interruption va à cette adresse
  12. goto irq_handle
  13.  
  14.  
  15. irq_handle
  16.     btfsc INTCON , TMR0IF ; si le flag d'interruption est levé (=1) goto TMR0_interrupt sinon (=0) retourne a l'adresse où il s'est arreté
  17.     goto TMR0_interrupt
  18.     retfie
  19.  
  20. TMR0_interrupt
  21.     bcf INTCON , TMR0IF ; clear le flag (=0) pour bien reset et ne pas boucler à l'infini
  22.     incf PORTC ; incrémente de 1 PORT C
  23.     retfie  ; retourne à l'adresse enregistrée lors de l'interruption
  24.  
  25. prog_init
  26.     clrf TRISC
  27.  
  28.     bsf T0CON , TMR0ON ; Active le timer 0
  29.     bsf T0CON , T08BIT ; met le timer sur 8 bits
  30.     bcf T0CON , T0CS ; utilise la clock interne
  31.     bcf T0CON , PSA ; active le préscalaire (diviseur de clock)
  32.  
  33.     bsf INTCON , GIE  ; autorise les interruptions
  34.     bsf INTCON , TMR0IE ; autorise les interuptions sur le timer
  35.     clrf TMR0 ; reset le timer, car il s'est deja incrémenter (depuis bsf T0CON , TMR0ON)
  36.  
  37.     GOTO MAIN_LOOP
  38.  
  39.  
  40. MAIN_LOOP
  41.     goto MAIN_LOOP
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement