1. Originally Posted by quzah
edit - Or I am missing something in your translation here. 20/10 is always 2, and 20%10 is always 0, and 0/1 is also always 0.
No, even in the land of microntrollers, mod is mod and divide is divide. I just think the code we're seeing is a simplified version of a future, more complex, version.

[EDIT]

...and our OPs grasp of what he or she is doing is not particularly strong.

2. Originally Posted by bivhitscar
No, even in the land of microntrollers, mod is mod and divide is divide. I just think the code we're seeing is a simplified version of a future, more complex, version.
Yeah, I know the math is right, I wasn't sure what he was trying to say. I didn't know if he was saying he was assigning the results of the expression, or if he thought he was actually placing "(20/10)" into the variable (similar to how a macro works).

In any case, what is really happening is as I described:
Code:
```x = 2;
y = z = 0;```
Originally Posted by bivhitscar
...and our OPs grasp of what he or she is doing is not particularly strong.
Agreed.

Quzah.

3. I am doing Water level sensor . Current function of the code is that the LED will turn on when 10cm the alert mode is active, and the both LED will turn on when 20cm the warning mode is active, the last emergency mode will active when the water level reached 30cm, the buzzer will turn on, and the 7 segment will display 30cm.

Above i have wrote one part of my coding. I want to display 3 different values in my 7 segment. When the water level reaches 10cm which is the alert(A) the 7 segment also need to show 10,when the water level reaches 20cm which is the warning(W) the 7 segment also need to show 20 and when the water level reaches 30cm which is the emergency(E)the 7 segment also need to show 30. But right now with the below code it can only shows the emergency level(E) where the water level reaches 30cm the 7 segment show 30 but cannot display for other 2 levels.

I want the code to programme like when the water level reaches 10cm the LED will turn on and the 7 segment must show 10, when the water level reaches 20cm the both LED turn on and the 7 segment must show 20 and when the water level reaches 30cm the both LED turn on , buzzer will turn on and the 7 segment must show 30. But the problem right now is that the 7 segment displays 30,20 and 10 continously when it reaches 30cm only it does not show the appropriate value when the water reaches the water level.

4. So when the water level reaches 10cm, what happens? Don't worry about anything else for now, just start with this question.

5. So when the water level reaches 10cm, one LED will turn on and have to show 10 in the 7 segment. But its not displaying the 10 in 7 segment.

6. So I guess when 20cm is reached, two LEDs turn on and still nothing in the 7seg? Do you get anything in the 7seg at all, or completely blank?

7. nothing completely blank in 7 segment for both 10 and 20 .

8. Ok, if you get 1 LED for 10cm and 2 LEDs for 20cm - then we know the transmitter is sending the correct signal.

This is just a guess but try deleting the following line from both the W and A if blocks. It looks like this is controlling the common for each 7seg and you're shifting it twice. Again, this is an assumption as bit banging is not my strong suit.

Code:
```P1OUT &= ~0x01;
P1OUT |= 0x02;
P2OUT &=~0x03; //Delete this line
P4DIR |=0x20;
P4DIR |=0x40;
P4OUT |=0x20;
P4OUT |=0x40;```

9. i just tested but still doesn't display . After it reach 30cm of water level than it shows 30, 20 and 10 continously. Its not displaying accordingly. Is there a way to disable 20 and 30 when 10cm of water reach so that it shows 10. same goes for others.

10. Originally Posted by Aneesha
i just tested but still doesn't display . After it reach 30cm of water level than it shows 30, 20 and 10 continously. Its not displaying accordingly. Is there a way to disable 20 and 30 when 10cm of water reach so that it shows 10. same goes for others.
You'd think so, wouldn't you?

1. Figure out how to turn one thing on.
2. Figure out how to turn it back off.
3. Repeat steps 1 and 2 for each individual thing you want to be able to turn on or off.
4. Turn on what you want, and off what you want.

You aren't even putting any thought into how to do this, you are just smashing your fingers across your keyboard hoping something works.

Quzah.

11. If i know i would have done and would not be asking help from you all. I really really don know. I have thought untill i was on mc for 2 days having high fever. I am also trying my best. But i also need your help thats why i join this forum. If i know than why should i post on forums.

