Connect with us

Atmel program problem.

Discussion in 'Electronic Basics' started by [email protected], Jan 17, 2005.

Scroll to continue with content
  1. Guest

    I've been trying to make a program for a atmel 90s1200 chip. The
    program is located at http://zet.no/~vidarlo/program.asm .
    It runs fine in Atmel AVR studio 3.56, and behaves like it is supposed
    to. However, when deployed on a chip, it does not work at all, it seems
    to run the fan subroutine all the time, no matter what switches is
    pressed. I've tried it on a stk-500 developer card, and built the
    circuit on a digital trainer, with debounced switches with pull-down
    resistors. However, it still seems to run the fan loop all the time,
    but it does not get stuck there. I've been running it at low frequency
    to determine that it is not stuck, the leds come on and off!
     
  2. Rich Webb

    Rich Webb Guest

    ....
    ldi r16, 0xff ; puts 0xFF in register 16
    out DDRB, r16 ; Sets bit in ddr for port B
    ....

    Grrrr. I *hate* assembly that's commented like that; states the obvious
    but doesn't explain what it's doing. Something like "Set all bits in
    Port B as outputs" etc. would be nice...

    ....
    main: ; start of main loop
    in r17, portD ; Read data from port D, store in r17
    andi r17, 7 ; Mask r17 with 7, to destroy all but last.
    ....

    This is the problem. The register "PortD" is the port latch and, when
    the port is set as an input, controls whether or not the internal
    pull-ups are enabled. The value after reset is 0x00 so that's what
    you'll always read and the app will always branch to the fan routine.
    To read the value at the pins, you should read the register "PinD"
    instead.

    ....
    main: ; start of main loop
    in r17, pinD ; Read data from port D, store in r17
    andi r17, 7 ; Mask r17 with 7, to destroy all but last.
    ....

    Not that *I've* ever made that mistake. <erm... cough cough>
     
  3. Guest

    Ok, thanks:) It worked with the correction you gave me. I just supposed
    portB...oh, very well, portD...*ahem - learning to read documentation*
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-