#include<pic.h>
__CONFIG(HS & WDTDIS & PWRTDIS & UNPROTECT & LVPDIS);
void delay(unsigned int duration);
void main(void)
{
TRISA = 0b111100;
PORTA = 0b000000;
TRISB = 0b00000111;
PORTB = 0b00000000;
unsigned int t0, t1, st = 0, sp;
unsigned long ctr = 0;
TRISC = 0;
PORTC = 0;
PR2 = 0b11111111;
T2CON = 0b00000111;
CCPR2L = 0b11111111;
CCP2CON = 0b00111100;
while(1)
{
while(!RB0 && !RB1 && RB2) // 1 0 1
{
st = 1;
CCPR2L = 130;
PORTA = 0b000010;
delay(2);
PORTA = 0b000000;
delay(5);
t0 = 0; t1 = 1;
}
while(RB0 && !RB1 && !RB2) // 1 0 0
{
st = 1;
CCPR2L = 130;
PORTA = 0b000001;
delay(2);
PORTA = 0b000000;
delay(5);
t0 = 1; t1 = 0;
}
while(!RB0 && RB1 && RB2) // 1 1 1
{
st = 1;
if(ctr < 30)CCPR2L = 130;
else CCPR2L = 120;
PORTA = 0b000010;
t0 = 0; t1 = 1; ctr++;
delay(1);
}
while(RB0 && RB1 && !RB2) // 1 1 0
{
st = 1;
if(ctr < 30)CCPR2L = 130;
else CCPR2L = 120;
PORTA = 0b000001;
t0 = 1; t1 = 0; ctr++;
delay(1);
}
while(RB0 && RB1 && RB2) // 1 1 1
{
if((t0 / 1) == 0 && (t1 / 1) == 0)
{
CCPR2L = 110;
PORTA = 0b000000;
while(ctr == 1500 && !(RB0 && !RB1 && RB2)) CCPR2L = 0;
ctr++;
}
if((t0 / 1) == 1 && (t1 / 1) == 0) { CCPR2L = 130; PORTA = 0b000001; }
if((t0 / 1) == 0 && (t1 / 1) == 1) { CCPR2L = 130; PORTA = 0b000010; }
delay(1);
}
while(RB0 && !RB1 && RB2) // 1 0 1
{
CCPR2L = sp;
PORTA = 0b000000;
t0 = 0; t1 = 0;
delay(15);
if(sp <= 165)sp = sp + 1;
}
sp = 120;
while(!RB0 && !RB1 && !RB2) // 0 0 0
{
CCPR2L = 100;
PORTA = 0b000000;
while(ctr == 750 && st == 1 && !(RB0 && !RB1 && RB2)) CCPR2L = 0;
ctr++;
delay(1);
t0 = 0; t1 = 0;
}
ctr = 0;
}
}
void delay(unsigned int duration)
{
while(duration!=0)
{
for(unsigned int i = 0;i <= 250;i++);
duration--;
}
}
No comments:
Post a Comment