12. Originally Posted by Aneesha
After it reach 30cm of water level than it shows 30, 20 and 10 continously.
Can you explain what you mean by this? Does it rapidly flash 10, then 20, then 30 (or 30, then 20, then 10)?

The only way this is possible, is if the transmitter isn't sending the expected values. However, if the LEDs are operating as expected (at 10cm and 20cm), then something else is wrong. From what I can tell, the code *should* work.

13. It rapidly flash 30, then 20, then 10. Below is my whole code

Code:
```#include "msp430x22x4.h"
#include "mrfi.h"
int count=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
BSP_Init();
MRFI_Init();//initalize 6 pin wire connection between cc2500 & msp430
TACCTL0 = CCIE;
TACCR0 = 37500;
TACTL = TASSEL_2 + MC_1 + ID_3;
P1DIR |= 0x03; // P1DIR = P1DIR | 0x03 Set P1.0, P1.1 to output direction
P1OUT &= ~0x03;
__bis_SR_register(GIE);
for (;;)
{
if(count>=0&&count<=15)
{
TACCR0 =37500; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
{
P1OUT |= 0x01;
P1OUT &= ~0x02;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='A';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
{
P1OUT |= 0x02;
P1OUT &= ~0x01;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='X';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
}
else if(count>=16&&count<=30)
{
TACCR0 = 37500; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
{
P1OUT |= 0x01;
P1OUT &= ~0x02;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='W';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
{
P1OUT |= 0x02;
P1OUT &= ~0x01;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='Y';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
}
else if(count>=31&&count<=45)
{
TACCR0 = 37500; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
{
P1OUT |= 0x01;
P1OUT &= ~0x02;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='E';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
{
P1OUT |= 0x02;
P1OUT &= ~0x01;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='Z';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
}
}
}
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if (count == 45)
{
count = 1;
}
else
{
count++;
}
}
void MRFI_RxCompleteISR()
{
}
#include "msp430x22x4.h"
#include "mrfi.h"
#define P3_set_out P2DIR |=0x01;//set Pin 3 and pin 4 to output
#define P4_set_out P2DIR |=0x02;

#define a_set_out P2DIR |=0x04;//set P2.2 output direction
#define b_set_out P2DIR |=0x08;//set P2.3 output direction
#define c_set_out P2DIR |=0x10;//set P2.4 output direction
#define d_set_out P4DIR |=0x08;//set P4.3 output direction
#define e_set_out P4DIR |=0x10;//set P4.4 output direction
#define f_set_out P4DIR |=0x20;//set P4.5 output direction
#define g_set_out P4DIR |=0x40;//set P4.6 output direction

#define a_on P2OUT |=0x04;
#define a_off P2OUT &=~0x04;
#define b_on P2OUT |=0x08;
#define b_off P2OUT &=~0x08;
#define c_on P2OUT |=0x10;
#define c_off P2OUT &=~0x10;
#define d_on P4OUT |=0x08;
#define d_off P4OUT &=~0x08;
#define e_on P4OUT |=0x10;
#define e_off P4OUT &=~0x10;
#define f_on P4OUT |=0x20;
#define f_off P4OUT &=~0x20;
#define g_on P4OUT |=0x40;
#define g_off P4OUT &=~0x40;

int num,num_1,num_2,r_1,count=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
BSP_Init();
P1REN|=0x04;
P1IE|=0x04;
MRFI_Init();//initalize 6 pin wire connection between cc2500 & msp430
TBCTL=TBSSEL_2+MC_1+ID_3;
TBCCTL0=CCIE;
TBCCR0=150;
__bis_SR_register(LPM0_bits+GIE);
P1DIR |= 0x03; // P1DIR = P1DIR | 0x03 Set P1.0, P1.1 to output direction
P1OUT &= ~0x03;
/*TBCTL=TBSSEL_2+MC_1+ID_3;
TBCCTL0=CCIE;
TBCCR0=150;*/
__bis_SR_register(GIE);
for(;;)
{
}
}
void MRFI_RxCompleteISR()
{
mrfiPacket_t packet;
if(packet.frame[9]=='A')
{
P1OUT |= 0x01;
P1OUT &=~0x02;
P2OUT &=~0x03;
P4DIR |=0x20;
P4OUT |=0x20;
packet.frame[9]=' ';

a_set_out;//set P2.2->segment A as output pin
b_set_out;//set P2.3->segment B as output pin
c_set_out;//set P2.4->segment C as output pin
d_set_out;//set P4.3->segment D as output pin
e_set_out;//set P4.4->segment E as output pin
f_set_out;//set P4.5->segment F as output pin
g_set_out;//set P4.6->segment G as output pin

num_1=(20/10);
r_1=20%10;
num_2=r_1/1;
if(count>=0&&count<=4)
{
P2OUT &=~0x03;
P2OUT |=0x01;
num=num_1;
}
if(count>=5&&count<=10)
{
P2OUT &=~0x03;
P2OUT |=0x02;
num=num_2;
}
packet.frame[9]=' ';
switch(num)
{
case 0:
a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_off;
break;
case 1:
a_off;
b_on;
c_on;
d_off;
e_off;
f_off;
g_off;
break;
case 2:
a_on;
b_on;
c_off;
d_on;
e_on;
f_off;
g_on;
break;
case 3:
a_on;
b_on;
c_on;
d_on;
e_off;
f_off;
g_on;
break;
case 4:
a_off;
b_on;
c_on;
d_off;
e_off;
f_on;
g_on;
break;
case 5:
a_on;
b_off;
c_on;
d_on;
e_off;
f_on;
g_on;
break;

case 6:
a_on;
b_off;
c_on;
d_on;
e_on;
f_on;
g_on;
break;
case 7:
a_on;
b_on;
c_on;
d_off;
e_off;
f_off;
g_off;
break;
case 8:
a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_on;
break;
case 9:
a_on;
b_on;
c_on;
d_off;
e_off;
f_on;
g_on;
break;
}
}
else if(packet.frame[9]=='W')
{
P1OUT &= ~0x01;
P1OUT |= 0x02;
P2OUT &=~0x03;
P4DIR |=0x20;
P4DIR |=0x40;
P4OUT |=0x20;
P4OUT |=0x40;
packet.frame[9]=' ';

a_set_out;//set P2.2->segment A as output pin
b_set_out;//set P2.3->segment B as output pin
c_set_out;//set P2.4->segment C as output pin
d_set_out;//set P4.3->segment D as output pin
e_set_out;//set P4.4->segment E as output pin
f_set_out;//set P4.5->segment F as output pin
g_set_out;//set P4.6->segment G as output pin

num_1=(10/10);
r_1=10%10;
num_2=r_1/1;
if(count>=0&&count<=4)
{
P2OUT &=~0x03;
P2OUT |=0x01;
num=num_1;
}
if(count>=5&&count<=10)
{
P2OUT &=~0x03;
P2OUT |=0x02;
num=num_2;
}
packet.frame[9]=' ';
switch(num)
{
case 0:
a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_off;
break;
case 1:
a_off;
b_on;
c_on;
d_off;
e_off;
f_off;
g_off;
break;
case 2:
a_on;
b_on;
c_off;
d_on;
e_on;
f_off;
g_on;
break;
case 3:
a_on;
b_on;
c_on;
d_on;
e_off;
f_off;
g_on;
break;
case 4:
a_off;
b_on;
c_on;
d_off;
e_off;
f_on;
g_on;
break;
case 5:
a_on;
b_off;
c_on;
d_on;
e_off;
f_on;
g_on;
break;

case 6:
a_on;
b_off;
c_on;
d_on;
e_on;
f_on;
g_on;
break;
case 7:
a_on;
b_on;
c_on;
d_off;
e_off;
f_off;
g_off;
break;
case 8:
a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_on;
break;
case 9:
a_on;
b_on;
c_on;
d_off;
e_off;
f_on;
g_on;
break;
}
}

else if(packet.frame[9]=='E')
{
P1OUT |= 0x01;
P1OUT |= 0x02;
P4DIR |=0x20;
P4DIR |=0x40;
P4OUT |=0x20;
P4OUT |=0x40;
P3_set_out;
P4_set_out;

a_set_out;//set P2.2->segment A as output pin
b_set_out;//set P2.3->segment B as output pin
c_set_out;//set P2.4->segment C as output pin
d_set_out;//set P4.3->segment D as output pin
e_set_out;//set P4.4->segment E as output pin
f_set_out;//set P4.5->segment F as output pin
g_set_out;//set P4.6->segment G as output pin

num_1=(30/10);
r_1=30%10;
num_2=r_1/1;
if(count>=0&&count<=4)
{
P2OUT &=~0x03;
P2OUT |=0x01;
num=num_1;
}
if(count>=5&&count<=10)
{
P2OUT &=~0x03;
P2OUT |=0x02;
num=num_2;
}
packet.frame[9]=' ';
switch(num)
{
case 0:
a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_off;
break;
case 1:
a_off;
b_on;
c_on;
d_off;
e_off;
f_off;
g_off;
break;
case 2:
a_on;
b_on;
c_off;
d_on;
e_on;
f_off;
g_on;
break;
case 3:
a_on;
b_on;
c_on;
d_on;
e_off;
f_off;
g_on;
break;
case 4:
a_off;
b_on;
c_on;
d_off;
e_off;
f_on;
g_on;
break;
case 5:
a_on;
b_off;
c_on;
d_on;
e_off;
f_on;
g_on;
break;

case 6:
a_on;
b_off;
c_on;
d_on;
e_on;
f_on;
g_on;
break;
case 7:
a_on;
b_on;
c_on;
d_off;
e_off;
f_off;
g_off;
break;
case 8:
a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_on;
break;
case 9:
a_on;
b_on;
c_on;
d_off;
e_off;
f_on;
g_on;
break;
}
}

else if(packet.frame[9]=='X')
{
//P1OUT |= 0x02;
P1OUT &=~0x01;
P4OUT &=~0x20;
P4OUT &=~0x40;
packet.frame[9]=' ';
}
else if(packet.frame[9]=='Y')
{
//P1OUT |= 0x02;
P1OUT &=~0x01;
P4OUT &=~0x20;
P4OUT &=~0x40;
packet.frame[9]=' ';
}
else if(packet.frame[9]=='Z')
{
//P1OUT |= 0x02;
P1OUT &=~0x01;
P4OUT &=~0x20;
P4OUT &=~0x40;
packet.frame[9]=' ';
}
}
#pragma vector =PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG&=~0x04;
//BUZZER
}
#pragma vector=TIMERB0_VECTOR
__interrupt void TB0_ISR(void)
{
if (count == 10)
{
count = 0;
}
else
{
count++;
}
}```

