.nolist ; ;ToDo's ; .include "c:\avrtools\appnotes\8535def.inc" .list ;------ PortA Defines ---------------------------------------- .equ Bvoltage = 0 ;battery voltage monitor .equ FfloorSensor = 1 ;front floor sensor .equ RfloorSensor = 2 ;rear floor sensor ;------ PortB Defines ---------------------------------------- .equ BumperSensor = 0 ;bumper switch .equ RunButton = 1 ;run button .equ ModeButton = 2 ;mode button .equ Green = 3 ;green test LED .equ Red = 4 ;red test LED .equ ScopeA = 6 ;Used for debugging with scope .equ ScopeB = 7 ;Used for debugging with scope ;------ PortC Defines ---------------------------------------- .equ db0 = 0 ;display data 0 .equ db1 = 1 ;display data 1 .equ db2 = 2 ;display data 2 .equ db3 = 3 ;display data 3 .equ rs = 4 ;display register select .equ display = 5 ;display enable ;------ PortD Defines ---------------------------------------- .equ Lencoder = 2 ;left encoder input .equ Rencoder = 3 ;right encoder input .equ FfloorLED = 6 ;front floor IR LED .equ RfloorLED = 7 ;read floor IR LED ;------ Macros for Port control ------------------------------ .macro ToggleDisplay sbi portc,display cbi portc,display .endm .macro FloorLEDon cbi portd,FfloorLED cbi portd,RfloorLED .endm .macro FloorLEDoff sbi portd,FfloorLED sbi portd,RfloorLED .endm .macro ClearEncoders clr Lencoder ;clear the encoder counters clr Rencoder .endm .macro GreenOn sbi portb,Green .endm .macro GreenOff cbi portb,Green .endm .macro RedOn sbi portb,Red .endm .macro RedOff cbi portb,Red .endm .macro ScopeAon sbi portb,ScopeA .endm .macro ScopeAoff cbi portb,ScopeA .endm .macro ScopeBon sbi portb,ScopeB .endm .macro ScopeBoff cbi portb,ScopeB .endm ;------ Command Constants ----------------------------------- .equ cmdForward = 0x01 ;Both drive motors go forward .equ cmdBackward = 0x22 ;Both drive motors go backward .equ cmdLeft = 0x33 ;Right motor forward, left motor stopped .equ cmdRight = 0x44 ;Left motor forward, right motor stopped .equ cmdJogLeft = 0x55 ;Slight turn to left, for course adjustment .equ cmdJogRight = 0x66 ;Slight turn to right, for course adjustment .equ cmdSpinLeft = 0x77 ;Right motor forward, left motor backwards .equ cmdSpinRight = 0x88 ;Left motor forward, right motor backwards .equ cmdVictory = 0x99 ;spin continously .equ cmdStop = 0xAA ;Both motors stop .equ cmdDump = 0x8A ;Dump data to PC .equ cmdGreenLed = 0x5A ;turn on Greenled .equ cmdGetStatus = 0xBB ;Return 8535 sensor status .equ cmdGetEncoder = 0xCC ;Return encoder values .equ cmdShake = 0xDD ;do the victory shake .equ cmdSleep = 0xEE ;go to sleep ;------ Mode Constants -------------------------------------- .equ mBump = 1 ;bumper mode .equ mSumo = 2 ;sumo mode, uses floor sensor .equ mBoth = 3 ;use bumper and floor sensor ;------ Display Constants ----------------------------------- .equ c_Clr = 0x01 ;clear display .equ c_CursorLeft = 0x10 ;move cursor left .equ c_CursorRight = 0x14 ;move cursor right .equ c_Goto = 0x80 ;data ram control .equ c_Cgen = 0x40 ;Character Generator ram .equ c_Line2 = 0x40 ;start address of line 2 .equ c_Line3 = 0x14 ;start address of line 3 .equ c_Line4 = 0x54 ;start address of line 4 .equ f_Set = 0x20 ;Function Commands .equ f_1line = 0x00 ;1 line mode .equ f_2line = 0x08 ;2 line mode .equ f_8font = 0x00 ;5x8 font .equ f_11font = 0x04 ;5x11 font .equ d_Set = 0x08 ;Display Control .equ d_DisplayOn = 0x04 ;Display on .equ d_DisplayOff = 0x00 ;Display off .equ d_CursorOn = 0x02 ;Cursor on .equ d_CursorOff = 0x00 ;Cursor off .equ d_BlinkOn = 0x01 ;Blink on .equ d_BlinkOff = 0x00 ;Blink off .equ e_Set = 0x04 ;Entry mode control .equ e_CursorRight = 0x02 ;cursor moves right .equ e_CursorLeft = 0x00 ;cursor moves left .equ e_NoShift = 0x00 ;cursor doesn't shift .equ e_Shift = 0x01 ;cursor shifts ;------ Flag Bits --------------------------------------- .equ Tick = 0 ;Timer Tick bit .equ Running = 1 ;Running mode .equ CmdReady = 2 ;command received flag .equ Busy = 3 ;command in process .equ CheckEncoders = 4 ;Encoder tick bit .equ Jogging = 5 ;jogging in progress ;------ Register Defines -------------------------------- .def LPMReg = r0 ;used with LPM in DisplayRom .def ISRTimer0 = r1 ;used in timer0 ISR .def ISRADC = r2 ;used in ADC ISR .def ADClo = r3 ;temp register used in ADC ISR .def ADChi = r4 ;temp register used in ADC ISR .def ISRDelay = r5 ;used in Delay routine could be replaced with push/pop .def ISRInt0 = r6 ;used in int0 ISR .def ISRInt1 = r7 ;used in int1 ISR .def MyLoop = r8 ;loop counter .def ISRUart = r9 ;used in uart ISR .def ISRUtemp = r10 ;used in uart ISR .def ISRTimer2 = r11 ;used in timer2 ISR .def Loglo = r12 ;stores the Z register values used for logging .def LogHi = r13 .def Acc = r16 ;used as accumulator .def Flags = r17 ;Flag bits .def Mode = r18 ;running mode .def Lencoder = r19 ;left encoder counter .def Rencoder = r20 ;right encoder counter .def Command = r21 ;current command .def BusyTimer = r22 ;timer for Busy routine .def LeftSpeed = r23 ;current setting for left motor .def RightSpeed = r24 ;current setting for right motor .def JogTimer = r25 ;counts time of jog adjustment .def TXPointer = r26 ;X register used by UART to send .def TXPointerHi = r27 ;status block to master .def ADCchannel = r28 ;Y register points to the current .def ADCchannelHi = r29 ;ADC channel being measured .def Ptrl = r30 ;Z register used with tables .def Ptrh = r31 ;------ Ram Defines ------------------------------------- .equ StatusBlock = 0x60 ;begining of status block .equ sbBattery = 0x60 ;battery voltage .equ sbFfloor = 0x61 ;front floor sensor .equ sbRfloor = 0x62 ;rear floor sensor .equ DataBuffer = 0x66 ;store logging data ;------ Interrupt Vector Table -------------------------- .cseg ;start code segment .org 0 rjmp Start ;reset vector rjmp Int0isr ;irq0 rjmp Int1isr ;irq1 reti ;timer2 compare rjmp Timer2 ;timer2 overflow reti ;timer1 capture reti ;timer1 compareA reti ;timer1 compareB reti ;timer1 overflow rjmp Timer0 ;timer0 overflow reti ;SPI transfer complete rjmp UARTrx ;uart rx complete rjmp UARTtx ;udr empty reti ;uart tx complete rjmp ADCIsr ;adc complete reti ;eeprom ready reti ;analog compare ;**************************************************************** ; Motor Speed Tables * ;**************************************************************** SpeedTableL: .db 0x00 ;Left0 .db 0xcc ;Left1 .db 0xcb ;Left2 .db 0xca ;Left3 .db 0xc9 ;Left4 .db 0xc8 ;Left5 .db 0xc7 ;Left6 .db 0xc6 ;Left7 .db 0xc5 ;Left8 .db 0xc4 ;Left9 SpeedTableR: .db 0x00 ;Right0 .db 0xce ;Right1 .db 0xcd ;Right2 .db 0xcf ;Right3 .db 0xd0 ;Right4 .db 0xd1 ;Right5 .db 0xd2 ;Right6 .db 0xd3 ;Right7 .db 0xd4 ;Right8 .db 0xd5 ;Right9 ;**************************************************************** ; MainJumpTable - Use an indirect jump with this table to * ; handle command routines * ;**************************************************************** MainJumpTable: rjmp SlaveOperation ;no command rjmp DoForward ;1 ;Both drive motors go forward rjmp DoBackward ;2 ;Both drive motors go backward rjmp DoLeft ;3 ;Right motor forward, left motor stopped rjmp DoRight ;4 ;Left motor forward, right motor stopped rjmp DoJogLeft ;5 ;Slight turn to left, for course adjustment rjmp DoJogRight ;6 ;Slight turn to right, for course adjustment rjmp DoSpinLeft ;7 ;Right motor forward, left motor backwards rjmp DoSpinRight ;8 ;Left motor forward, right motor backwards rjmp DoVictorySpin ;9 ;spin continously rjmp DoStop ;A ;Both motors stop rjmp DoGetStatus ;B ;Return 8535 sensor status rjmp DoGetEncoder ;C ;Return encoder counts rjmp DoVictoryShake ;D ;little dance shaking rjmp DoSleep ;E ;ignore master ;**************************************************************** ; Timer0 - Timer Interrupt Service Routine * ; Entry occurs every 4ms * ;**************************************************************** Timer0: in ISRTimer0,sreg ;save status register sbr Flags,1<