Hello,
I was wondering if someone can help me,to set timer0 for my program.
The situation is following:
GP1 input,all others output.
Logic 0 on GP1 starts the 2 seconds timer.
If in in those two seconds Logic 0 appears once more on GP1,then do first event.If not do second event.
So here is a code I have written.
It always triggers the first event,I can't get it to work properly.
Kind regards,
Sima
I was wondering if someone can help me,to set timer0 for my program.
The situation is following:
GP1 input,all others output.
Logic 0 on GP1 starts the 2 seconds timer.
If in in those two seconds Logic 0 appears once more on GP1,then do first event.If not do second event.
So here is a code I have written.
Rich (BB code):
#include<12F629.h>
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
#fuses NOMCLR,NOWDT,NOPROTECT,INTRC
#use delay(clock=4000000)
#use fast_io(a)
#define LED GP0
#define Trigger GP1
#define MAXRT 1000
void main()
{
unsigned int8 cnt_8ms;
setup_timer_0(RTCC_Internal|RTCC_Div_32);
set_tris_a(0b00000010);
while(TRUE)
{
output_a(0);
cnt_8ms = 0;
if(input(Trigger) == 0)
{
while(input(Trigger) == 1 && cnt_8ms < 2000/8)
{
set_timer0(0);
while(get_timer0() < 8000/32)
++cnt_8ms;
}
if(cnt_8ms < MAXRT/8) //first event
{
output_high(LED);
delay_ms(1000);
output_low(LED);
delay_ms(1000);
output_high(LED);
delay_ms(1000);
output_low(LED);
}
if(cnt_8ms > MAXRT/8) //second event
{
output_high(LED);
delay_ms(2000);
output_low(LED);
}
delay_ms(1000);
}
}
Kind regards,
Sima
Last edited by a moderator: