; FlatSpat Firmware .nolist .include "c:\avrtools\appnotes\8535def.inc" .list ;------ PortA Defines ---------------------------------------- .equ RightFloor = 1 ;Right floor sensor .equ LeftFloor = 0 ;Left floor sensor ;------ PortB Defines ---------------------------------------- .equ LeftRange = 0 ;Left Range sensor .equ RightRange = 1 ;Right Range sensor .equ GreenLed = 2 ;green LED .equ btnRun = 3 ;Run button .equ btnDiag = 5 ;diag button .equ LeftDiagLED = 6 ;left diag LED .equ RightDiagLED = 7 ;right diag LED ;------ PortC Defines ---------------------------------------- ;------ PortD Defines ---------------------------------------- .equ LeftServo = 4 ;left drive servo .equ RightServo = 5 ;right drive servo .equ LeftLed = 6 ;left floor LED .equ RightLed = 7 ;right floor LED ;------ Macros for Port control ------------------------------ .macro EnableFloorLED cbi portd,LeftLED cbi portd,RightLED .endm .macro DisableFloorLED sbi portd,LeftLED sbi portd,RightLED .endm .macro GreenLEDon cbi portb,GreenLed .endm .macro GreenLEDoff sbi portb,GreenLed .endm .macro LeftLEDon cbi portb,LeftDiagLED .endm .macro LeftLEDoff sbi portb,LeftDiagLED .endm .macro RightLEDon cbi portb,RightDiagLED .endm .macro RightLEDoff sbi portb,RightDiagLED .endm ;------ Flag Bits --------------------------------------- .equ Tick = 0 ;Timer Tick bit .equ Running = 1 ;Running mode .equ BlinkOn = 2 ;controls blink LED .equ sInFront = 3 ;Object is in front of us .equ sLeft = 4 ;Object is to the left .equ sRight = 5 ;Object is to the right ;------ Mode Constants ---------------------------------- .equ mdSearch = 0 ;use eyes and search Green .equ mdBlind = 1 ;no eyes, just wander Green blink ;------ Sensor bits ------------------------------------- .equ sRightFloor = 0 ;Right floor sensor .equ sLeftFloor = 1 ;Left floor sensor .equ sRightEye = 2 ;Right eye sensor .equ sLeftEye = 3 ;Left eye sensor ;------ Register Defines -------------------------------- .def ISRTimer0 = r1 ;used in timer0 ISR .def ISRTimer2 = r2 ;used in timer2 ISR .def ISRDelay = r3 ;used in Delay routine .def Acc = r16 ;used as accumulator .def Mode = r17 ;current mode .def Flags = r18 ;Flag bits .def MyLoop = r19 ;loop counter .def BlinkRate = r20 ;controls LED blink rate .def Sensors = r21 ;bit weighted sensor readings .def temp = r22 ;temp used in BlinkValue .def SearchCounter = r23 ;used during search routines ;------ Interrupt Vector Table -------------------------- .cseg ;start code segment .org 0 rjmp Start ;reset vector reti ;irq0 reti ;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 reti ;uart rx complete reti ;udr empty reti ;uart tx complete reti ;adc complete reti ;eeprom ready reti ;analog compare ;**************************************************************** ; Timer0 - Timer Interrupt Service Routine * ; Entry occurs every 4ms * ;**************************************************************** Timer0: in ISRTimer0,sreg ;save status register sbr Flags,1<