14. Can you try replacing all the code in here:

Code:
```if(packet.frame[9]=='A')
{

}```

With this:

Code:
```if(packet.frame[9]=='A')
{
P1OUT |= 0x01;
P1OUT &=~0x02;
P4DIR |=0x20;
P4OUT |=0x20;

a_set_out;//set P2.2->segment A as output pin
b_set_out;//set P2.3->segment B as output pin
c_set_out;//set P2.4->segment C as output pin
d_set_out;//set P4.3->segment D as output pin
e_set_out;//set P4.4->segment E as output pin
f_set_out;//set P4.5->segment F as output pin
g_set_out;//set P4.6->segment G as output pin

P2OUT &=~0x03;
P2OUT |=0x01;

packet.frame[9]=' ';

a_on;
b_on;
c_on;
d_on;
e_on;
f_on;
g_on;
}```

If my interpretation is correct, this should turn on 1 LED and set one of the 7segs to '8' when the water reaches 10cm.

And while you try that, I will start reading all that code...

15. It really does me no good to help you here, since you aren't interested in how it works, you just want your answer. You don't care if you can light one up and turn it off at will, you just want it to do what your assignment is and nothing more. Because if you did care, you'd actually make a small program to figure out these simple things first, and once you knew how to make it do what you wanted, then you'd go about putting it all together in some bigger program. As it is, you are just copying/pasting in lines of code from wherever you got them in the first place, without caring what they actually do.

Quzah.