Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Timer_1 setup in PIC16F877A

Status
Not open for further replies.

jean12

Advanced Member level 2
Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
www.ntigltd.com
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:
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);


}
 }    
}
Thanks.

Please.Help
 
Last edited:

Have you saw my question?can you please hep me with codes??
I want to use a timer1 as counter for just creating a delay in which the signl from AN0 be tested with that tie?
Thanks,please help.
 

You should configure Timer1 as Timer and not Counter for creating delays. You can use a variable to count the no. of interrupts which can be used for creating delays. Post your CCS C project files. I will fix the code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top