' Golgoth 2004 Programme #include "start.bas" DDRD = 0 ' PD5=PD4=PD3=PD2=input SCONF = 0x4C ' B,C = sorties byte n1,n2,T,c1,ct,ct2, vit,ct3,ct4,c2 int compteur,t2,t1 lcdinit() ' enable l'afficheur PACTL.1 = 1 ' selectioner la vitesse interruption 16ms PACTL.0 = 0 PACTL.7 = 1 ' A7 en sortie PACTL.3 = 1 TMSK2.6 = 1 ' declencher le timer cli ' autoriser les inter print "golgoth" n1=180 ' A3 servo vertical n2=150 ' A7 servo horizontal ct=0 ct2=0 ct3=0 ct4=0 vit=128 ' vitesse de rotation servo PORTB.1=1 tempo(30) PORTB.1=0 PORTC = 255 do ' pour toujours ' do ' wai c1=PORTE c1=c1 AND %00001111 ' wai ' c2=PORTE ' c2=c2 AND %00001111 ' loop until c1=c2 if c1=0 then gosub arret end if if c1=1 then gosub avancer end if if c1=2 then gosub reculer end if if c1=3 then gosub tourner_g end if if c1=4 then gosub tourner_d end if if c1=5 then PORTB.0=1 tempo(20) PORTB.0=0 end if if c1=6 then PORTB.1=1 tempo(20) PORTB.1=0 end if if c1=7 then PORTB.2=1 tempo(20) PORTB.2=0 end if if c1=8 then PORTB.5=1 tempo(20) PORTB.5=0 end if if c1=9 then PORTB.6=1 tempo(20) PORTB.6=0 end if if c1=10 then PORTB.7=1 tempo(20) PORTB.7=0 end if if c1=11 then n1=180 ' A3 servo vertical n2=150 ' A7 servo horizontal end if if c1=12 then ct=ct+1 if ct=vit then n2=n2+1 ' servo horizontal if n2>=200 then n2=200 end if ct=0 end if end if if c1=13 then ct2=ct2+1 if ct2=vit then n2=n2-1 ' servo horizontal if n2<=100 then n2=100 end if ct2=0 end if end if if c1=14 then ct3=ct3+1 if ct3=vit then n1=n1-1 ' servo vertical if n1<=130 then n1=130 end if ct3=0 end if end if if c1=15 then ct4=ct4+1 if ct4=vit then n1=n1+1 ' servo vertical if n1>=230 then n1=230 end if ct4=0 end if end if loop do gosub ultrason if PORTA.0=0 then PORTA.4=0 PORTB.1=1 tempo(300) PORTB.1=0 gosub tourner_g end if if PORTA.1=0 then PORTB.7=1 gosub tourner_d PORTB.7=0 end if PORTA.5=0 PORTA.6=0 PORTA.4=1 ' Puissance ON loop ultrason2: PORTC.5=1 for t1=1 to 10 next t1 PORTC.5=0 for t1=1 to 5000 next t1 return ultrason: PORTC.5=1 for t1=1 to 10 next t1 PORTC.5=0 do loop until PORTA.2=1 compteur=0 do compteur=compteur+1 loop until PORTA.2=0 lcdinit() ' print "compt=",compteur," " 'tempo(10) if compteur<150 then PORTB.7=1 'buzzer court tempo(20) PORTB.7=0 gosub reculer gosub tourner_d end if For t2=1 to 5000 next t2 return reculer: ' PORTA.4=0 'Puissance off PORTA.5=1 PORTA.6=1 PORTA.4=1 ' Puissance ON tempo(20) return avancer: PORTA.5=0 PORTA.6=0 PORTA.4=1 'Puissance ON tempo(20) return arret: PORTA.4=0 tempo(20) return tourner_g: ' PORTA.4=0 ' Puissance OFF PORTA.5=1 PORTA.6=0 PORTA.4=1 ' Puissance ON tempo(20) PORTA.4=0 ' Puissance OFF return tourner_d: ' PORTA.4=0 ' Puissance OFF PORTA.5=0 PORTA.6=1 PORTA.4=1 ' Puissance OFF tempo(20) PORTA.4=0 ' Puissance OFF return interrupt function rtiint at $FFF0 PORTA.3=1 FOR T = 1 to n1 NEXT T PORTA.3=0 PORTA.7=1 FOR T = 1 to n2 NEXT T PORTA.7=0 TFLG2.6 = 1 ' autoriser ints a nouveau end function function tempo(cnt) int i, k,l for l=0 to cnt for i=0 to 1000 next next end function #include "lcd.bas"