hi sujeetha. the best approach will be to use the timers in the 89C51 as a counter. for example u can make use of two timers for this purpose. the first timer should act as a gating device to the second timer just like the conventional frequency counter. it can be made to enable the second timer at an interval of say one second. while the second timer which will be configured as a counter is enabled, it will count the number of pulses present on its pin, when disabled via the first timer which is a free runing gater, the number of counts that it has made will be copied to a register which will act as a buffer for further processing....hope this helps
sequel...
yes because the MCU will still of two machine cycle...which is 11.0592MHz/24
You want to measure heartbeat pulses, (e.g=70-80) but in second??? Not in minute????
hi sujeetha. the best approach will be to use the timers in the 89C51 as a counter. for example u can make use of two timers for this purpose. the first timer should act as a gating device to the second timer just like the conventional frequency counter. it can be made to enable the second timer at an interval of say one second. while the second timer which will be configured as a counter is enabled, it will count the number of pulses present on its pin, when disabled via the first timer which is a free runing gater, the number of counts that it has made will be copied to a register which will act as a buffer for further processing....hope this helps
sequel...
i dont think am getting you clear.....is it that the interrupt will be used to initiate the count?... or the count can be made regardless of the interrupt?
....please clearify
ok check out this quick code. here i used timer0 and timer2....the ext0 should be tied to timer0 so that the falling edge of the pulse will trigger an interrupt and also form the basis for counting....feel free to ask your questions...sequel
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RUNS @ 12MHZ
; TARGET CHIP 89S52 OR 89C52
; BY VINCENT "SEQUEL"
; DATE 19-11-2012
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
T2CON DATA 0C8H
RCAP2L DATA 0CAH
RCAP2H DATA 0CBH
;;;;;;;;;;;;;;;;;;;;;;;;;
OUTPUT DATA 080H ; PORT0 SERVES AS THE OUTPUT FOR SEVEN SEGMENT DISPLAY A-G
SCAN DATA 0A0H ;
SEG_1 BIT SCAN.0 ; USED FOR MUX LSB
SEG_2 BIT SCAN.3 ; USED FOR MUX
SEG_3 BIT SCAN.6 ; USED FOR MUX MSB
COUNTER DATA 000H
COUNTER2 DATA 001H
STORE_1 DATA 002H
STORE_2 DATA 003H
STORE_3 DATA 004H
DELAY_REG DATA 005H
DELAY_REG1 DATA 006H
DELAY_REG2 DATA 007H
RESTORE DATA 008H
SAMPLER DATA 009H
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF VARIABLE DECLARATION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORG 000H
AJMP BOOTSTRAP
ORG 003H
AJMP GET_PULSES
ORG 02BH
AJMP SAMPLE
ORG 02FH
BOOTSTRAP:
MOV SP,#020H
MOV OUTPUT,#000
MOV COUNTER,#000
MOV COUNTER2,#000
MOV STORE_1,#000
MOV STORE_2,#000
MOV STORE_3,#000
MOV SCAN,#000
MOV RCAP2L,#0F0H ; THE RCAP2 IS A 16BIT REGISTER AND IT IS CONFIGURED IN AUTORELOAD MODE BY LOADING IT WITH THE VALUE OF 55536
MOV RCAP2H,#0D8H ; THIS MEANS THAT IT WILL COUNT UPWARDS TO 65535...THAT IS TO SAY AN EXTRA 10000
; THUS IT WILL DIVIDE THE SYSTEM FREQUENCY DOWN TO 100HZ...THAT IS 12MH/12 = 1000000
; 1000000/10000 = 100
MOV SAMPLER,#100 ; THIS REGISTER IS FURTHER USED TO BRING THE 100HZ DOWN TO A SECOND
MOV TMOD,#005H ; CONFIGURE TIMER0 FOR COUNTER MODE
MOV IE,#10100001B ; INTERRUPT VECTORS FOR EXT0 AND FOR TIMER2 OVERFLOW
AJMP MAIN
MAIN: MOV A,STORE_1
ACALL DISP_MASK
MOV OUTPUT,A
SETB SEG_1
ACALL DELAY_150_12
CLR SEG_1
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_2
ACALL DISP_MASK
MOV OUTPUT,A
SETB SEG_2
ACALL DELAY_150_12
CLR SEG_2
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_3
ACALL DISP_MASK
MOV OUTPUT,A
SETB SEG_3
ACALL DELAY_150_12
CLR SEG_3
AJMP MAIN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DISP_MASKLAY MASK SUBROUTINE FOR COMMON ANODE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DISP_MASK: INC A
MOVC A,@A+PC
RET ; SWAP WITH THESE FOR COMMON CATHODE
DB 03FH ; Digit 0 mask 0C0H
DB 006H ; Digit 1 mask 0F9H
DB 05BH ; Digit 2 mask 0A4H
DB 04FH ; Digit 3 mask 0B0H
DB 066H ; Digit 4 mask 099H
DB 06DH ; Digit 5 mask 092H
DB 07DH ; Digit 6 mask 082H
DB 007H ; Digit 7 mask 0F8H
DB 07FH ; Digit 8 mask 080H
DB 06FH ; Digit 9 mask 090H
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;START PULSE COUNTING;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GET_PULSES: MOV IE,#10100000B ; DISABLE EXT0 INT.
MOV T2CON,#004
SETB TR0
RETI
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAMPLE SUBROUTINE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SAMPLE: MOV T2CON,#004
DJNZ SAMPLER,RETII
CLR TR0
MOV T2CON,#000
MOV SAMPLER,#100
MOV COUNTER,TL0
MOV COUNTER2,TH0
MOV TL0,#000
MOV TH0,#000
MOV A,COUNTER ; YOUR COUNT IS COPIED TO THIS REGISTER "LOW BYTE" THATS 8BIT...YOU CAN USE THE TH0 FOR THE HIGH BYTE. THUS GIVING U 16BIT
BINARY_2BCD: MOV B,#010 ; THIS ROUTINE CONVERTS YOUR BINARY DATA TO DECIMAL
DIV AB
MOV STORE_1,B
MOV B,#010
DIV AB
MOV STORE_2,B
MOV STORE_3,A
MOV IE,#10100001B ; ENAABLE EXT0 INT....NOTE THAT YOU CAN INTRODUCE A DELAY HERE INCASE YOUR DISPLAY FLICKERS
RETII: RETI
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DELAY SUBROUTINE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY_150_12: MOV DELAY_REG1,#14
MOV DELAY_REG2,#168
_150_12: DJNZ DELAY_REG2,_150_12
DJNZ DELAY_REG1,_150_12
RET
END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?