sacban
Junior Member level 3
Hi There,
I have a problem with my code, could please see on below :
Sacban.
- - - Updated - - -
My problem are :
As you see here :
LED0 = 0; // I add these LED0 And LED1, mean are Q1 && Q2 have a voltage LED2 is ON and LED0 and LED1 become off
LED1 = 0; // but it doesn't work, it only blinking
LED2 = 1; // LED1 is on
When Q1 and Q2 have a voltage, I wish to turn OFF 2 LED, are LED0 and LED1 and Turn ON LED2, but onto my code, both LED (0 and 1) only blinking or On can't be OFF.
Also
BLINK is PORTE0, this Led can't blink for xx second then turn off, this LED (BLINK) always blinking and doesn't stop or can blinking everytime, I wish this BLINK will blinking every time Q1 have a voltage then if Q1 don't have a voltage reference he should off for LED (BLINK).
Sacban.
I have a problem with my code, could please see on below :
Code:
unsigned int adc_val, adc_val1, adc_val2, adc_val3;
unsigned long Q1, Q2, Q3, Q4; // These are gate PORTA0 - PORTA3
sbit LED0 at PORTD.B0;
sbit LED1 at PORTD.B1;
sbit LED2 at PORTD.B2;
sbit LED3 at PORTD.B3;
sbit BLINK at PORTE.B0; // I hope this will BLINK every voltage is on, but still not get the result
void main() {
ADCON1 = 0x0F; // configure Vref, and analog channels 0x88
TRISA = 0x0F; // designate PORTA as input 0xFF
TRISB = 0x00;
TRISC = 0x00; // PORTC all output to LED
TRISD = 0x00; // PORTD all output to LED
TRISE = 0x00;
PORTA = 0x30;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
Delay_ms(100);
for (;;) {
adc_val = ADC_read(0); // get ADC value for U from channel 0
Q1 = (long)adc_val*5000/1023; // Convert ADC value to millivolts
adc_val1 = ADC_read(1); // get ADC value for U from channel 1
Q2 = (long)adc_val1*5000/1023; // Convert ADC value to millivolts
adc_val2 = ADC_read(2); // get ADC value for U from channel 2
Q3 = (long)adc_val2*5000/1023; // Convert ADC value to millivolts
adc_val3 = ADC_read(3); // get ADC value for U from channel 3
Q4 = (long)adc_val3*5000/1023; // Convert ADC value to millivolts
// This an input voltage at PORTA0
if (Q1 > 200 && Q1 <= 5000) {
// BLINK = 1; ===> I adding this LED On PORTE to make it BLINK, but it doesn't work only led on or always blinking
// I wish to BLINK 1 times when have a voltage input
LED0 = 1;
Delay_ms(8);
}
else
if (Q1 == 0) {
{
LED0 = 0;
}
} // END BUTTON # 1
//===============================================
if (Q2 > 200 && Q2 <= 5000) {
LED1 = 1;
Delay_ms(8);
}
else
if (Q2 == 0) {
{
LED1 = 0;
}
} // BUTTON # 2
/***************************************************************************************/
/** MY PROBLEM HERE, PLEASE SEE ON BELOW NOTE *****************************************/
//===============================================
if (Q1 > 200 && Q1 <= 5000 && Q2 > 200 && Q2 <= 5000) { // If Q1 and Q2 have a voltage then
// if (Q2 > 200 && Q2 <= 5000 ) {
Delay_ms(100); // Wait
LED0 = 0; // I add these LED0 And LED1, mean are Q1 && Q2 have a voltage LED2 is ON and LED0 and LED1 become off
LED1 = 0; // but it doesn't work, it only blinking
LED2 = 1; // LED1 is on
Delay_ms(50); // 5 second
}
else
if (Q1 == 0 || Q2 == 0) // If PORTA0 & PORTA1 have 0 Voltage then
{
LED2 = 0; // LED2 should turn Off
}
}
//===============================================
/********* I AM WAITING TO SOLVED ABOVE CODE THEN WILL CONTINUE TO ANOTHER CODE ************/
if (Q4 > 200 && Q4 <= 5000) {
LED3 = 1;
Delay_ms(8);
}
else
if (Q4 == 0) {
{
LED3 = 0;
}
}
while (1);
// Voltage reference up then xx voltage
(Q1 > 4700 && Q1 <= 5000);
(Q2 > 4700 && Q2 <= 5000);
(Q3 > 4700 && Q3 <= 5000);
(Q4 > 4700 && Q4 <= 5000);
}
Sacban.
- - - Updated - - -
My problem are :
/***************************************************************************************/
/** MY PROBLEM HERE, PLEASE SEE ON BELOW NOTE *****************************************/
//===============================================
if (Q1 > 200 && Q1 <= 5000 && Q2 > 200 && Q2 <= 5000) { // If Q1 and Q2 have a voltage then
Delay_ms(100); // Wait
LED0 = 0; // I add these LED0 And LED1, mean are Q1 && Q2 have a voltage LED2 is ON and LED0 and LED1 become off
LED1 = 0; // but it doesn't work, it only blinking
LED2 = 1; // LED1 is on
Delay_ms(50); // 5 second
}
else
if (Q1 == 0 || Q2 == 0) // If PORTA0 & PORTA1 have 0 Voltage then
{
LED2 = 0; // LED2 should turn Off
}
}
As you see here :
LED0 = 0; // I add these LED0 And LED1, mean are Q1 && Q2 have a voltage LED2 is ON and LED0 and LED1 become off
LED1 = 0; // but it doesn't work, it only blinking
LED2 = 1; // LED1 is on
When Q1 and Q2 have a voltage, I wish to turn OFF 2 LED, are LED0 and LED1 and Turn ON LED2, but onto my code, both LED (0 and 1) only blinking or On can't be OFF.
Also
if (Q1 > 200 && Q1 <= 5000) {
// BLINK = 1; ===> I adding this LED On PORTE to make it BLINK, but it doesn't work only led on or always blinking
// I wish to BLINK 1 times when have a voltage input
LED0 = 1;
Delay_ms(8);
}
else
if (Q1 == 0) {
{
LED0 = 0;
}
} // END BUTTON # 1
BLINK is PORTE0, this Led can't blink for xx second then turn off, this LED (BLINK) always blinking and doesn't stop or can blinking everytime, I wish this BLINK will blinking every time Q1 have a voltage then if Q1 don't have a voltage reference he should off for LED (BLINK).
Sacban.