' ************************************************************************** ' * * ' * PICAXE-18 MOTION MONITOR FOR CYBOT AXE18MON * ' * * ' ************************************************************************** ' * * ' * Program AXE18MON.BAS * ' * * ' * Target PICAXE-18 * ' * Compiler Revolution Programming Editor 2.3.5 * ' * Memory Used 67 bytes of 128 ( 51 free ) * ' * * ' * Version 1.00 * ' * Created 2002-04-23 * ' * Last Modified 2002-04-23 * ' * * ' * Author The Happy Hippy * ' * Web Site http://www.psynet.net/hippy * ' * * ' * Copyright (C) 2002, The Happy Hippy * ' * * ' ************************************************************************** ' * * ' * DESCRIPTION * ' * * ' * This program monitors the serial line from the Brain, and displays * ' * motion requests in a graphical format on a 7-segment display. The * ' * 7-segment display must be of the common cathode type. * ' * * ' * The interface should be connected to the Motor Controller * ' * processor. TX from the Brain goes to RX here, and to RX on the * ' * Motor Controller processor. * ' * * ' ************************************************************************** ' * * ' * CIRCUIT DIAGRAM * ' * * ' * .-. * ' * 5v |O|------.------------------------.---------. * ' * RX |O|------|---------------------. | __|__ * ' * 0v |O|--.---|---------------------|--|----. _____ 100nF * ' * `-' | | | | | | * ' * | |^| PICAXE-18 | | `----' * ' * | | | 4K7 .---------. | | * ' * | |_| | 1 18 | | | * ' * | | | 2 17 | | | * ' * }---|------>| 3 16 | | | * ' * | `------>| 4 15 |<--' | * ' * }-----------| 5 14 |------' * ' * | F <--| 6 13 |--> DP * ' * | A <--| 7 12 |--> G * ' * | B <--| 8 11 |--> E * ' * | C <--| 9 10 |--> D * ' * | `---------' * ' * | * ' * | .------------------. * ' * | | .------. | The actual connections * ' * | `--| A |--< A | to the 7-segment display * ' * | F >--| F B |--< B | will depend upon its * ' * | G >--| G |--< C | make and model. * ' * | E >--| E C |--< DP | * ' * | D >--| D * |-k------{ The display must be of * ' * | `------' | the common cathode type. * ' * | 7-SEG |^| * ' * | 1K5 | | _|_ * ' * | |_| _\ /_ * ' * | | | * ' * `----------------------------' k * ' * * ' ************************************************************************** ' * * ' * HISTORY * ' * * ' * 1.00 2002-04-23 First public release * ' * * ' ************************************************************************** ' * * ' * KNOWN BUGS * ' * * ' * 1.00 2002-04-23 None. * ' * * ' ************************************************************************** ' ************************************************************************** ' * * ' * Define input pin usage * ' * * ' ************************************************************************** symbol RA0 = 0 ' RA0 / A2D0 symbol RA1 = 1 ' RA1 / A2D1 symbol RA2 = 2 ' RA2 / A2D2 symbol RX = 6 ' RA6 - Serial In symbol RA7 = 7 ' RA7 ' ************************************************************************** ' * * ' * Define output pin usage * ' * * ' ************************************************************************** symbol SEGF = 0 ' RB0 - F AAAA symbol SEGA = 1 ' RB1 - A F B symbol SEGB = 2 ' RB2 - B F B symbol SEGC = 3 ' RB3 - C GGGG symbol SEGD = 4 ' RB4 - D E C symbol SEGE = 5 ' RB5 - E E C symbol SEGG = 6 ' RB6 - G DDDD symbol DP = 7 ' RB7 - DP DP ' ************************************************************************** ' * * ' * Define constants * ' * * ' ************************************************************************** symbol BAUD = N2400 ' Maximum baud rate ' ************************************************************************** ' * * ' * Define variables * ' * * ' ************************************************************************** symbol dataReceived = b0 ' Data received from Brain symbol dataType = b1 ' Type of data received symbol motionRequired = b2 ' Motion requested by Brain symbol segBits = b3 ' Segment Display Bits ' ************************************************************************** ' * * ' * Program Initialisation * ' * * ' ************************************************************************** ' The program starts execution here when the processor is powered up, is ' reset, and after the program has been downloaded. ' ' We start the program by putting up a cycling display on the 7-segment ' display running clockwise. This will cycle segments F, A, B, C, D, E and ' then G. The Decimal Point (DP) is not tested. ' ' The order of segments matches the output line bit assignment so we can use ' a simple bit shift. ' ' The cycling takes approximately 7 x 125mS = 875mS. We then turn all the ' segments off and pause for just over 2S. ' ' The program is ready to start monitoring the serial line after 3S. ' ' The Motor Controller will send its first serial data byte 5S after it is ' reset, the Brain will respond shortly after that. The Motion Monitor will ' be ready and waiting to receive that byte from the Brain. Start: segBits = %00000001 ' Start with F segment InitLoop: pins = segBits ' Turn the required segment on pause 125 ' Delay 125mS if segBits = %01000000 then InitDone ' Just done G segBits = segBits * 2 ' Select next segment goto InitLoop ' Turn the segment on InitDone: pins = 0 ' Turn all segments off pause 2125 ' Wait until 3S from reset ' ************************************************************************** ' * * ' * Main Program Loop * ' * * ' ************************************************************************** ' We wait to receive a serial byte that has been sent by the Brain. The ' format of the byte is - ' ' .-----------.-----------.-----------------------. ' | t | t | s | s | m | m | m | m | ' `-----------^-----------^-----------------------' ' ' where t is type, if not 00 we ignore the data received ' s is Speed, 0 = slowest .. 3 = fastest ' m is Motion required, 0 .. 15 ' ' 0 = Stop 7 = Turn Left ' 1 = Forward Left 8 = Turn Right ' 2 = Forward Right ' 3 = Move Forward 9 ..11 = Rotate Left ' 4 = Move Backward 12..14 = Rotate Right ' 5 = Backwards left ' 6 = Backwards Right 15 = Stop for 10S ' ' If the type is not 00, we ignore the data received. ' ' The speed is ignored. ' ' The motion is extracted from the received byte, and is used as an index ' into a table to determine which segments of the display should be set. ' ' We are using the 'read' and 'eeprom' commands because these use less code ' space than the equivalent 'lookup', and it also makes the program more ' readable. ' ' The display segments are set as follows - ' ' --- #### #### ##### --- ' | | # | | # # # | | ' ### #--- ---# #---# #---# ' | | | | | | | | # # ' --- --- --- --- ##### ' ' Stop Fwd Left Fwd Right Forward Backwards ' ' --- --- #### #### ' | | | | # | | # ' #--- ---# #### #### ' # | | # | | | | ' #### #### --- --- ' ' Back Left Back Right Turn Left Turn Right ' ' #--- ---# ### ' # | | # | | ' #### #### --- ' # | | # | | ' #--- ---# ### ' ' Rotate Rotate Stop for ' Left Right 10S ' ' The display segments are set, and the program waits to receive the next ' motion request byte from the Brain. The entire process is then repeated. ' ' The program continues until powered off, reset, or reprogrammed. WaitForDataToBeReceived: serin RX,BAUD,dataReceived CheckDataTypeIs00: dataType = dataReceived & %11000000 if dataType <> %0000000 then WaitForDataToBeReceived DetermineMotionRequired: motionRequired = dataReceived & %00001111 GetSegmentBitsToTurnOn: read motionRequired,segBits ' PGEDCBAF ( P = Decimal Point ) eeprom (%01000000) ' 0 - Stop eeprom (%00000011) ' 1 - Turn Forward Left eeprom (%00000110) ' 2 - Turn Forward Right eeprom (%00000111) ' 3 - Move Forward eeprom (%00111000) ' 4 - Move Backwards eeprom (%00110000) ' 5 - Turn Bacwards Left eeprom (%00011000) ' 6 - Turn Backwards Right eeprom (%01000011) ' 7 - Spin Left eeprom (%01000110) ' 8 - Spin Right eeprom (%01100001) ' 9 - Rotate Left eeprom (%01100001) ' 10 - Rotate Left eeprom (%01100001) ' 11 - Rotate Left eeprom (%01001100) ' 12 - Rotate Right eeprom (%01001100) ' 13 - Rotate Right eeprom (%01001100) ' 14 - Rotate Right eeprom (%00010010) ' 15 - Stop for 10S OutputSegmentBits: pins = segBits ' Turn segments on or off together ContinueForever: goto WaitForDataToBeReceived ' ************************************************************************** ' * * ' * End of source code * ' * * ' **************************************************************************