zain kaleem
New Member
Hi
I am working on simple project. I just want to create the blinking led with variable delay. I have connected two push buttons for increment and decrement the delay value to blink the led. I am using PIC16F883 on proteus simulation and for programming MPLAB IDE. My code is not working correctly. The value for the delay is not changing.
Can anybody help me with this ?
Here is the complete code.
#include <xc.h>
#include "confi.h" // header file for configuration settings.
void delay(unsigned int x);
unsigned int speedstep=0;
void main(void) {
unsigned int x,y;
TRISC0=1;
TRISC1=1;
TRISC2=0;
PORTCbits.RC2=0;
while(1)
{
RC2=1;
delay(y);
RC2=0;
delay(y);
if (PORTCbits.RC0 == 0) //was the increment button pushed?
{
for(x=0; x<500; x++) //debounce switch
;
speedstep++; //increment speedstep variable by 1
y = speedstep;
while(PORTCbits.RC0 == 0);//show variable value on port c
}
if (PORTCbits.RC1 == 0) //was the decrement button pushed?
{
for(x=0; x<500; x++) //debounce switch
;
speedstep--; //deccrement speedstep variable by 1
y = speedstep; //show variable value on port c
while(PORTCbits.RC1 == 0);
}
}
}
void delay(unsigned int x){
for(int i=0; i!=x; i++)
{
NOP();
}
}
I am working on simple project. I just want to create the blinking led with variable delay. I have connected two push buttons for increment and decrement the delay value to blink the led. I am using PIC16F883 on proteus simulation and for programming MPLAB IDE. My code is not working correctly. The value for the delay is not changing.
Can anybody help me with this ?
Here is the complete code.
#include <xc.h>
#include "confi.h" // header file for configuration settings.
void delay(unsigned int x);
unsigned int speedstep=0;
void main(void) {
unsigned int x,y;
TRISC0=1;
TRISC1=1;
TRISC2=0;
PORTCbits.RC2=0;
while(1)
{
RC2=1;
delay(y);
RC2=0;
delay(y);
if (PORTCbits.RC0 == 0) //was the increment button pushed?
{
for(x=0; x<500; x++) //debounce switch
;
speedstep++; //increment speedstep variable by 1
y = speedstep;
while(PORTCbits.RC0 == 0);//show variable value on port c
}
if (PORTCbits.RC1 == 0) //was the decrement button pushed?
{
for(x=0; x<500; x++) //debounce switch
;
speedstep--; //deccrement speedstep variable by 1
y = speedstep; //show variable value on port c
while(PORTCbits.RC1 == 0);
}
}
}
void delay(unsigned int x){
for(int i=0; i!=x; i++)
{
NOP();
}
}