Find the address peripherals you need at http://www.add.ece.ufl.edu/4744/references/tms320f28335_sprs439e.pdf page 94,95.
Then since you are just using direct addressing we can just use some symbols for the addresses for less confusion.
GPADIR .set 0x6F8A ;used to set direction of GPIO[0:31]
GPADAT .set 0x6FC0 ;the actual pins/ports for GPIO[0:31]
To direct address with symbols/numbers we have set up the data-page pointer correctly (if we had defined labels the assembler would take care of the aligning of the data-page pointer itself see below).
A 32 bit data address
0000 0000|00XX XXXX|XXXX XXXX|XXYY YYYY
where {X} is the data-page (stored in DP) and {Y} is the offset stored as a 6-bit immediate in the opcode.
So the address (0x6FC0) is:
0000 0000|0000 0000|0110 1111|1100 0000
0110 1111 11
We want DP to equal 0x6FC0>>6 = 0x1BF
We can let the assembler do the math for us:
MOV DP,#GPADAT>>6
MOV @GPADAT,#0x0001 ;output a 1.
Some of you are thinking,"Hey why do you use another 16 bit number (GPADAT) for the direct addressing?" we really aren't, the format is to avoid confusion and the assembler truncates GPADAT to the 6-bits used to address the data-page. So the opcode for this looks like this:
0010 1000|0000 0000|0000 0000|0000 0001
0010 1000|00YY YYYY|ZZZZ ZZZZ|ZZZZ ZZZZ
where {Y} is the offset stored as a 6-bit immediate and {Z} is the 16-bit immediate value.
Using direct addressing with labels defined in .data or .bss
If there were a less complicated assembler/linker you could define label and locate them anywhere you please. Such as pointing a label at the GPIO. However, the assembler uses directives like .data, .text, .bss to define areas of memory and the linker command files assigns these sections to areas of memory.
The assembler does make it easy for use labels for direct addressing here's how it works. Define some variables, use the first variable name to set up the data-page pointer, now you can use the specific variable names for direct addressing without changing the data-page pointer as long as they are in the same 64-word data page range.
Example:
.data
val1 .word 0x000
val2 .word 0x001
...
val64 .word 0x020
val65 .word 0x021
...
val128 .word 0x040
.text
main:
mov AL,#0
mov DP,#val1
add AL,@val1 ;1
add AL,@val2 ;2
...
add AL,@val64
add AL,@val65 ;1-this actually adds @val1 again
mov DP,#val65
add AL,@val65 ;1-here we go
add AL,@val66 ;2
...
The opcodes for the lines with matching numbers should be exactly the same...
No comments:
Post a Comment