Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] problem in atmega8....

Status
Not open for further replies.

Deexith Hasan

Advanced Member level 4
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Activity points
740
a simple program on timer1 to get 1sec delay and successfully compiled in winavr.. but got error push program stack:SP is not initialized .. in proteus....
how to solve it.........

Code:
#include <avr/io.h>
#include <util/delay.h> 
  void delay();
 
  void main(void)
 
  {
    SPH=0X00;
	SPL=0X00;
    DDRB=0XFF;
    while(1)
    {
	PORTB=0X00;
	delay();
	PORTB=0XFF;
	delay();
      
    }
    
  }

   void delay()
{
TCNT1H=0X85;
TCNT1L=0XEE;
TCCR1A=0X00;
TCCR1B=0X04;
  while((TIFR& (0X1<<TOV1))==0);
TCCR1B=0X00;
  TIFR=0x1<<TOV1;
  }
 

Here is mikroC PRO AVR Code.

It uses Timer to get 1 second delay. LEDs are connected to PORTB.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
char count = 0;
 
//Timer1 Prescaler = 64; Preload = 31249; Actual Interrupt Time = 500 ms
 
//Place/Copy this part in declaration section
void InitTimer1() {
    SREG_I_bit = 1;
    TCCR1A = 0x80;
    TCCR1B = 0x0B;
    OCR1AH = 0x7A;
    OCR1AL = 0x11;
    OCIE1A_bit = 1;
}
 
void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA {
    //Enter your code here
    if(++count == 2) {
         count = 0;
         PORTB = ~PORTB;
    }
}
 
void main() {
 
    DDRB = 0xFF;
    DDRC = 0xFF;
    DDRD = 0xFF;
    
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    
    InitTimer1();
    
    while(1) {
    
          asm nop
    }
}




broken link removed
 

Attachments

  • Timer Based LED Blinking.rar
    72.9 KB · Views: 56
  • Timer Based LED Blinking.png
    Timer Based LED Blinking.png
    19.3 KB · Views: 96
  • Atmel Studio.rar
    36.4 KB · Views: 51
Last edited by a moderator:

thats k....for atmega16 & 32 got gud result in proteus only for atmega8 y?? what does it mean error push program stack:SP is not initialized
 

SP not initialized means Stack Pointer not initialized. Why are you clearing the stack pointer in the code. Don't do anything with stack pointer. Here I am attaching LED Blinking code made for different AVR Compilers.
 

Attachments

  • LED Blinking.rar
    354.1 KB · Views: 55

i removed the SP again faced the same problem....
Code:
SPH=0X00;
SPL=0X00;
y????
 

Unistall Atmel Studio and install the latest version which is v6.2 and try.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top