hello,
i need help with the code i wrote below for a turn signal/brake signal flasher module. i use PIC 16F1503. Currently, when left is pressed, light leds come on flashing,m when right is pressed, right leds come on and when brake is pressed all leds turn on. but when left/brake and right/brake is pressed, the leds act weird. whats happening is when left/brake is pressed, the Brake portion of leds stay solid while the left leds are bliking very subtly-can hardly see them and blinking fast. its although two signals are working at the same time-one asking it to blink, another asking it to turn off.... sometimes ALL THE LIGHTS stay solid, no blinking.... same with right/brake..any input is appreciated.
#include <xc.h>
void main(void)
{
ANSELC = 0; //analog select register takes analog input only by default. making the bits 0 connects it to digital/port registers. See page 103 of datasheet.
TRISC = 0b00000111; // set port C-RC0 (left sw in),RC1 (right sw in),RC2 (brake sw in) as inputs and RC3 (right led out), RC4 (left led out)
OSCCON = 0b01100000; //Oscillator set to 2MHZ
OPTION_REG = 0b00000111; //prescalar 256
int counter1;
int CountLimit = 3;
TMR0IF = 0;
while(1)
{
if (INTCONbits.TMR0IF == 1) //check to see if timer rolled over
{
counter1++; //increment counter
INTCONbits.TMR0IF = 0; // clear timer 0 flag
if (counter1 >= CountLimit) //counts 1- timer roll-overs
{
//ALL OFF
if (PORTC == 0)
{
PORTCbits.RC3 = 0;
PORTCbits.RC4 = 0;
}
//LEFT TURN SIGNAL
if (PORTCbits.RC0 == 1)
{
PORTCbits.RC3 = 0;
counter1 = 0; //reset counter
if (PORTCbits.RC4 == 1) // if LED is on
{
PORTCbits.RC4 = 0; // turn LED off
}
else
{
PORTCbits.RC4 = 1; // otherwise turn it on
}}
else
{
PORTCbits.RC4 = 0; // This will set C4 low if the input C0 is not high
}
//RIGHT TURN SIGNAL
if (PORTCbits.RC1 == 1) //check to see if there is input voltage at RC0
{
PORTCbits.RC4 = 0;
counter1 = 0; //reset counter
if (PORTCbits.RC3 == 1) // if LED is on
{
PORTCbits.RC3 = 0; // turn LED off
}
else
{
PORTCbits.RC3 = 1; // otherwise turn it on
}
}
else
{
PORTCbits.RC3 = 0; // This will set C3 low if the input C0 is not high
}
//LEFT TURN & BRAKE SIGNAL
if (PORTCbits.RC0 == 1 & PORTCbits.RC2 == 1) //check to see if there is input voltage at RC0
{
PORTCbits.RC3 = 1;
counter1 = 0; //reset counter
if (PORTCbits.RC4 == 1) // if LED is on
{
PORTCbits.RC4 = 0; // turn LED off
}
else
{
PORTCbits.RC4 = 1; // otherwise turn it on
}
}
//RIGHT TURN & BRAKE SIGNAL
if (PORTCbits.RC1 == 1 & PORTCbits.RC2 == 1) //check to see if there is input voltage at RC0
{
PORTCbits.RC4 = 1;
counter1 = 0;
if (PORTCbits.RC3 == 1) // if LED is on
{
PORTCbits.RC3 = 0; // turn LED off
}
else
{
PORTCbits.RC3 = 1; // otherwise turn it on
}
}
//BRAKE SIGNAL
if (PORTCbits.RC2 == 1 & PORTCbits.RC0 == 0) //check to see if there is input voltage at RC2
{
if (PORTCbits.RC2 == 1 & PORTCbits.RC1 == 0)
{
PORTCbits.RC3 = 1; // otherwise turn RIGHT LED on
PORTCbits.RC4 = 1; // otherwise turn LEFT LED on
} }
}}}}
