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.

How to start counter when sensor is activate

Status
Not open for further replies.
Yes led blinking one time with internal clock

This is the good point to rectify the issue
Learn by doing it

Can you imagine why it is blinking one time
Can you modify the code with internal clock to blink continuously
 

This is the good point to rectify the issue
Learn by doing it

Can you imagine why it is blinking one time

I don't know but if I use external clock or internal LED is blinking only one time
 

Code:
// PIC16F877A Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ

/*
 * 
 */
void main(void) 
{
    PORTD = 0b00000000;
    
    TRISC0 = 1;    //PORTC R0  pins are used as Input encoder
    TRISD4 = 0;    //PORTD R4  pins are used as output.LED
    TRISB1 = 1;    //PORTC R0  pins are used as Input. sensor
   
    
     //Loading starting value of counter 65486
    TMR1H = 0xFF ;    // High byte FF
    TMR1L = 0xF6 ;    // Low Byte F6
    
    //Set T1CON Register 
    
    TMR1ON  = 0; // Stops Timer1
    TMR1CS =  0; // Oscillator is enabled
    T1SYNC =  0; // Synchronize external clock input
    T1OSCEN = 0; // Oscillator is shut-off
    T1CKPS0 = 0; // 1:8 prescale value
    T1CKPS1 = 0;
    
    TMR1IF = 0 ;  // Clear interrupt flag
    
    TMR1ON = 1; //Start Timer1
       
    while(1)
    {
       if(TMR1IF ==1)
      { 

         RD4 = 1;  // LED ON
          
         __delay_ms(500); // 
          RD4 = 0;  // LED OFF
         
            __delay_ms(500); // 
         
          TMR1IF=0; // Clear timer interrupt flag
          
        //TMR1ON = 0; //Stop Timer1
          
          //reload counter
          TMR1H = 0xFF ;    // High byte FF
          TMR1L = 0xF6 ;    // Low Byte F6
      }  
    } 
}

let me know the result since I should not have testing board
it should blink continuously

Code:
<xc.h> while(1)
    {

       TMR1ON = 1; // Start Timer
       if(TMR1IF ==1)
      { 

         
         
          TMR1IF=0; // Clear timer interrupt flag
          
          TMR1ON = 0; //Stop Timer1


          //Load Register 
          
      }  
    } </xc.h>
</stdlib.h></stdio.h></xc.h>
 
Last edited:
Code:
// PIC16F877A Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ

/*
 * 
 */
void main(void) 
{
    PORTD = 0b00000000;
    
    TRISC0 = 1;    //PORTC R0  pins are used as Input encoder
    TRISD4 = 0;    //PORTD R4  pins are used as output.LED
    TRISB1 = 1;    //PORTC R0  pins are used as Input. sensor
   
    
     //Loading starting value of counter 65486
    TMR1H = 0xFF ;    // High byte FF
    TMR1L = 0xF6 ;    // Low Byte F6
    
    //Set T1CON Register 
    
    TMR1ON  = 0; // Stops Timer1
    TMR1CS =  0; // Oscillator is enabled
    T1SYNC =  0; // Synchronize external clock input
    T1OSCEN = 0; // Oscillator is shut-off
    T1CKPS0 = 0; // 1:8 prescale value
    T1CKPS1 = 0;
    
    TMR1IF = 0 ;  // Clear interrupt flag
    
    TMR1ON = 1; //Start Timer1
       
    while(1)
    {
       if(TMR1IF ==1)
      { 

         RD4 = 1;  // LED ON
          
         __delay_ms(500); // 
          RD4 = 0;  // LED OFF
         
            __delay_ms(500); // 
         
          TMR1IF=0; // Clear timer interrupt flag
          
        //TMR1ON = 0; //Stop Timer1
          
          //reload counter
          TMR1H = 0xFF ;    // High byte FF
          TMR1L = 0xF6 ;    // Low Byte F6
      }  
    } 
}

let me know the result since I should not have testing board
it should blink continuously </stdlib.h></stdio.h></xc.h>
I am at outside so would take some time to test code but I am sure 100% it would be work

Can you add sensor triggred code
 

What is this project ?
Is it wall follower robot (Micromouse )
 

let me know the result since I should not have testing board
it should blink continuously
Yes LED is blinking continousely but problem is, it's blinking while there is no input on RC0. and I want to incremet counter if there is pulses on RC0
 

Where the codes that you tested last
 

The OP has another thread covering the same subject.
This one will be closed.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top