bumper.c

Go to the documentation of this file.
00001 /*
00002  * control module for Bumper sensors
00003  * (c) 2007 by Matthias Arndt <matthias.arndt@tu-clausthal.de>
00004  *
00005  */
00007 #include "t89c51cc02.h"
00008 #include "datatypes.h"
00009 #include "bumper.h"
00010 #include "adc.h"
00011 
00015 void Bumper_init()
00016 {
00017         P2=(P2 & 0xFC); /* clear msb of bumper control bus */
00018         P1_5=0; /* clear lsb of bumper control bus */
00019 
00020         Bumper_deactivate();    /* make sure bumper sensors are not active */
00021 
00022         ADCF |= 0x08;   /* enable analogue input on P1.3 for bumpers */
00023 }
00024 
00033 void Bumper_select(BYTE sensorid)
00034 {
00035 
00036         sensorid=(sensorid & 0x07); /* mask sensors which are not allowed */
00037 
00038         P2=(P2 & 0xFC)|(sensorid & 0x03); /* set lower bus bits */      
00039         P1_5=(bit) (sensorid & 0x04); /* set lsb of decoder bus */
00040 
00041         /* trade in some time to latch the new address properly */
00042         _asm
00043         nop
00044         nop
00045         nop
00046         _endasm;
00047 }
00048 
00057 WORD Bumper_read(BYTE bumpernr)
00058 {
00059         WORD result;
00060 
00061         /* the subsystem assumes that the bumpers are turned on and off only when required */
00062         Bumper_select(bumpernr);
00063         Bumper_activate();
00064         result=ADC(3);  /* read bumper value from P1.3 (bumper analogue input) */
00065         Bumper_deactivate();
00066         return(result);
00067 }

Generated on Wed Oct 24 12:57:24 2007 for SensorControl by  doxygen 1.4.6