/* File: robotics7opt.h
   Header file for OPTIONS Version of basic controller routines for Version 7
   of the UE controller board  (motors, A to D, and sound only)

   Keil C headers are not guarded.  If robotics library is used, its header
   file should be the only included file unless KEIL_C_H is defined first.
*/

#ifndef ROBOTICS7OPT_H
#define ROBOTICS7OPT_H

#ifndef KEIL_C_H
#define KEIL_C_H
#include<reg51f.h>
#include<absacc.h>
#endif

/*-------------------------------------------------------------------------
GLOBAL CONSTANTS AND STATIC VARIABLES
---------------------------------------------------------------------------*/
/* General constants */
#define BITMASK 0x01

/* Controller indexes */
#define MOTOR_IDX 0x6000
#define ATOD_IDX 0xC000

/* Motor constants */
#define ALLMOTORSOFF 0x01  /* LSB set to 1 to leave IR sensors on */
#define MAXMOTORID 4       /* Max ID for motor */
#define MOTOROFF 0x03      /* Inverse for shifting */
#define MOTORLEFT 0x01
#define MOTORRIGHT 0x02
#define PWM_ENABLE 0x42  

/* Sound constants */
#define OFF 0
#define ON 1

/* State variables */
static unsigned char motors = 0x01;      /* Current state of motor port */
                                         /* LSB set to 1 to turn on IR sensors */

/* ------------------------------------------------------------------------
DELAY ROUTINE.  With count = 1 this routine provides a delay 
of about 200 usec.
---------------------------------------------------------------------------*/
extern void Delay(unsigned char count);

/* ------------------------------------------------------------------------
MOTOR ROUTINES 
Must call InitializeMotors before using.
Motors indexed 1-3.
Speed is: -255 to 255, however, |speed| needs to be > 190 to be effective
for most vehicle designs.
Direction is based on sign of speed:
                   < 0 for left/reverse
                   = 0 for stop
                   > 0 for right/forward
---------------------------------------------------------------------------*/
extern void InitializeMotors(void);
extern void AllStop(void);
extern void SetMotor(unsigned char motorID, int speed);

/* ------------------------------------------------------------------------
A TO D CONVERTER ROUTINE
Channels indexed 0 to 7
---------------------------------------------------------------------------*/
extern unsigned char GetAtoD (unsigned char channel);

/* ------------------------------------------------------------------------
SOUND ROUTINES
Sound turns buzzer ON (1) and OFF (0).
Beep oscillates buzzer for duration cycles.
---------------------------------------------------------------------------*/
extern void Sound(unsigned char state);
extern void Beep(unsigned char duration);

#endif  /* ROBOTICS7OPT_H */
