how to count external pulse using Pic16f877A

Status
Not open for further replies.
I didn't test it but if you hooked some led up on Portb use all pins with resistors sinking to gnd and what you want to test on Porta 0 it should out put the count to portb in binary.If your pulse never stops the leds will not light because I didn't put a delay in it.
Code:
	 list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF 
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


		cblock	0x20			;start of general purpose registers
		count			;used in looping routines

		endc



;**********************************************************************
	ORG     0x000             ; processor reset vector

	nop			  ; nop required for icd
  	goto    main              ; go to beginning of program


	ORG     0x004             ; interrupt vector location





main:

		BANKSEL ADCON1			;disable analogue inputs
		movlw 	0x06
		movwf 	ADCON1
		BANKSEL PORTA
		banksel TRISA
		movlw	b'00000001'		;Set port data directions, data output
		movwf	TRISA
		banksel TRISB
		movlw	b'00000000'
		movwf	TRISB
		banksel PORTB
		clrf	PORTB

loop
        btfsc   PORTA,0        ; if input gos high
	incf	PORTB,f			; count it out to leds on PORTB 
        goto    loop            ; repeat forever

		
	END                       ; directive 'end of program'
 
Last edited:
My clock at
**broken link removed**
counts the pulses using the rb0 interrupt, you can download the code ( boostc )
 
My clock at
**broken link removed**
counts the pulses using the rb0 interrupt, you can download the code ( boostc )

Hi Russ,
Thought I'd have a look at this; there are no source files in the zip file for this projects... perhaps you forgot to update your download?

contents of DClock_v1.zip:
ClockFace.png
MotorMount1.png
PICClock.wmv
PowerSupplyBoardBrd.png
PowerSupplyBoardSch.png
ProcessorBoardBrd.png
ProcessorBoardSch.png
WClockNoPS.sch
WClockNoPS_2.brd
WClockPS.brd
WClockPS.sch
 
I changed the code I posted It will count out to leds on portb It works I tried it for fun
 



My bad: I will fix it and change the text for the download. -- done
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…