ArdyNT
Full Member level 2
- Joined
- Nov 6, 2012
- Messages
- 126
- Helped
- 7
- Reputation
- 14
- Reaction score
- 7
- Trophy points
- 1,298
- Activity points
- 2,304
if((ldr1 <= 300) && (motor_flagA == 0)) [COLOR="#FF0000"]// It gives error only when I add this part and the last part[/COLOR]
{
turn_A(ARIGHT,23);
motor_flagA++;
}
#asm("cli")
if((PORTB.0 == 1) && (ldr1 <= 300) && (motor_flagA == 1))
{
if(x > 1)
{
x = x - 1;
}
}
// If light intensity greater than the setpoint, increase the firing delay, and close blinds
if((PORTB.0 == 1) && (ldr1 >= 350))
{
if(x < 280)
{
x = x + 1;
}
}
#asm("sei")
if((ldr1 >= 350) && (x == 280) && (motor_flagA == 1)) [COLOR="#FF0000"]// This one[/COLOR]
{
turn_A(ALEFT,23);
motor_flagA = 0;
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 void change_intensity() { static unsigned int motor_flagA = 0; static unsigned int motor_flagB = 0; static unsigned int motor_flagC = 0; // If light intensity below the setpoint, open blinds, and shorten the firing delay if((ldr1 <= 300) && (motor_flagA == 0)) { turn_A(ARIGHT,23); motor_flagA++; } #asm("cli") if((PORTB.0 == 1) && (ldr1 <= 300) && (motor_flagA == 1)) { if(x > 1) { x = x - 1; } } // If light intensity greater than the setpoint, increase the firing delay, and close blinds if((PORTB.0 == 1) && (ldr1 >= 350)) { if(x < 280) { x = x + 1; } } #asm("sei") if((ldr1 >= 350) && (x == 280) && (motor_flagA == 1)) { turn_A(ALEFT,23); motor_flagA = 0; } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 void change_intensity() { static unsigned int motor_flagA = 0; static unsigned int motor_flagB = 0; static unsigned int motor_flagC = 0; // If light intensity below the setpoint, open blinds, and shorten the firing delay if((ldr1 <= 300) && (motor_flagA == 0)) { turn_A(ARIGHT,23); motor_flagA++; } #asm("cli") if((PORTB.0 == 1) && (ldr1 <= 300) && (motor_flagA == 1)) { if(x > 1) { x = x - 1; } } // If light intensity greater than the setpoint, increase the firing delay, and close blinds if((PORTB.0 == 1) && (ldr1 >= 350)) { if(x < 280) { x = x + 1; } } #asm("sei") if((ldr1 >= 350) && (x == 280) && (motor_flagA == 1)) { turn_A(ALEFT,23); motor_flagA = 0; } // If light intensity below the setpoint, open blinds, and shorten the firing delay if((ldr3 <= 300) && (motor_flagC == 0)) { turn_C(CRIGHT,23); motor_flagC++; } #asm("cli") if((PORTB.2 == 1) && (ldr3 <= 300) && (motor_flagC == 1)) { if(z > 1) { z = z - 1; } } // If light intensity greater than the setpoint, increase the firing delay, and close blinds if((PORTB.2 == 1) && (ldr3 >= 350)) { if(z < 280) { z = z + 1; } } #asm("sei") if((ldr3 >= 350) && (z == 280) && (motor_flagC == 1)) { turn_C(CLEFT,23); motor_flagC = 0; } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 void change_intensity() { static unsigned int motor_flagA = 0; static unsigned int motor_flagB = 0; static unsigned int motor_flagC = 0; // If light intensity below the setpoint, open blinds, and shorten the firing delay if((ldr1 <= 300) && (motor_flagA == 0)) { turn_A(ARIGHT,23); motor_flagA++; } #asm("cli") if((PORTB.0 == 1) && (ldr1 <= 300) && (motor_flagA == 1)) { if(x > 1) { x = x - 1; } } // If light intensity greater than the setpoint, increase the firing delay, and close blinds if((PORTB.0 == 1) && (ldr1 >= 350)) { if(x < 280) { x = x + 1; } } #asm("sei") if((ldr1 >= 350) && (x == 280) && (motor_flagA == 1)) { turn_A(ALEFT,23); motor_flagA = 0; } // If light intensity below the setpoint, open blinds, and shorten the firing delay if((ldr2 <= 300) && (motor_flagB == 0)) { turn_B(BRIGHT,23); motor_flagB++; } #asm("cli") if((PORTB.1 == 1) && (ldr2 <= 300) && (motor_flagB == 1)) { if(y > 1) { y = y - 1; } } // If light intensity greater than the setpoint, increase the firing delay, and close blinds if((PORTB.1 == 1) && (ldr2 >= 350)) { if(y < 280) { y = y + 1; } } #asm("sei") if((ldr2 >= 350) && (y == 280) && (motor_flagB == 1)) { turn_B(BLEFT,23); motor_flagB = 0; } // If light intensity below the setpoint, open blinds, and shorten the firing delay if((ldr3 <= 300) && (motor_flagC == 0)) { turn_C(CRIGHT,23); motor_flagC++; } #asm("cli") if((PORTB.2 == 1) && (ldr3 <= 300) && (motor_flagC == 1)) { if(z > 1) { z = z - 1; } } // If light intensity greater than the setpoint, increase the firing delay, and close blinds if((PORTB.2 == 1) && (ldr3 >= 350)) { if(z < 280) { z = z + 1; } } #asm("sei") if((ldr3 >= 350) && (z == 280) && (motor_flagC == 1)) { turn_C(CLEFT,23); motor_flagC = 0; } }
what will be the effect of using #asm("cli") and #asm("sei") too many times?
#asm("cli")
if((PORTB.0 == 1) && (ldr1 <= 300) && (motor_flagA == 1))
{
if(x > 1)
{
x = x - 1;
}
}
// If light intensity greater than the setpoint, increase the firing delay, and close blinds
if((PORTB.0 == 1) && (ldr1 >= 350))
{
if(x < 280)
{
x = x + 1;
}
}
#asm("sei")
void turn_B(unsigned char directionB, int stepB)
{
static unsigned char k = 0;
unsigned int l = 0;
while(l <= stepB)
{
l++;
if(directionB)
{
k++;
}
else
{
k--;
}
if(k == 255)
{
k = 3;
}
else
if(k == 4)
{
k = 0;
}
PORTD = (PORTD & 0b10000111) | (motor_stepB[k] & 0b01111000); // [B][COLOR="#FF0000"]Here[/COLOR][/B]
delay_ms(50);
}
}
unsigned int motor_stepA[4] = {0b00101000, 0b00110000, 0b01010000, 0b01001000};
unsigned int motor_stepA[4] = {0b00101000, 0b00110000, 0b01010000, 0b01001000};
unsigned char motor_stepA[4] = {0b0000[COLOR="#FF0000"]0101[/COLOR], 0b0000[COLOR="#FF0000"]0110[/COLOR], 0b0000[COLOR="#FF0000"]1010[/COLOR], 0b0000[COLOR="#FF0000"]1001[/COLOR]};
unsigned char motor_stepB[4] = {0b[COLOR="#FF0000"]0101[/COLOR]0000, 0b[COLOR="#FF0000"]0110[/COLOR]0000, 0b[COLOR="#FF0000"]1010[/COLOR]0000, 0b[COLOR="#FF0000"][COLOR="#FF0000"]1001[/COLOR][/COLOR]0000};
PORTB= motor_stepA[step1] | motor_stepB[step2];
PORTB= motor_stepA[i] | motor_stepB[k]
If you don't want to do it simultaneously then you can write them one at a time using a mask as I showed you before
PORTB = (PINB & 0b11110000) | (motor_stepA[i] & 0b00001111);
PORTB = (PINB & 0b00001111) | (motor_stepB[k] & 0b11110000);
then I should make i and k as global variable?
I use this but they do not work well.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?