Beruflich Dokumente
Kultur Dokumente
;John McDonald
;EE 476 Final Project
;RC Car - TRANSMITTER
.include "4414def.inc"
;========================================================
; Toggle ADC Clock - PORTA
;ADC reads and outputs data on falling edge of the clock
.MACRO A_CLOCKPULSE
sbi PORTA, AADCCLK ;CLK high
nop
cbi PORTA, AADCCLK ;CLK low
nop
.ENDMACRO
;========================================================
; Toggle ADC Clock - PORTC
;ADC reads and outputs data on falling edge of the clock
.MACRO C_CLOCKPULSE
sbi PORTC, CADCCLK ;CLK high
nop
cbi PORTC, CADCCLK ;CLK low
nop
.ENDMACRO
;========================================================
;************************
.dseg
;************************
.cseg
.org $0000
rjmp Reset ;reset entry vector
reti
reti
reti
reti
reti
reti
reti
reti
reti
rjmp TXempty ;UART buffer empty
rjmp TXdone ;UART transmit done
reti
RESET:
cli
ldi temp, LOW(RAMEND) ;setup stack pointer
out SPL, temp
ldi temp, HIGH(RAMEND)
out SPH, temp
;initial conditions
clr TXbusy ;start out not busy on TX
;setup UART -- enable TXempty & RXdone int, and RX, TX pins
ldi temp, 0b00101000
out UCR, temp
;set baud rate to 9600
ldi temp, baud96
out UBRR, temp
;debounce setup
clr debounce ;debounce on or off
clr DBcnt ;debounce counter
clr status ;initialize car to off
sei
A_CLOCKPULSE
cbi PORTA, AADCCS ;initiate conversion
A_CLOCKPULSE
sbi PORTA, AADCDI ;startbit
A_CLOCKPULSE
sbi PORTA, AADCDI ;single ended
A_CLOCKPULSE
cbi PORTA, AADCDI ;channel 0
A_CLOCKPULSE
ReadA: A_CLOCKPULSE
clc ;clear carry
sbic PINA, AADCDO
sec ;set carry if high
rol Volt
dec Count
brne ReadA ;more bits remaining
ldi Count, 8
IgnoreA:A_CLOCKPULSE
dec Count
brne IgnoreA ;ignore lsb first data
;***********************Transmit Speed***********************
_bakCmd:
cpi Volt, SpdMid
brlt _fwdCmd
cpi Volt, SpdMid
breq _stpCmd
lsr Volt
subi Volt, RevOffset
ori Volt, bakcmd
mov command, Volt
rjmp Sendspd
_fwdCmd:
ldi temp, SpdMid
sub temp, Volt
subi temp, FwdOffset
ori temp, fwdcmd
mov command, temp
rjmp Sendspd
_stpCmd:
ldi command, 0x00
Sendspd:
; rcall LEDSt
rcall SendMsg
C_CLOCKPULSE
cbi PORTC, CADCCS ;initiate conversion
C_CLOCKPULSE
sbi PORTC, CADCDI ;startbit
C_CLOCKPULSE
sbi PORTC, CADCDI ;single ended
C_CLOCKPULSE
cbi PORTC, CADCDI ;channel 0
C_CLOCKPULSE
ReadC: C_CLOCKPULSE
clc ;clear carry
sbic PINC, CADCDO
sec ;set carry if high
rol Volt
dec Count
brne ReadC ;more bits remaining
ldi Count, 8
IgnoreC:C_CLOCKPULSE
dec Count
brne IgnoreC ;ignore lsb first data
;***********************Transmit Steering***********************
_rgtCmd:
cpi Volt, StrMid
brlt _lftCmd
cpi Volt, StrMid
breq _ctrCmd
lsr Volt
subi Volt, RgtOffset
ori Volt, rgtcmd
mov command, Volt
rjmp Sendstr
_lftCmd:
ldi temp, StrMid
sub temp, Volt
subi temp, LftOffset
ori temp, lftcmd
mov command, temp
rjmp Sendstr
_ctrCmd:
ldi command, 0x00
ori command, rgtcmd
Sendstr:
; rcall LEDSt
rcall SendMsg
;***************************Get Status***************************
Getstat:
cpi debounce, ON ;check if debounce is on
breq _debounce
in temp, PORTB
cpi release, OFF ;check if buttons have been released
breq _release
_trig:
mov temp2, status
andi temp2, 0x0f
inc temp2
cpi temp, Maxlights
brge _lightsoff
rjmp _running
_lightsoff:
ori status, 0xf0
rjmp _running
_debounce:
inc DBcnt ;increment debounce counter
breq _DBdone
rjmp _release
_DBdone:
ldi debounce, OFF ;turn debounce off
rjmp _release
_release:
ori temp, 0x30
brne _status
ldi release, ON
;************************Transmit Status*************************
_status:
mov command, status
ori command, 0xf0
breq _off
_on:
mov command, status
ori command, 0x5f
_off:
mov command, status
ori command, 0x4f
rcall SendMsg
rjmp GetSpd
;***************************Return*******************************
;******************
;Pause procedure
;******************
;_Wait:
; cli ;disable interrupts
; clr temp2 ;clear upper 8 bits of counter
;outerL:
; clr temp3 ;clear lower 8 bits of counter
;innerL:
; inc temp3
; cpi temp3, 0
; brne innerL
; inc temp2
; cpi temp2, 255
; brne outerL
; sei ;here the outer loop is
complete; approx. 1 ms has passed
; ret ;return from wait subroutine
;*******************
;message sending sub
;*******************
SendMsg:
ldi ZL, LOW(cntstr) ;ptr to RAM
ldi ZH, HIGH(cntstr)
inc ZL
st Z, command
ld r0,Z
out UDR, r0 ;fire off the UART transmit
clr TXflash ;the string is in RAM
ser TXbusy ;and set the TX busy flag
sbi UCR, UDRIE ;enable the TXempty interrupt
rcall TXwait
ret
;******************
;Debug procedure
;******************
LEDSt:
mov LEDReg, command
com LEDReg ;invert to send correct output to leds
out PORTB, LEDReg
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;UART stuff follows.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;*****************************
;subroutine