'-------------------------------------------------------------- ' file: Tuna-d001.BAS ' KAH 11/22/2004 ' For Atmel 90s2313-based TTT board Tuna-can wheeled robot '-------------------------------------------------------------- Dim A As Byte , B1 As Byte , C(3) As Byte , S1 As Byte Dim S1low As Byte , S1hi As Byte Dim L As Bit Dim Lmotor As Byte , Rmotor As Byte Dim Lmb As Byte , Rmb As Byte Declare Sub Gets1() Config Portd = &B0010010 'PD0 = RxD, Input 'PD1 = TxD, Output 'PD2 = IRPDR, Input 'PD3 = IRPDL, Input 'PD4 = LED, Output 'PD5,6 = Inputs Printbin 02 'reset and clear CRT Printbin 12 Print "TTT 90S2313" Lmb = 53 Rmb = 104 Open "comb.3:2400,8,n,1" For Output As #1 Printbin #1 , 0 Printbin #1 , Lmb Printbin #1 , Rmb Printbin #1 , 0 Print "Sumo Tuna D001" ; Chr(13) Print "5 seconds..." ; Chr(13) Wait 5 Print "Go!" ; Chr(13) 'Configure for software SPI Config Spi = Soft , Din = Portb.6 , Dout = Portb.5 , Clock = Portb.7 Config Pinb.4 = Output Spiinit Call Gets1() ' pre-calc the offset for the edge detect ' +/- 15 from initial light sensor read mean edge S1low = S1 - 15 S1hi = S1 + 15 Printbin #1 , 128 L = 1 ' do forever While L = 1 Call Gets1() ' hit the line (bright) If S1 > S1hi Then B1 = Rmb - 4 Printbin #1 , B1 B1 = Lmb + 1 Printbin #1 , B1 Wait 1 Printbin #1 , Lmb Printbin #1 , Rmb End If ' hit the line (dark) If S1 < S1low Then B1 = Rmb - 4 Printbin #1 , B1 B1 = Lmb + 1 Printbin #1 , B1 Wait 1 Printbin #1 , Lmb Printbin #1 , Rmb End If B1 = Pind And &H0C ' check IR sensors If B1 = 0 Then ' Print "no target" Lmotor = Lmb - 3 Rmotor = Rmb + 2 End If If B1 = 4 Then ' Print "left" Lmotor = Lmb - 2 Rmotor = Rmb - 2 End If If B1 = 8 Then ' Print "right" Lmotor = Lmb + 2 Rmotor = Rmb + 2 End If If B1 = 12 Then ' Print "straight" ' Attack! Lmotor = 127 Rmotor = 1 End If Printbin #1 , Lmotor Printbin #1 , Rmotor Waitms 20 Wend Sub Gets1() Portb.4 = 0 A = &B00001100 Spiout A , 1 Spiin C(1) , 2 Portb.4 = 1 Shift C(1) , Left , 4 Shift C(2) , Right , 4 S1 = C(2) Or C(1) End Sub Print "Completed" ; Chr(13) End