Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
I want to make liquid tank level control using pic 16F877A and ultrasonic to transmit and recieve signal so i need to activat timer0 or timer 1 and using a value of timer in equation
This is code for a PIC18F452 but the 16F877A is similar. I had to put dots in there to try and format the code for readability. There's probably a better way to format the code in this post but I don't know how to do that yet:
Delay .......................... ; wait for TIMER1 overflow, 50/sec (20mSec) @ 12.288 MHz
;
; CLRWDT ............................ ; kick the dog (if you're using the watchdog timer)
movwf temp2 .................... ; save W
bcf TMR1ON,0 .................... ; stop TIMER1
clrf TMR1L
movlw 0x10 ....................... ; was $10
movwf TMR1H .................... ; seed TIMER1 to $1000 to start for 20 msec delay
bsf TMR1ON,0 .................... ; start TIMER1
bcf PIR1,TMR1IF ................. ; clear overflow flag for test
delaylp btfss PIR1,TMR1IF . ; did TIMER1 overflow occur?
goto delaylp ...................... ; no, continue polling
bcf PIR1,TMR1IF ................. ; yes, clear flag and return to caller
decf timecode,F ................. ; decrement timeout counter and check for zero (timeout)
btfsc STATUS,Z .................. ; check for zero value (timeout)
bsf timeout ....................... ; timeout occurred, set flag and reset
incf ticks,F ......................... ; increment tick counter
movf ticks,W
xorlw 0x32 ........................ ; see if 50 ticks have passed
btfss STATUS,Z
goto $+3
incf seconds,F ................... ; increment seconds timer
clrf ticks ............................ ; reset tick counter
movf temp2,W .................. ; restore W
return
This code is pretty well documented but you'll probably need to read the relevant sections of the PIC16F877A datasheet in order to understand what's going on. Hope this helps.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.