Created
October 20, 2018 08:46
-
-
Save SamaHadhod/a2303ec56c1c74fcbc080739450ef2dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int a;int b;int d;int x=0;int y=0; | |
void read1(){TMR1H = 0;TMR1L = 0; | |
PORTa.F6 = 1;Delay_us(10);PORTa.F6 = 0; | |
while(!PORTa.F7);T1CON.F0 = 1;while(PORTa.F7);T1CON.F0 = 0; | |
a = (TMR1L | (TMR1H<<8));a = a/34;a = a + (a/5); | |
if(a<11){a=a+1;}else a=a;} | |
void read2(){TMR1H = 0;TMR1L = 0; | |
PORTa.F1 = 1;Delay_us(10);PORTa.F1 = 0; | |
while(!PORTa.F0);T1CON.F0 = 1;while(PORTa.F0);T1CON.F0 = 0; | |
b = (TMR1L | (TMR1H<<8));b = b/34;b = b + (b/5); | |
if(b<11){b=b+1;}else b=b;} | |
void read3(){TMR1H = 0;TMR1L = 0; | |
PORTa.F2 = 1;Delay_us(10);PORTa.F2 = 0; | |
while(!PORTa.F3);T1CON.F0 = 1; while(PORTa.F3);T1CON.F0 = 0; | |
d = (TMR1L | (TMR1H<<8));d = d/34;d = d + (d/5); if(d<11){d=d+1;}else d=d;} | |
void main() | |
{ cmcon=7; T1CON = 0x10; TRISB = 0b00000000; TRISa = 0b10001001; porta=0; portb=0;delay_ms(100); | |
loop: | |
read2();x=b;delay_ms(200); read2();y=b; | |
b=(x-y); | |
if( b>=14){portb.f0=1;read1();read3(); | |
if(a>=d){portb.f7=1;portb.f4=1;delay_ms(200);portb.f7=0;portb.f4=0;} | |
if(d>=a){portb.f1=1;portb.f3=1;delay_ms(200);portb.f1=0;portb.f3=0;} | |
} | |
if( b<=10){portb.f0=0;} | |
goto loop; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment