0

Works on simulator, but not in real world
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Works on simulator, but not in real world

by Russ Nagel on Fri May 30, 2008 5:54 am

I am working on a simple program that will count the number of times a button (active low with a pull up resistor) is pushed. After 5 seconds, if no button is pushed it will flash an LED the same number of times the button is pushed.

This is a varation of the project at:

http://imakeprojects.com/Projects/avr-tutorial/



It works fine in the debugger, but when I download it to the chip (attiny45) it doesn't do a thing. I have tried inserting (LED blink) code in different places to see if the program is making it to certain sections and it doesn't seem to be doing anything at all. I have tried other programs in the same chip and they are working fine.

The pushbutton is on PINB3 (physical pin 2) and the output is on PINB4 (physical pin 3). An earlier version of this program was working on the tiny45, it wasn't working correctly but at least it was doing something!

Here is the code. Any help or ideas would be greatly appreciated.

Russ

#include<avr/io.h>
#include<util/delay.h>

int count_the_pushes (int numberofpushes);
int increment_timer (int numberoftimesegments);
void display_the_count (int numberofblinks);

int timesegments = 0;
int pushcount = 0;
int temp;

int main (void)
{

DDRB = 0b00010000;
for ( ;1==1; )
{
temp = (PINB & 0x08);
if (temp ==0)
{
pushcount = count_the_pushes (pushcount);
timesegments = 0;
}
else
{
timesegments = increment_timer (timesegments);
}
if ((timesegments == 20) & (pushcount == 0))
{
timesegments = 0;
}
if ((timesegments == 20) & (pushcount >=1) )
{
display_the_count (pushcount);
timesegments = 0;
pushcount = 0;
}
}
return 1;
}

int count_the_pushes(int pc)
{
return pc=pc+1;
}

int increment_timer (int tc)
{
return tc=tc+1;
}

void display_the_count (int flashes)
{
for (int i=0; i<flashes; i++)
{
PORTB = 0x08;
_delay_ms(250);
PORTB = 0x00;
_delay_ms(1000);

}
}
Russ Nagel
 
Posts: 18
Joined: Fri Mar 07, 2008 9:10 pm

by Russ Nagel on Fri May 30, 2008 11:16 am

UUUUHHHHH Nevermind!
Russ Nagel
 
Posts: 18
Joined: Fri Mar 07, 2008 9:10 pm

Please be positive and constructive with your questions and comments.