PIC16F84A Test Circuit


Toggle ON-OFF LED on RB1 Based on External Interrupt on RB0

by Lewis Loflin


SN74HC14 based square wave generator with differentiator circuit.
SN74HC14 based square wave generator with differentiator circuit.


The next section requires a square wave generator or source. This used the above setup one can build. See Simple Schmitt Trigger SN74HC14 Square Wave Generator

Connect either A or B to RB0 INT pin 6 on the PIC16F84A. With a frequency counter (a function on better digital volt meters) measure the input frequency. The LED will blink at half the input frequency.


;=================================================================================
;   CLOCK: External 4MHz (instruction execution time: 1usec)
;	Program name: PORTB RB0 External Interrupts.
;	Toggle ON-OFF LED on RB1 Based on External Interrupt on RB0
;	Date: 6/22/2024
;	Author: Lewis Loflin
;	LEDS connected to GRD RB1-RB3. Switch, pulse inputs RA0-RA2			
;======================================================================

	; Check assembler divice settings! 
 	list      p=16F84A      ; list directive to define processor
	#include <p16F84A.inc>  ; processor specific variable definitions
	errorlevel  -302        ; Ignore error message when storing to Bank 1.
 
  	__CONFIG        _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC 

;======================================================================

; define 

LED1 EQU 1
LED2 EQU 2
LED3 EQU 3

; Assign each register from Bank 0 RAM.
; range 0xC0-0x4F
CBLOCK  0xC0 
B0
B1
B2
temp1
temp2
CNT1
CNT2
CNT3
CNT4
ENDC ; Conclude Bank 0 RAM assignments.

;*******************************************
	ORG     0x000          
	goto    setup          
	
	ORG     0x004         
	; isr code can go here
		;	incf CNT1
	movlw 0x02
	xorwf PORTB, f
	bcf INTCON, INTF ; clear RB0/INT Flag bit
	retfie    ; return from interrupt

;********************************************
			
			
setup
      
    BSF	STATUS,RP0   ;Jump to bank 1
	; BANKSEL TRISA	
	; 1 = INPUT, 0 = OUTPUT
	MOVLW	B'00010000'		;Config Port A, RA0 to RA3 are outputs
	MOVWF	TRISA			;Set I/O configuration for PORTA
	MOVLW	B'11110001'		;Config Port B, RB1-3 OUTPUT, RB0, RB4-7 INPUT
	MOVWF	TRISB			;Set I/O configuration for PORTB
	
	; OPTION_REG bit 6 INTEDG: Interrupt Edge Select bit
	; 1 = Interrupt on rising edge of RB0/INT pin
	; 0 = Interrupt on falling edge of RB0/INT pin
	BSF OPTION_REG, 6 ; LOW to HIGH
	
	BCF	STATUS,RP0		    ;Jump back to bank 0 of PIC.
	; BANKSEL INTCON
	

	CLRF	PORTA			;Clear all I/O's of PORTA
	CLRF	PORTB
				;Clear all I/O's of PORTB
	CLRF INTCON
	BSF INTCON, 7 ; GIE  enable global INT
	BSF INTCON, 4 ; INTE RB0/INT External Interrupt Enable bit
	BCF INTCON, 1 ; INTF ; RB0/INT External Interrupt Flag bit
	; INTF must be cleared in software      

goto main

main
; do nothing
goto main
	
end

Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.