Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic16f877a CCP1 - display values on a LCD screen

Status
Not open for further replies.

Avatar1

Newbie level 1
Joined
Feb 7, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,292
Hi Guys

Hay I’m fairly new to all this programming but have been reading some threads on here and have read the MPlab tutorial so have a basic idea on how to start my programming project. So please be patient if I ask stupid questions .

So my set up I’m using
Chip: PIC16F877A
External Clock: using 8mhz crystal
Prototyping board scrounged from college
Software: MPLab IDE

(Please ask if you require further details)

Now I have a signal from an oscillator which varies roughly from 100hz to 1500hz. I wish to use the CCP on the Pic to sample the changing frequency of the oscillator. I then wish it to display values on a LCD screen. So far i have got the following code:

Code:
	list		p=16f877a	; list directive to define processor
	#include	<p16f877a.inc>	; processor specific variable definitions
	






;***** VARIABLE DEFINITIONS (examples)

; example of using Shared Uninitialized Data Section
INT_VAR		UDATA_SHR	0x71   
w_temp		RES     1		; variable used for context saving 
status_temp	RES     1		; variable used for context saving
pclath_temp	RES	1		; variable used for context saving

; example of using Uninitialized Data Section
TEMP_VAR	UDATA	0x20		; explicit address specified is not required
temp_count	RES	1		; temporary variable (example)


; example of using Overlayed Uninitialized Data Section
; in this example both variables are assigned the same GPR location by linker
G_DATA		UDATA_OVR		; explicit address can be specified
flag		RES	2		; temporary variable (shared locations - G_DATA)

G_DATA		UDATA_OVR   
count		RES	2		; temporary variable (shared locations - G_DATA)


;**********************************************************************
RESET_VECTOR	CODE	0x000		; processor reset vector
	nop				; nop required for icd
	movlw	high  start		; load upper byte of 'start' label
	movwf	PCLATH			; initialize PCLATH
	goto	start			; go to beginning of program


INT_VECTOR	CODE	0x004		; interrupt vector location
	movwf	w_temp			; save off current W register contents
	movf	STATUS,w		; move status register into W register
	movwf	status_temp		; save off contents of STATUS register
	movf	PCLATH,w		; move pclath register into w register
	movwf	pclath_temp		; save off contents of PCLATH register

; isr code can go here or be located as a call subroutine elsewhere

	movf	pclath_temp,w		; retrieve copy of PCLATH register
	movwf	PCLATH			; restore pre-isr PCLATH register contents
	movf	status_temp,w		; retrieve copy of STATUS register
	movwf	STATUS			; restore pre-isr STATUS register contents
	swapf	w_temp,f
	swapf	w_temp,w		; restore pre-isr W register contents
	retfie				; return from interrupt


MAIN	CODE
start

		CALL	PULSE			;Record timer reading when 1st pulse arrives
		MOVF	CCPR1L,0X0		;Save timer value in mem addresses 0X0 and 0X1 when 1st pulse arrives
		MOVF	CCPR1H,0X1 		
		CALL	PULSE			;Record timer reading when second pulse arrives 
		CLRF	CCP1CON			;Disbable more captures
		MOVF	CCPR1L,0X2  	;Save timer value in mem addresses 0x2 and 0x3 when 2nd pulse arrives
		MOVF	CCPR1H,0X3		
		CALL	RESULT			;Compute periode measured in clock cycles

PULSE	BCF		PIR1,CCP1IF		;Clear timer int flag
CHECK	BTFSS	PIR1,CCP1IF		;rising edge arrived? (bit test, skip if set)
		
RESULT	MOVF	0X0,W			;lst-pulse low byte reading to W
		SUBWF	0X2,F			;subtract W from 2nd-pulse low byte reading, save in mem address 0x2
		MOVF	0X1,W			;2nd-pulse high byte reading to W
		SUBWF	0x3,1			;Subtract W from 2nd-pulse high byte reading, save in mem address 0x3
		CALL	TABLE
;************************************************************************************


Now the questions so brace your self:

Is the following code above doing as i require (sampling each rise and calculating the difference between two and storing that in the W register)?

How do i go about creating a look up table that will take the value in the w register and compare it to values in the look up thus allowing me to display the value on a LCD screen?

Thanks

Mark
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top