Interrupt service routine handler- programmable Integrated circuit

 

When trigger switch connected to int/RB0 that will start counting 0 to 10 we can get out put from RA0 toRA3 as 0000 to 1010 use with pic = 16F84

org 0x00                     ;This is where we come on power up and reset

;*******************SETUP CONSTANTS*******************
INTCON         EQU 0x0B       ;Interrupt Control Register

PORTB           EQU 0x06       ;Port B register address

PORTA          EQU 0x05       ;Port A register address

TRISA         EQU 0x85       ;TrisA register address

TRISB            EQU 0x86       ;TrisB register address

STATUS          EQU 0X03      ;Status register address

COUNT          EQU 0x0c         ;This will be our counting variable

TEMP              EQU 0x0d      ;Temporary store for w register

  goto    main                              ;Jump over the interrupt address

;***************INTERRUPT ROUTINE***************

  org                  0x04                ;This is where PC points on an interrupt

  movwf TEMP              ;Store the value of w temporarily

incf                  COUNT,1       ;Increment COUNT by 1, and put the result

;back into COUNT

movlw 0x0A               ;Move the value 10 into w

subwf              COUNT,0       ;Subtract w from COUNT, and put the

;result in w

btfss                STATUS,0       ;Check the Carry flag. It will be set if

                                                ;COUNT is equal to, or is greater than w,

                                                ;and will be set as a result of the subwf

                                                ;instruction

goto                carry_on           ;If COUNT is <10, then we can carry on

goto                clear                 ;If COUNT is >9, then we need to clear it

carry_on

bcf                  INTCON,0x01 ;We need to clear this flag to enable

  ;more interrupts

movfw TEMP              ;Restore w to the value before the interrupt

  retfie                                      ;Come out of the interrupt routine

clear

clrf                  COUNT          ;Set COUNT back to 0

bcf                  INTCON,1      ;We need to clear this flag to enable

                                                ;more interrupts

retfie                              ;Come out of the interrupt routine

;*******************Main Program*********************

main

;*******************Set Up The Interrupt Registers****

bsf                   INTCON,7      ;GIE – Global interrupt enable (1=enable)

bsf                   INTCON,4      ;INTE - RB0 Interrupt Enable (1=enable)

bcf                  INTCON,1      ;INTF - Clear FLag Bit Just In Case

;*******************Set Up The Ports******************

  bsf                STATUS,5     ;Switch to Bank 1

movlw 0x01           

movwf TRISB              ;Set RB0 as input

movlw 0x10                       

movwf TRISA              ;Set R 0 to RA3 on PortA as output

  bcf                  STATUS,5  ;Come back to Bank 0

;*******************Now Send The Value Of COUNT To Port A           

loop

movf                 COUNT,0       ;Move the contents of Count into W

movwf              PORTA           ;Now move it to Port A

goto                 loop                 ;Keep on doing this

end                                           ;End Of Program

 

image

if you need more details go to http://www.mstracey.btinternet.co.uk

There many more things about pic and interrupt service routine .This works for me with Mplab ide and proteous 7 environment

Nuwan added this:

1. You use RC OSC and no capacitor. (R1 and OSC1) This is ok with some pic's but, some are fail. You use distributed capacitance of Rosc pin and it is better to connect 20pF cap to ground.


2. RB0 ,Int 0 RC low pass filter R2 value is too large. Use between 2K ~ 10K value.

1 comment:

  1. Dear, There are 2 issues in this Diagram.

    1. You use RC OSC and no capacitor. (R1 and OSC1) This is ok with some pic's but, some are fail. You use distributed capacitance of Rosc pin and it is better to connect 20pF cap to ground.

    2. RB0 ,Int 0 RC low pass filter R2 value is too large. Use between 2K ~ 10K value.... Read More

    That's all. :-)

    ReplyDelete

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...