'>Hextor_8US.BSx '============================================================== '{$stamp BS2Sx} '============================================================== 'Debug program for testing the ultrasonic sensor and servo 'Note J6,7 must be set to ON for the scanning servo to work. 'New '--- 'Required knowledge: ' 'Constants: ustx usrx ustout usmin usahead usmax 'Variables: usdir usRange 'Subroutine: usget '============================================================== epower con 2 'pin high turns on power to electronics Rled con 8 'pin high turns on right green led Lled con 9 'pin high turns on left red led ustx con 14 'pin ultrasonic commands, i96n usrx con 15 'pin ultrasonic data in, i96n i96n con 16624 '9600 baud, 8 bit, no parity, inverted poweruptime con 1500 'pause before powering up electronics ustout con 10000 'timeout min 6000 for 0 to 255 travel usdir var byte 'us servo direction, 255=left 0=right usRange var byte 'us servo range, 15-255 'during downloading the power to the electronics is turned off, 'if it is turned back on again too soon the electronics, 'especially the ultrasonics do not power up properly, 'so wait poweruptime before turning power on. init: output Rled output Lled high Rled high Lled pause poweruptime high epower 'turn on electronics debug cls 'Program start '------------- 'to set sensor in correct place on servo and check end points 'comment-out 'goto sweep'. For sweep de-comment 'goto sweep'. start:toggle Rled ' goto sweep goto limit 'edit values for usmaxright, usmaxleft to check servo travel. 'If servo judders at end points then it is hitting its stops, 'alter usmaxright and usmaxleft until servo doesn't judder. usmin con 10 'right,increase if servo hits end stop usahead con 135 'alter so servo points straight ahead usmax con 255 'left, decrease if servo hits end stop limit: 'comment-out two of the options for usdir ' usdir =usmax usdir =usahead ' usdir =usmin gosub usget pause 50 goto limit sweep:usdir =usmax gosub usget nxt1: usdir =usahead gosub usget nxt2: usdir =usmin gosub usget nxt3: goto sweep '------------- subroutines --------------------- usget:'talk to UltraSonic co-processor usRange =0 'invalid value, used if no repyl usdir =usdir min usmin max usmax 'don't hit end stops usout:serout ustx,i96n,["T",usdir] serin usrx,i96n,ustout,us1,[usRange] 'jump if no reply debug dec usdir," ",dec usRange," ",cr return us1: debug "no reply from ultrasonics",cr return '------------------------ end program -------------------------