long delay

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

Hello,

I have a problem programming a long delay loop. It will work fine in AVR Studio simulation, but in an 2313 it will always jump back to start.

loop:
inc r1         
brne loop
sbis PORTB,5 ; to ask if a key is set or not
rjmp Start
inc r2
brne loop
inc r3
brne loop    
 
What is wrong with this?

Greetings Dieter    

admin's test signature
 

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

Sorry if this is the bleeding obvious, but it seems suspicious that the jump target is the target of the conditional test for pin 5 on port B. Have you checked that port B is connected correctly and is at logic 0 (not floating)?

Sean

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

You may try implementing a short "de-bounce" delay inside your "ask if a key is set" (a couple of ms should be sufficient)

admin's test signature
 

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

Hi Dieter,

If your testing an input pin from your keypad, then you should be interogating PinB,5 and not PortB,5. PortB is the port's latch.
If you do a read from PortB, all you're reading is the latch.
A read from PinB will read the actual pin.

Cheers Jack

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

Yesterday I hadn't the program listing with me.
I don't know what I'm doing wrong. It is my first
try programming a microcontroller.
Here is the whole program:

.include "C:\Atmeldef\2313def.inc"

.Macro Wait1 ; this is working
ldi R17,$15
WGLOOP0: ldi R18,$C6
WGLOOP1: ldi R19,$C9
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
.endmacro

.Macro Wait2 ; this is working without
ldi R17,$FF ; the sbis PINB and rjmp start command
WGLOOP3: ldi R18,$FF
WGLOOP4: ldi R19,$FF
WGLOOP5: dec R19
brne WGLOOP5
sbis PINB,5
rjmp start
sbis PINB,6
rjmp start
dec R18
brne WGLOOP4
dec R17
brne WGLOOP3
.endmacro

start:ldi r20,0x04
ldi r16, 0x1F ;3 In- and 5 Out
out DDRB, r16
ldi r16,0xE0 ;Inputs Pull_up
out PORTB, r16 ;Outputs Activ high
out PINB, r16

Ein1: sbic PINB,5 ;wenn bit gelöscht-springe
jmp Ein2
sbi PORTB,0 ;setze PORTB,0 high
Wait1
nop
sbic PINB,5
dec r20
sbis PINB,5
inc r20
out PORTB,r20
Wait1
nop
Wait1
nop
Wait2
nop
rjmp Start

Ein2: sbic PINB,6 ;wenn PINB,6 low - springe
rjmp Ein1
sbi PORTB,0 ;setze PORTB,0 high
Wait1
nop
sbic PINB,6
dec r20
sbis PINB,6
inc r20
out PORTB,r20
Wait1
nop
Wait1
nop
Wait2
nop
Wait2
nop
rjmp start

admin's test signature
 

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

>From: alenze (Andreas Lenze)

>You may try implementing a short "de-bounce" delay inside your "ask if a key
>is set" (a couple of ms should be sufficient)

That what I will try tonight.
So I'm waisting time in the controller (I need 60 sec. delay), I will try to let the controller do some
cycles another routine. I hope this will help.
Thank you.

Dieter

admin's test signature
 

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

Hi Dieter,

If it's your first try, get an LED blinking first, then you can move on to sending guided missiles through Bagdad streets.

Cheers Jack

Dieter Schmidt Wrote:

>It is my first try programming a microcontroller.