Counting Number of Occurrences
    
    This PIC Microcontroller project is used to count the occurrence of a given number from a set of numbers stored in the 
        Instrumental Model - Parallel Pattern with Interrupt. To simulate this circuit, initially activate Mixed Mode simulator from the Schematic Editor window. Simulation can be performed by selecting Run Transient analysis (Oscillograph) from Simulation menu.
 
    The circuit contains a PIC Microcontroller, 
        Parallel Pattern with Interrupt, Binary to 7 Segment Decoder/Driver, 
        Seven Segment LED Display.
    PortA and PortB is set as Input Port.PortC is first set as Input Port and after reading the number to be checked, it is changed to Output Port. Whenever the interrupt signal goes low, PortB starts reading the data from the Parallel Pattern model. The count showing the occurrence of the given number after all the comparisons will be available in PortC and it will be displayed through the Seven Segment Display.
    The source code written in Assembly language can be viewed from the 
        code editor window 
    The program is as shown:
    
    include "p16c5x.inc"
    
    TEMP_VAR UDATA
    c_data   RES 1
    count   RES 1
    
    startup  code
    start   movlw  0xff   ;moving literal constant 0xff to W
     tris  PORTA   ;setting PORTA in input mode
     tris  PORTB  ;setting PORTB in input mode
    tris  PORTC  ;setting PORTC in input mode
     movf  PORTC,1  ;reading through PORTC
    movf  PORTC,0  ;moving the read value to W
    movwf  c_data  ;moving the value to c_data
     movlw  0x00 ;moving literal constant 0x00 to W
      tris  PORTC  ;setting PORTC in output mode
    bchk  btfsc  PORTA,3  ;checking whether RA3 pin is clear or not
     goto  bchk  ;if not
    d_read  bcf  PORTA,3  ;if yes, blocks further read
      movf PORTB,1  ;reading through PORTB
      movf  PORTB,0  ;moving the read value to W
    xorwf  c_data,0  ;xoring the data with the value stored in c_data
      btfsc  STATUS,2  ;checking whether zero flag is clear or not
       incf  count,1  ;if not
     movf  count,0  ;if yes, the value stored in count is moved to W
      movwf  PORTC   ;outting the value through PORTC
      bsf  PORTA,3  RTA,3  ;setting the RA3 pin HIGH
     goto  bchk  ;again goes to bchk
      goto  start   ;repeat
      end
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    The source code in the 
  code editor window
   has to be  
 compiled
 after making any modifications 
  (editing). 
Also the code can be 
  debugged
 during
   simulation.