Simple ASM

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey everyone,

Here is a simple little asm program...I was playing around with a "pause" in order to see the output and am still not happy with my ideas...I suppose the _second_ macro is not used for code timing (sorry if that is a stupid question!!)

.include "m2560def.inc"

.cseg
.org 0x00

reset:
clr r17
clr r16
clr r18
ldi r18,1

main:
mov r16,r18
out portb,r16
inc r18
cpi r18,255
breq reset
rjmp  main

Eventually I hope to write an ISR for the FR and use both Bascom and ASM.

John

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Unable to copy avatar file: permission denied.

Anyone know what this is all about? Pixels are 60 x 45 and file is 1.5KB...what gives??

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The avatar upload has been broken for several months.

On your program, you haven't set the DDR, so you're just flipping pullups on and off.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Chuck...I know, chapter 1 of your book details the pullups;)

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's easy to overlook, along with every other little detail of these blasted monsters.

As for the program as you have it written, it'll take a 'scope to see anything because of the speeds involved. If you want to slow it down to human terms, you can do something like the following:

x1:  decr r20
     brne x1
     decr r21
     brne x1
     decr r22
     brne x1
     

Each decr/brne pair will multiply the number of loops by 256, so it adds up fast. If you want to be polite, you can zero out the registers first, but if you don't it will just make the first time through possibly short. You don't need to reload anything because they've all counted down to zero before they fall through.

Of course you can preload/reload things to other than zero to have better control over the delay, other than 256, 64K, 16.7 million, etc. loops.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I was playing with methods to use the 16 bit registers to pause 1sec but things were getting sloppy. I could use AVR Studio to disassemble the Bascom "Wait" command but, I won't learn anything that way!!

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The easiest way to do the 16 bit register countdown is probably:

     ldi   xl,low(your number here)
     ldi   xh,high(your number here)
lp:  sbiw  xh:xl,1
     brne  lp

Or you could use adiw and count up to zero (64K).

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was trying to multiply 65535 by 122 and then use two 16 bit registers to count down thinking that at 8mhz that would give me one second!!

Austin Powers: "I hope I didn't say that out loud right now!"

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since you are trying so hard to get a delay function running. :)

;====================
.CSEG
;====================

;Wait the number of ms in y (16 bit value-up to 65.535s) 

WAIT_y_ms: 
   rcall	WAIT1ms 
   sbiw		yl,1 
   brne		WAIT_y_ms
   ret  

;Waits the number of ms in temp1 (8 bit value, up to 255ms)
WAITms_lp:
	rcall	WAIT1ms
	dec		temp1
	brne	WAITmS_lp	
	ret
	
;1mS delay. Accurate from about 100KHz to about 260MHz clock
WAIT1ms:
	push	yl				;2 cycles
	push	yh				;2 cycles
	ldi		yl,low  (((fosc/1000)-14)/4)	;1 cycle
	ldi		yh,high (((fosc/1000)-14)/4)	;1 cycle
dlyms:	
	sbiw	yl,1			;2 cycles
	brne	dlyms			;2 cycles
	pop		yh				;2 cycles
	pop		yl				;2 cycles
	ret						;4 cycles

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Subtracts an immediate value (0-63) from a register pair

Thanks John...I need to learn more commands. I will need to look closer at your bottom two examples to understand them. What about the predefined macros I mentioned > _seconds_ ? Is there a good tutorial you can recommend?

John

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What about the predefined macros I mentioned > _seconds_ ?
Where did you get those macros from? Or are you hoping that there are such macros??

All I have is an "accurate" 1ms loop that gets called up to 255 times or 65535 depending on how long a delay you want. The 8 bit delay saving a few bytes of flash.

So if you want a 1s time delay just load Y with 1000 and call WAIT_y_ms.

The 1ms delay is adjusted by the assembler to give the closet 1ms time delay depending on the oscillator clock frequency so I don't have to redo the time delay if I'm using 1 MHz or 20MHz.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John,

Here they are...I have a lot of work to do so, I will get there but, I was trying to find more examples of macro use!

I found the info in the AVR Assmebler help section. A screen shot is shown below!!

Attachment(s): 

Just some guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which version of Studio are you usinsg?? Not the same as 4.16.

Anyway those macros have nothing to do with actual code that goes into the chip. More likely stuff that will appear in your list file to keep track of when programs were built.

If you want to learn about macros that actually produces code then download AVR001.

edit ok it has moved to the pre-prcessor section now with 4.16 and they have to do with:

__DATE__
 String
 built-in
 Build date. Format: "Jun 28 2004", see -FD command-line option.
 
__TIME__ 
 String
 built-in
 Build time. Format: "HH:MM:SS". see -FT command-line option
 

the preprocessor can handle code generation as well but the ones you list are not for that purpose.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly