PDA

View Full Version : pulse counter 16f84a



daydream
- 1st May 2012, 14:27
hi
i have connected my pic16f84a to lcs 16*2 like this.
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
now i want to use it as a pulse counter to measure the freq of inputed pulse.
can anyone send me the pbp and asm code.pleeeeease
or can you make changes nessesry to this code and send me pbp and asm and hex code for pic16f84a.
thanks.
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5
REM Variables
TMR0_POSTCOUNT1 var WORD ' POSTSCALER COUNTERS
COUNT_RESULT var WORD ' THE RESULT OF THE COUNT
REFRESHED var BIT ' FLAG TO SAY COUNT REFRESHED
'-------------------------'
ON INTERRUPT GOTO PULSE_COUNT ' DEFINE WHERE TO JUMP TO ON AN INTERRUPT
'-------------------------'
GOTO INITIALIZE ' JUMP ALL INT CODE
'----- INTERRUPT CODE -------------------
Disable
PULSE_COUNT:
TMR0 = TMR0 + 7 ' RELOAD THE TIMER
TMR0_POSTCOUNT1 = TMR0_POSTCOUNT1 - 1
IF TMR0_POSTCOUNT1 = 0 THEN
TMR0_POSTCOUNT1 = 500 ' 1/4 sec (may need some adjust)
T1CON.0 = 0 ' TURN OFF THE TMR1
COUNT_RESULT.lowbyte = TMR1L ' GET THE COUNT
COUNT_RESULT.Highbyte = TMR1H ' GET THE COUNT
TMR1L = 0
TMR1H = 0
T1CON.0 = 1
REFRESHED = 1 ' SET FLAG TO SAY COUNT READ
ENDIF
INTCON.2 = 0 ' CLEAR INTTERUPT FLAG
Resume
enable ' RELOAD THE SYSTEM VARS
'------ END OF INTERRUPTS CODE ----------
'------ INTIALIzE ALL REGS --------------
INITIALIZE:
TMR0_POSTCOUNT1 = 500 ' INITIALZE THE POST SCALERS
OPTION_REG.0 = 0 ' SET THE PRESCALER TO 1:1
OPTION_REG.1 = 0
OPTION_REG.2 = 0
OPTION_REG.5 = 0 ' TMR0 CLOCK FROM MAIN OSC
OPTION_REG.3 = 0 ' IN THIS INSTANCE PRESCALER IS ASSINED TO TMR0
INTCON.2 = 0 ' CLEAR INTERRUPT FLAG
T1CON = %00000110
T1CON.0 = 1 ' TURN TIMER 1 ON
TMR0 = 7 ' LOAD THE TIMER
INTCON.5 = 1 ' ENABLE TMR0 INTERRUPTS
REFRESHED = 0 ' DONT MAKE FIRST READ UNTIL MAIN INT HAS OCCURED
INTCON.7 = 1 ' START THE WHOLE THING RUNNING
COUNT_RESULT = 0
pause 500
lcdout $FE,1

'------ MAIN CODE BELOW HERE -------------
LOOP:
IF REFRESHED = 1 THEN
lcdout $fe,1,$fe,2, "Freq = ", dec (COUNT_RESULT * 4) ' Show results in pulses / Sec
REFRESHED = 0 ' PREVENT A RE-READ UNTIL NEXT MAIN INTERRUPT
ENDIF
GOTO LOOP
END
by srspinho.

ScaleRobotics
- 1st May 2012, 14:59
The PIC16F84A is a very old chip. It only has one timer, timer0. This code needs two timers, timer0 and timer1.

daydream
- 1st May 2012, 15:25
what pic should i use?can anyone send me the code in asm or hex and pbp for that pic.please heeelp.

ScaleRobotics
- 1st May 2012, 16:04
How about a PIC16F628A? Do you have one of those, or a PIC16F876a?

You can compile yourself, with the 15 day trial version of PBP 3.0. And there is also an experimenter's version for $49.95 which supports these chips: 12F683, 16F688, 16F690, 16F88, 16F886

18F25K20, 18F25K22, 18F2550, 16F1937



Attached are two hex files for the above chips. Refer back to Henrik's post for which pin to use:
http://www.picbasic.co.uk/forum/showthread.php?t=550&p=112348#post112348

daydream
- 1st May 2012, 16:47
so if i use pic16f628a and put your hex code in it and give the input pulse to pin 12/T1CKI-pin the lcd will show freq?
thank you sooooooooo much.you are the best.
should LCD be connected like this?
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
if not please help me
thank you.

ScaleRobotics
- 1st May 2012, 17:30
I compiled the code as:
Define LCD_DREG PORTA
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5

default is 4 bits, unless defined, so since it is not defined, it is 4 bit bus. So Port A0, through A4 go to the D4 through D7 on the LCD. Since PortB was defined for both RSREG and EREG, RSBit is portb.4 and EBit is portb.5. If you need me to change those, let me know. But again, you can compile yourself with the 15 day free trial version.

Here is a picture of the connections. There is similar information in the PBP manual.
6450

daydream
- 1st May 2012, 18:51
thank you so much for the picture of the connections.according to picture i should connect pin 15,16 with a 4mhz crystal and pin 4 to 5volt right.after putting your hex code in pic i should use pin 12 for puls input.and lcd will show the freq.am i right?
thanks so much for your help.you are great.