Discussion in "Project Help" started by    Ansh12    Mar 22, 2019.
Sun Apr 28 2019, 07:45 pm
#11


I made a minor change, it works in Proteus.
Try the attached hex code, just in case you have a compiler problem.

Are you sure you are getting a good signal into pin RB0 ?

if(INTF==1)
    {
         RD4 = 1;  // LED ON
         __delay_ms(1000); // 
         RD4 = 0;  // LED OFF
         __delay_ms(1000); // 
         
         INTF = 0;
    } 


ExperimenterUK



you are absolutely right. I reinstalled MPLABX IDE and my previous program is working now

Now all is working so I want to do little changes

I have one sensor when it triggered I want to start counting. How to do it ?

// 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 = ON       // Brown-out Reset Enable bit (BOR enabled)
#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)
 
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
#include 
 
volatile unsigned int Counter;
char Trigger;
 
void main(void) 
{
    
    TRISB0=1;     // encoder as input
	
    TRISB1=1;     // Sensor as input
    TRISD1= 0;    // LED as output
    OPTION_REG=1;  // Set Rising Edge Trigger 
    INTCON = 1;   // Enable The Global Interrupt
    INTE = 1;     // External Interrupt Enable (not INTF)
    GIE=1;
    Counter = 0;  //initial values at start up
    Trigger = 0;
    
    while (1)
    {
        if(Trigger == 1)
        {
             Trigger = 0;
             Counter = 0;
            
             RD1 = 1;  // LED ON
             __delay_ms(1000); // 
             RD1 = 0;  // LED OFF
             __delay_ms(500); 
        }
    }
 
}
 
void interrupt isr(void)
{  
    if(INTF==1)
    {
        INTF = 0;  // Clear interrupt flag
        Counter++;    // add 1 to the Counter
        if(Counter == 30) 
        Trigger = 1;
    } 
}




[ Edited Sun Apr 28 2019, 07:47 pm ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

EdwardFew
Mon Mar 18 2024, 01:14 pm
EmeryPah
Mon Mar 18 2024, 11:51 am
RobertMax
Sun Mar 17 2024, 10:22 pm
DanielJar
Fri Mar 15 2024, 06:52 pm
Tuzaimecor
Fri Mar 15 2024, 02:32 am
PromotionFoode
Thu Mar 14 2024, 08:11 pm
EdwardGeawn
Sun Mar 10 2024, 12:24 pm
ZacharyShado
Sat Mar 09 2024, 10:04 am