' programme AROBOT NEW commandé par recepteur 27Mhz ' 02-12-2002 ' ' Il faut brancher les sorties du récepteur HF sur les entrées A7 et A0 ' voie 2 sur A7 et voie 1 sur A0 (à moins que ce soit l'inverse ...) ' prévu pour cboy 8Mhz, il faut ajuster les valeurs pour cboy 16Mhz #include "start.bas" BYTE n,nt BYTE T INT comp,comp2,mb DDRD = 0 ' PD5=PD4=PD3=PD2=input SCONF = 0x4C ' B,C = sorties lcdinit() PACTL.7=0 PACTL.5=1 PACTL.4=0 PACTL.6=1 TMSK2.1=0 TMSK2.4=1 TMSK2.6=0 TFLG2.6=0 n=150 nt=180 PORTB.2 = 0 cli ' autoriser les inter print " arobot 2 " do PACNT=0 wai comp=PACNT print "comp=",comp 'comp pour gauche / droite ' tempo(50) ' print "comp2=",comp2 'comp pour haut / bas ' tempo(20) ' print "n =",n ' tempo(50) if comp2>90 and comp2<110 then gosub AVANCER end if if comp2>160 and comp2<185 then gosub RECULER end if if comp>55 and comp<67 then gosub DROITE ' print "droite" end if if comp>30 and comp<40 then gosub GAUCHE ' print "gauche" end if if comp>45 and comp<54 then gosub TOUTDROIT end if if comp2>130 and comp2<150 then gosub STOP end if loop ' sous programme STOP: PORTB.2 = 0 tempo(5) ' n=150 ' wai mb=0 RETURN RECULER: if mb = 0 or mb=1 then 'on recule si on est arret ou avance PORTB.2=0 tempo(5) PORTB.0=0 PORTB.1=0 tempo(5) PORTB.2=1 mb=2 end if RETURN AVANCER: if mb = 0 or mb = 2 then 'on avance si on est arret ou recule PORTB.2=0 tempo(5) PORTB.0=1 PORTB.1=1 tempo(5) PORTB.2=1 mb=1 end if RETURN DROITE: n=100 ' wai RETURN TOUTDROIT: n=150 ' wai RETURN GAUCHE: n=200 ' wai RETURN TOURELLEGAUCHE: nt=nt+2 if nt>230 THEN nt=230 RETURN TOURELLEDROITE: nt=nt-2 if nt<130 THEN nt=130 RETURN TOURELLECENTRE: nt=160 RETURN function tempo(cnt) int i, k for cnt=cnt to 0 step -1 for i=0 to 1000 next next end function interrupt function rtiint at $FFDA ' Déclenché sur A7 comp2=0 do comp2=comp2+1 loop until PORTA.0=0 PORTA.4 = 1 FOR T = 1 to n NEXT T PORTA.4 = 0 PORTA.5 = 1 FOR T = 1 to nt NEXT T PORTA.5 = 0 TFLG2.6 = 1 ' autoriser ints a nouveau end function #include "lcd.bas"