;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
.text ; program start
.global _main ; define entry point
_main:
NOP
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog timer
;Set the I/O port that controls the RED LED to an output.
; To do this set bit 0 in the P1DIR register. Leave all
; all other I/O lines as inputs
Call #SetIOPorts
Call #InitilizeDisplaySPI
Call #InitilizeDisplay
looptemp:
;mov.b #0xa5,R10
;call #SendSPI
;jmp looptemp
call #DisplayLetters
;bic #0X4100,&UCSCTL6
call #HalfSecondDelay
;bic.b #0X70,&UCSCTL1
;MOV #0X11FF,&UCSCTL2
;call #HalfSecondDelay
Mainloop:
jmp Mainloop; jump to the Mainloop label
nop
InitilizeDisplay:
bic.b #01000000b,P1OUT ;reset the display
call #HalfSecondDelay ;only need 20us but I have a half second delay.
bis.b #01000000b,P1OUT
mov.a #DisplayInitilizationData,R4
InitDisplayMore:
bic.b #00001000b,P2OUT
mov #0x1f,R10
call #SendSPI
mov.b @R4+,R13
cmp.b #0xff,R13
jz InitDisplayDone
mov.b R13,R10
and.b #0x0f,R10
call #SendSPI
rra.b R13
rra.b R13
rra.b R13
rra.b R13
mov.b R13,R10
and.b #0x0f,R10
call #SendSPI
bis.b #00001000b,P2OUT
jmp InitDisplayMore
InitDisplayDone:
bis.b #00001000b,P2OUT
ret
DisplayInitilizationData:
.byte 0x3A,0x01f,0x09,0x06,0x1E,0x39,0x1B,0x6E,0x56,0x7A,0x38,0x01,0x0F,0x39,0x56,0x70,0x38,0xff
Displaynumbers:
mov.a #DisplayNumberData,R4
bic.b #00001000b,P2OUT
DisplaynumbersMore:
mov.b @R4+,R10
cmp.b #0xff,R10
jz DisplaynumbersDone
call #SendSPI
jmp DisplaynumbersMore
DisplaynumbersDone:
bis.b #00001000b,P2OUT
ret
DisplayNumberData:
.byte 0x5f,0x01,0x03,0x02,0x03,0xff
DisplayLetters:
mov.a #DisplayLettersData,R4
bic.b #00001000b,P2OUT
DisplayLettersMore:
mov.b @R4+,R10
cmp.b #0xff,R10
jz DisplayLettersDone
call #SendSPI
jmp DisplayLettersMore
DisplayLettersDone:
bis.b #00001000b,P2OUT
ret
DisplayLettersData:
.byte 0x5f,0x01,0x04,0x02,0x06,0x01,0x06,0x0E,0x06,0x0F,0x06,0x02,0x06,0xff ; Abanoub
HalfSecondDelay:
mov #0x1,R14
OuterTimercountLoop:
mov #0xffff,R15
TimercountLoop:
nop
sub #1,R15
jnz TimercountLoop
sub #1,R14
jnz OuterTimercountLoop
ret
SetIOPorts:
; IO ports need to be defined as Inputs and outputs based on the development board
;
; PORT 1 bit direction function
; 0 output LED on Developmet board
; 1 input (pullup) Switch 2 on development board
; 2 input right distance sensor
; 3 input left distance sensor
; 4 output left pwm
; 5 output right pwm
; 6 output Display reset
; 7 input EzEET_uart
mov.b #00000011b,P1OUT ;set up all default output values and pullups
mov.b #00000010b,P1REN ;enable pull up/dn resistors
mov.b #01110001b,P1DIR ;set all pin directions per definition
; PORT 2 bit direction function
; 0 output Distance Right Trigger
; 1 input (pullup) Switch 1 on development board
; 2 output Direction of right motor
; 3 output Chip Select for display
; 4 input front distance sensor
; 5 output front distance sensor trigger
; 6 output left distance sensor trigger
; 7 output direction of left motor
mov.b #00001010b,P2OUT ;set up all default output values and pullups
mov.b #00000010b,P2REN ;enable pull up/dn resistors
mov.b #11101101b,P2DIR ;set all pin directions per definition
; PORT 3 bit direction function
; 0 output MOSI (also LED 1)
; 1 input MISO (also LED 2)
; 2 output SCLK (also LED 3)
; 3 output UART Tx (also LED 4)
; 4 input UART Rx (also LED 5)
; 5 output LED 6
; 6 output LED 7
; 7 output LED 8
mov.b #00000110b,P3OUT ;set up all default output values and pullups
mov.b #00000000b,P3REN ;enable pull up/dn resistors
mov.b #11101101b,P3DIR ;set all pin directions per definition
mov.b #00000111b,P3SEL
; PORT 4 bit direction function
; PORT 5 bit direction function
; PORT 6 bit direction function
; PORT 7 bit direction function
ret
InitilizeDisplaySPI:
bic.b #00001000b, &P2OUT ;Chip Select low initializer
mov.b #01000000b, &P1OUT ;Reset high initializer
mov.b #00001000b, &P2DIR ;Chip Select Output mode
mov.b #01000000b, &P1DIR ;Reset Output mode
mov.b #00000111b, &P3SEL ;SCLK, MOSI, MISO
mov.b #00000001b, UCB0CTL1 ;Allow modifications
mov.b #01001001b, &UCB0CTL0 ;Communication parameters
mov.b #11000001b, &UCB0CTL1 ;More parameters
mov.b #0x0B, &UCB0BR0 ;Setting baud rate to achieve 100 kHz clock
mov.b #0x00, &UCB0BR1
bic.b #00000001b, UCB0CTL1 ;Enable serial
bic.b #01000000b, &P1DIR ;Pull reset low
call #HalfSecondDelay ;Wait
; bic.b #01000000b, &P1DIR ;Pull reset high
nop
ret
SendSPI:
; Send SPI will send the data in R10 to the SPI port and recieve the data
; R9 is used to check the buisy bit.
; make sure to check teh busy bit before and after sending data.
bis.b #01000000b, &P1DIR ;Pull Chip Select high
bis.b #01000000b, &P1DIR ;Pull Chip Select high
mov.b R10, &UCB0TXBUF ;send the spi the content of r10
CheckSTATUS:
bit.b #1, &UCB0STAT l ;if spi is busy wait till its finished
jnz CheckSTATUS
nop
ret
nop
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET