psb64
Newbie level 4
I want to keep a relay off for 20hrs and keep it on for 14 hrs using a micro-controller. Please help me by giving the necessary program (in mikroBasic/Assembly) and schematic diagram to do so.
Last edited:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I want to keep a relay off for 20hrs and keep it on for 14 hrs using a micro-controller. Please help me by giving the necessary program (in mikroBasic/Assembly) and schematic diagram to do so.
I want to use the PIC16F84A to do this and the cristal should be 4Mhz
---------- Post added at 21:47 ---------- Previous post was at 21:36 ----------
I found the following circuit in mikroBasic. Will it work?
program timer84EDA
symbol relay = PORTB.B0
const ontime = 43200000
const offtime = 75600000
main:
TRISB = 0
PORTB = 0
relay = 0 'relay off
delay_ms(offtime) 'twenty-one hour delay
relay = 1 'relay on
delay_ms(ontime) 'twelve hour delay
relay = 0 'relay off
while true 'done
wend
end.
program timer84EDA
symbol relay = PORTB.B0
const ontime = 43200000
const offtime = 75600000
main:
TRISB = 0
PORTB = 0
while true 'done
relay = 0 'relay off
delay_ms(offtime) 'twenty-one hour delay
relay = 1 'relay on
delay_ms(ontime) 'twelve hour delay
wend
end.
const ontime = 43200000
const offtime = 75600000
delay_ms(offtime) 'twenty-one hour delay
If you are using a 4MHz crystal....
The operating frequency will be 4MHz/4 = 1MHz (4 machine cycle constitute 1 instruction cycle)
ie, it will execute 1,000,000 instructions in 1 second.
so to get a 1 second, you have to use a for loops which will consume 1,000,000.
for a minute 60 times the 1second loop
for hour, 60times the 1minute loop..
from this you will get the exact timing...