Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

what might be wrong

Status
Not open for further replies.

t.man

New Member
I have this program for blinking LED...but that's not what happens. LED is always ON. is the delay too small?

whats the problem?

Code:
.include "m8def.inc"

	rjmp	RESET		;reset handle


;* Long delay 

;* Register variables

	.def  T1      = r1
	.def  T2      = r2
	.def  temp    = r19

;* Code
	    
longDelay:      
	clr   T1		;T1 used as delay 2nd count
	clr   T2		;T2 used as delay 3d count
delay_1:    
	dec   T2
	brne  delay_1            
	dec   T1
	brne  delay_1           
	dec   temp		
	brne  delay_1		
	ret                     


;* Resets the data direction register D

;* Defines

	.equ  led   = 6		;LED at PD6

;* Code

RESET:
	sbi   DDRD, led		;connect LED to PORTD pin 6
	    

;* Main program

;* This part will let the LED go on and off by w

;* Register variables

	.equ  w   =  10 	;enter delaytime w

flash: 
	sbi   PORTD, led	;LED on
	ldi   temp, w		;w sec delay           
	rcall longDelay             
	cbi   PORTD, led	;LED off            
	ldi   temp, w		;w sec delay
	rcall longDelay
	rjmp  flash		;another run

the program is running on mega8 using a 6.144MHz crystal.
 
whats the problem?

You'll need to add the code to initialize the STACK Pointer or else the stack pointer initialise to all zero after reset. See the following code:

Code:
.include "m8def.inc"

	rjmp	RESET		;reset handle

;* Code

RESET:
[color=red][b]        ldi   temp,HIGH(RAMEND)    ; get high byte of end of memory address
        out   SPH,temp
        ldi   temp,LOW(RAMEND)     ; get low byte of end of memory address
        out   SPL,temp
[/b][/color]
	sbi   DDRD, led		;connect LED to PORTD pin 6
	    

;* Main program

;* This part will let the LED go on and off by w
 
Status
Not open for further replies.

Latest threads

Back
Top