Is there something wrong with this code?

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

I am basically trying to make an oscillator using an Attiny2313 just to give myself a basic start on something. I am using avrasm2 for the assembler and creating intel hex files.

 

.include          "tiny2313def.inc"

 

start:     ldi    r16, 0b11111111

            out   ddra, r16

            out   portb, r16

 

            ldi    r17,  0b00000000

            out portb, r17

            

            rjump start

 

I am using a crystal oscillator and I have a 1mhz square wave on the pd2 oscillator output pin. I am monitoring portb with an oscilliscope but it sits at a constant low.

I have almost zero coding experience with the Atmel stuff and I am probably missing something very basic.

 

Thanks for any help.

 

    

This topic has a solution.
Last Edited: Sat. Aug 17, 2019 - 08:54 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a minor "pick". Its MHz, not mhz! The latter is millihertz and that is REALLY slow.

 

You are setting the direction of PortA, then writing to then writing to PORTB. Bet it will work if you change ddra to ddrb.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Aug 17, 2019 - 08:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Made the correction and you were right sir. Thank you for the help!

 

Roger

 

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

You should leave the DDR register alone once it is initialised. ie

; you don't really need this line with AS7, it is added behind the scenes for you

.include	"tiny2313def.inc" 

start:
	ldi	r16, 0b11111111
	out	ddrb, r16

loop:
	ldi	r16, 0b11111111		; this could be set, r16 or you could load it just before loop
	out	portb, r16		; for a faster loop

	ldi	r17,  0b00000000	; this could be clr, r17 or you could load it just before loop
	out 	portb, r17		; for a faster loop

	rjmp loop

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sat. Aug 17, 2019 - 10:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  First of all, you are setting DDR A to all output, but putting the off/on data on port B.  Port B is still at its default DDR value of all inputs.  Writing 0x00 and 0xff to port B is turning off and on the internal pull-up resistor on each Port B pin a million times a second.

 

Assembler programs generally follow a strict template.  Go to the projects section and download a random set of assembler language files and review how they are put together.

Last Edited: Sat. Aug 17, 2019 - 11:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or:

 

; you don't really need this line with AS7, it is added behind the scenes for you

.include	"tiny2313def.inc" 

start:
    ldi	r16, 0b11111111
    out	ddrb, r16

loop:
    out	portb, r16		; for a faster loop
    com r16             ; complement all bits
    rjmp loop

 

Last Edited: Sun. Aug 18, 2019 - 10:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mopar_512 wrote:
rjump start

RJUMP is another name for RJMP?  Or a case of posted code that isn't the real code.

 

You might be interested in

https://www.avrfreaks.net/commen...

theusch wrote:

donepel wrote:
only in pure and hard asm.

I would suggest a start at www.avrbeginners.net.  Several basic applications are posted there.

 

http://www.avrbeginners.net/gett...

 

theusch wrote:
I posted the shortest ever (AFAIK) AVR LED-blink program:  https://www.avrfreaks.net/commen... Two program lines, and eight choices of LED blink interval.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.