Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3346006
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:15:09+00:00 2026-05-18T01:15:09+00:00

Please help me with this code, it is making me crazy. This is a

  • 0

Please help me with this code, it is making me crazy. This is a very simple program with 8-bit timer, cycling through all 8 leds (one-by-one). Am using ATSTK600 board.

My timers are working well, I think there is some problem with the loops (when I debug this program using avr studio-gcc, I can see all the leds working as I want but when I transfer it on board…leds don’t blink). Am going crazy with this type of behavior.

Here is my code:

#include <avr/io.h>
#include <avr/interrupt.h>

volatile unsigned int intrs, i, j = 0;

void enable_ports(void);
void delay(void);

extern void __vector_23 (void) __attribute__ ((interrupt));

void enable_ports()
{
    DDRB = 0xff;

    TCCR0B = 0x03;

    TIMSK0 = 0x01;

    //TIFR0 = 0x01;

    TCNT0 = 0x00;

    //OCR0A = 61;

    intrs = 0;
}

void __vector_23 (void)
{
    for(i = 0; i<=8; i++)
    {
        while(1)
        {
            intrs++;
            if(intrs >= 61)
            {
                PORTB = (0xff<<i);
                intrs = 0;
                break;
            }

        }
    }
    PORTB = 0xff;
}

int main(void)
{
    enable_ports();
    sei();

    while(1)
    {

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:15:10+00:00Added an answer on May 18, 2026 at 1:15 am

    Your interrupt routine is flawed. intrs counts only the number of times the loop has executed, not the number of timer interrupts as its name suggests. 61 iterations of that loop will take very little time. You will see nothing perceivable without an oscilloscope.

    The following may be closer to what you need:

    void __vector_23 (void)
    {
        intrs++;
        if(intrs > 60)
        {
            intrs = 0;
            PORTB = (0xff<<i);
    
            i++ ;
            if(i == 8 )
            {
                i = 0 ;
                PORTB = 0xff;
            }
        }
    }
    

    Although setting the compare register OCR0A to 61 as in your commented out code would avoid the need for the interrupt counter and reduce unnecessary software overhead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please help with this noob questions but really making me go crazy> if I
Could anyone please help me convert this code to vb.net, I have tried it
Could you please help me converting this c++ code into python: I am trying
Hey friends any one please help me for this issue.in this javascript code i
Please i need help, this code below works fine on my localhost, php5.3+ but
Please, help me. I dont know what is wrong with this code: import android.appwidget.AppWidgetProvider;
i have very simple code that i making partial postback by jquery and i
Please help this would be my last problem in dealing with access database with
Please help this beginner here... I have a SQL Server 2008 R2 running on
Please help me with this update query. I COMPLETELY understand how redundant this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.