jean12
Advanced Member level 2
- Joined
- Aug 27, 2013
- Messages
- 529
- Helped
- 5
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 18
- Activity points
- 5,497
Hello there I would like to setup timer1 of PIC16F877A for creating a delay of 3 seconds,I understand that it has to be configured as counter
but I don't know any thing more on it ;can anyone help me??
So I have to edit the following codes for making an ON/OFF switch:
Thanks.
Please.Help
but I don't know any thing more on it ;can anyone help me??
So I have to edit the following codes for making an ON/OFF switch:
PHP:
#include "16f877a.h"
#device adc=10
#fuses HS,NOWDT,NOLVP,NOCPD,NODEBUG
#use delay(clock=4M)
float volt, oldval,volt1 ;
int count=0
#int_timer2
void timer2_isr(void)
{
//clock=clock++;
x=get_timer2();
set_timer2(0);
}
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00);
//Analog module configuration for reading the voltage from the PIN_AN0
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_vref(FALSE);
//Interrupt uses for counting 3 seconds
setup_timer_2(T0_INTERNAL | T0_DIV_BY_8);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while(1)
{
delay_us(20);
read_adc(adc_start_only);
delay_us(100);
volt = read_adc(adc_read_only);
volt = volt * 30.0/ 1023.0;
if(volt>1)
{
delay_ms(3);
output_high(PIN_D0);
}
else if((x<=125)&&(volt>1) //turn off the led on D1
{
output_high(PIN_D0);
}
}
}
Please.Help
Last edited: