I posted also above this post, i dont think you’ve read.
I went back to our code we made that took the timing readings - which i modified so that it was all in the main function (and removed the slide pot - if you remember, for the time being). the codes below.
On this one i get a constant clicking in the headphones maybe 10 times a second???, and pressing a button which i have now added between pins 13 and 8(gnd) for pd7, the button does…nothing…
/*******************************************************************/
/* Mega8 MP3 Player (mega8 + VS1003 + SD) V1.8 */
/* */
/* Discription: Can play mp3/wma/wav/mid SF0 files in the root */
/* directery on the SD card which file system is FAT16*/
/* or FAT32. */
/* It has six keys to control this player */
/* MODE: switch between repeat all (default),repeat 1 */
/* and shuffle */
/* PLAY/PAUSE: */
/* PREV: previous songs */
/* NEXT: next songs */
/* UP : volume up */
/* DOWN: volume down */
/* Platform : AVRStudio4.13 b528 + WinAVR20070525 */
/* optimize -0s */
/* Author : bozai(Zhang Qibo) */
/* E-mail : sudazqb@163.com */
/* MSN : zhangqibo_1985@hotmail.com */
/* Date : 2007-06-16 */
/*******************************************************************/
/* V1.8 */
/* 2007-06-16 */
/* Still the bug of FAT, it's not resolved totally */
/* */
/* V1.7 */
/* 2007-05-21 */
/* Fix a serious bug of FAT */
/* Set the default mode to "Shuffle" */
/* Because the mode button is inside the box */
/* So I don't want to open the box when I turn on it */
/* If the button is easy to press of your mp3 player */
/* just change the macro below to: */
/* 0 = repet all 1 = repet one 2 = shuffle */
#define DEFAULT_MODE 0
/* */
/* V1.6 */
/* 2007-05-09 */
/* And a track function to make the shuffle a real shuffle */
/* Due to the limted RAM space of mega8. Maximum no repetition */
/* songs is 1024. And songs more than that will use randomly play */
/* Special thanks to Ronald Ausloos (Belgium)'s advice */
/* */
/* V1.5 */
/* 2007-05-03 */
/* Change the behavior of the LEDs: */
/* VS1003 faild: LED1 blink */
/* SD faild : LED2 blink */
/* FAT faild : LED1 & LED2 blink alternatly */
/* File not found: Both LED blink */
/* Add read capacity function, fix the bug of FAT init */
/* Add slow start up code of VS1003 */
/* */
/* V1.4 */
/* 2007-05-02 */
/* Add enough delay when operate VS1003 */
/* */
/* V1.3 */
/* 2007-04-21 */
/* Modify the retry time of sd reset */
/* Enable some code incase that when FAT initialize */
/* faild program can't jump out the loop */
/* so the error LED can't light up */
/* And light up both leds when FAT_Ini fails */
/* */
/* V1.2: */
/* 2007-04-04: */
/* Add a macro of path */
/* */
/* V1.1: */
/* 2007-02-25 */
/* Change the directory to C:\music\ */
/* A bug fixed */
/* Modify some code to adjust new GCC compiler */
/* */
/* V1.0: */
/* 2006-12-03: */
/* Original Version */
/*******************************************************************/
// F_CPU tells util/delay.h our clock frequency
#define F_CPU 8000000UL // Orangutan frequency (8MHz)
#include<avr/io.h>
#include"MMC_SD/MMC_SD.h" //head files
#include"FAT/FAT.h"
#include"VS1003B/VS1003B.h"
#include<avr/pgmspace.h>
#include <avr/interrupt.h>
#include <util/delay.h>
const unsigned char single_zero_wheel[37]={0,32,15,19,4,21,2,25,17,34,6,
27,13,36,11,30,8,23,10,5,24,
16,33,1,20,14,31,9,22,18,29,
7,28,12,35,3,26};
const unsigned char single_zero_order[37]={0,23,6,35,4,19,10,31,16,27,18,
14,33,12,25,2,21,8,29,3,24,5,
28,17,20,7,36,11,32,30,15,26,
1,22,9,34,13};
#define uint8 unsigned char
#define uint16 unsigned int
#define uint32 unsigned long
#define PATH (unsigned char *)("\\music")
//It's the path where the file placed
//Change it if you want to placed it to anoter foler
//The path should not have blanks, and each foler name's length should less than 8 with no extention
//diagnose and state indicate leds
//at start up this two led indicate error
//at normal they indicate the state of the MODE
#define LED1_CON() DDRC|=_BV(PC5)
#define LED1_ON() PORTC|=_BV(PC5)
#define LED1_OFF() PORTC&=~_BV(PC5)
#define LED2_CON() DDRB|=_BV(PB1)
#define LED2_ON() PORTB|=_BV(PB1)
#define LED2_OFF() PORTB&=~_BV(PB1)
//keys
#define STOP _BV(PD2)
#define MODE _BV(PD3)
#define NEXT _BV(PD7)
#define UP _BV(PD4)
#define DOWN _BV(PD6)
#define PREV _BV(PD5)
#define MP3 1
#define WMA 2
#define MID 3
//mode
#define REPET_ALL 0
#define REPET_ONE 1
#define RANDOM 2
extern uint16 SectorsPerClust;
extern uint16 FirstDataSector; //struct of file information
extern uint8 FAT32_Enable;
struct FileInfoStruct FileInfo;
struct direntry MusicInfo; //the mp3 file item whichi will be played
uint16 totalsongs; //total songs in the root directery on the SD card
uint8 type; //file type
uint8 track[128]; //stroe the information of songs (bit set indicate songs has been played)
void ClearTrackInfo() //cleare the array track[128]
{
uint8 i;
for(i=0;i<128;i++)track[i] = 0;
}
uint8 SetTrack(uint16 songs)//set the track bit, return 1 means the song has been played
{
uint8 byte_offset;
uint8 bit_offset;
songs--;
byte_offset = songs/8;
bit_offset = songs%8;
if(track[byte_offset] & (1<<bit_offset))return 1;
else
{
track[byte_offset] |= 1<<bit_offset;
return 0;
}
}
void Delay(uint16 n)//ÑÓʱ
{
while(n--)asm("nop");
}
//Timer initialization offer seed of the srandom()
void Timer1_Initial()
{
TCNT1H=0x00;
TCNT1L=0x00;
TCCR1B=0x01;//system clock;
ICR1H=0xff;
ICR1L=0xff;
}
void PlaySong(uint16 songs){
uint16 keylen; //ÓÃÓÚ¼ü´¦Àí //for key processing
uint16 count; //Êý¾Ý¼ÆÊý //data counting
uint8 i; //Ñ»·±äÁ¿ //loop variable
uint16 j; //Ñ»·±äÁ¿ //loop variable
uint32 p; //´Øָʾֵ //cluster
uint32 totalsect; //ÎļþÓµÓеÄÉÈÇøÊý //cotain the total sector number of a file
uint16 leftbytes; //Ê£Óà×Ö½Ú //cotain the left bytes number of a file //the last cluster usually not fully occupied by the file
uint8 *buffer; //»º³å //buffer
uint32 sector; //ÉÈÇø //recor the current sector to judge the end sector
uint8 flag; //²¥·Å/ÔÝÍ£±êÖ¾ //flag of pause
// uint16 vol=DefaultVolume;//³õʼÒôÁ¿£¬Ó¦Óëvs1003º¯ÊýÀïµÄ³õʼÒôÁ¿Ïàͬ //default volume
uint8 mode=DEFAULT_MODE;//µ¥ÇúÖظ´ //repet all by default
uint16 songs_cnt = 0; //how many songs have been played
if(totalsongs==0)return;//Èç¹ûûÓиèÇúÔòÒì³£Í˳ö //if no music file return
uint32 rand_val;
Timer1_Initial();//Æô¶¯¶¨Ê±Æ÷£¬ÓÃÓÚ²úÉúËæ»úº¯ÊýµÄÖÖ×Ó //initialize the timer
ClearTrackInfo();
//next://ÏÂÒ»Ê׸èµÄÆðʼµØ·½ //label for "goto"
if(mode==RANDOM)//Ëæ»ú²¥·Å¸èÇú //if the mode is shuffle the songs
{
songs_cnt++;
if(songs_cnt == totalsongs && totalsongs<1025)
{
ClearTrackInfo();
songs_cnt = 0;
}
rand_val = TCNT1;
Delay((random() && 0x00ff));
rand_val <<= 16;
rand_val += TCNT1;
srandom(rand_val);
if(totalsongs>1024)
{
songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ //create random song number
}
while(totalsongs<1025)
{
songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ //create random song number
if(SetTrack(songs) == 0)break;
}
}
count=0;//Çå»ùÊý //clear count
flag=1;
while(count<2048 && (type != MID))//recommand 2048 zeros honoring DREQ befor soft reset
{ //ÓÃÓÚ´ÓwmaÌø³öµ½ÏÂÒ»Ê׸裬ºÍÒ»Ê׸è½áÊøÌî³äÊý¾Ý//midi¸ñʽ²»ÐèÒª
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0)
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00);//Ìî³ä0 //fill 0
count++;
}
if(count == 2047)break;
}
}
VS1003B_SoftReset();//soft reset //in case of playing wma files//Èí¼þ¸´Î»
Search(PATH,&MusicInfo,&songs,&type); //ÕÒµ½ÏàÓ¦µÄÎļþ //find the file
p = MusicInfo.deStartCluster+(((uint32)MusicInfo.deHighClust)<<16);//¶ÁÎļþÊ×´Ø //the first cluster of the file
totalsect = MusicInfo.deFileSize/512; //¼ÆËãÉÈÇøÊý //calculate the total sectors
leftbytes = MusicInfo.deFileSize%512; //¼ÆËãÊ£ÓàµÄ×Ö½ÚÊý //calculate the left bytes
i=0;
sector=0;
while(1)
{
keylen=0;
for(;i<SectorsPerClust;i++) //Ò»¸ö´Ø //a cluster
{
buffer=malloc(512);
FAT_LoadPartCluster(p,i,buffer);//¶ÁÒ»¸öÉÈÇø //read a sector
count=0;
while(count<512)
{
if(flag==0){if(keylen){Delay(100);keylen--;}}
else if(type == MID){if(keylen){Delay(100);keylen--;}}
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag) //¸ù¾ÝÐèÒªËÍÊý¾Ý //send data honoring DREQ
{
for(j=0;j<32;j++) //ÿ´ÎËÍ32¸öÊý¾Ý //32 Bytes each time
{
VS1003B_WriteDAT(buffer[count]);
count++;
}
if(keylen)keylen--; //ÓÃÓÚ¼ü´¦Àí //for key processing
if(sector == totalsect && count >= leftbytes) //Èç¹ûÎļþÒѽáÊø //if this is the end of the file
{
if(type == MID)//waiting the midi file was decoded
{//¶ÔÓÚmidÒôÀÖÒª½Ó×ÅËÍ2048¸öÁã
count=0;
while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
{
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00);
count++;
}
if(count == 2047)break;
}
}
}
i=SectorsPerClust;
break;
}//Îļþ½áÊø //file ended
if(count == 511){break;}//512×Ö½ÚËÍÍêÌø³ö //break if a sector was sent
}
if((PIND&STOP)==0 /*&& keylen==0*/)//²¥·ÅÔÝÍ£¼ü //key PLAY/PAUSE
{
Delay(100);
if(!(PIND&STOP))
{
while(!(PIND&STOP));
if(flag)flag=0;
else flag=1;
Delay(1000);
}
}
}
sector++;
free(buffer);
}
}
}
void PlayMusic()//²¥·ÅÒôÀÖº¯Êý£¬Ò»µ©Ö´Ðв»»áÍ˳ö
{
uint16 keylen; //ÓÃÓÚ¼ü´¦Àí //for key processing
uint16 count; //Êý¾Ý¼ÆÊý //data counting
uint8 i; //Ñ»·±äÁ¿ //loop variable
uint16 j; //Ñ»·±äÁ¿ //loop variable
uint32 p; //´Øָʾֵ //cluster
uint32 totalsect; //ÎļþÓµÓеÄÉÈÇøÊý //cotain the total sector number of a file
uint16 leftbytes; //Ê£Óà×Ö½Ú //cotain the left bytes number of a file //the last cluster usually not fully occupied by the file
uint8 *buffer; //»º³å //buffer
uint32 sector; //ÉÈÇø //recor the current sector to judge the end sector
uint8 flag; //²¥·Å/ÔÝÍ£±êÖ¾ //flag of pause
// uint16 vol=DefaultVolume;//³õʼÒôÁ¿£¬Ó¦Óëvs1003º¯ÊýÀïµÄ³õʼÒôÁ¿Ïàͬ //default volume
uint16 songs=1; //ĬÈϷŵÚÒ»Ê׸è //play the fist songs by default
uint8 mode=DEFAULT_MODE;//µ¥ÇúÖظ´ //repet all by default
uint16 songs_cnt = 0; //how many songs have been played
if(totalsongs==0)return;//Èç¹ûûÓиèÇúÔòÒì³£Í˳ö //if no music file return
uint32 rand_val;
Timer1_Initial();//Æô¶¯¶¨Ê±Æ÷£¬ÓÃÓÚ²úÉúËæ»úº¯ÊýµÄÖÖ×Ó //initialize the timer
ClearTrackInfo();
next://ÏÂÒ»Ê׸èµÄÆðʼµØ·½ //label for "goto"
if(mode==RANDOM)//Ëæ»ú²¥·Å¸èÇú //if the mode is shuffle the songs
{
songs_cnt++;
if(songs_cnt == totalsongs && totalsongs<1025)
{
ClearTrackInfo();
songs_cnt = 0;
}
rand_val = TCNT1;
Delay((random() && 0x00ff));
rand_val <<= 16;
rand_val += TCNT1;
srandom(rand_val);
if(totalsongs>1024)
{
songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ //create random song number
}
while(totalsongs<1025)
{
songs = (uint16)(((random()/214749)*(uint32)totalsongs)/10000)+1;//Ëæ»ú²úÉú¸èÇúÐòºÅ //create random song number
if(SetTrack(songs) == 0)break;
}
}
count=0;//Çå»ùÊý //clear count
flag=1;
while(count<2048 && (type != MID))//recommand 2048 zeros honoring DREQ befor soft reset
{ //ÓÃÓÚ´ÓwmaÌø³öµ½ÏÂÒ»Ê׸裬ºÍÒ»Ê׸è½áÊøÌî³äÊý¾Ý//midi¸ñʽ²»ÐèÒª
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0)
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00);//Ìî³ä0 //fill 0
count++;
}
if(count == 2047)break;
}
}
VS1003B_SoftReset();//soft reset //in case of playing wma files//Èí¼þ¸´Î»
Search(PATH,&MusicInfo,&songs,&type); //ÕÒµ½ÏàÓ¦µÄÎļþ //find the file
p = MusicInfo.deStartCluster+(((uint32)MusicInfo.deHighClust)<<16);//¶ÁÎļþÊ×´Ø //the first cluster of the file
totalsect = MusicInfo.deFileSize/512; //¼ÆËãÉÈÇøÊý //calculate the total sectors
leftbytes = MusicInfo.deFileSize%512; //¼ÆËãÊ£ÓàµÄ×Ö½ÚÊý //calculate the left bytes
i=0;
sector=0;
while(1)
{
keylen=0;
for(;i<SectorsPerClust;i++) //Ò»¸ö´Ø //a cluster
{
buffer=malloc(512);
FAT_LoadPartCluster(p,i,buffer);//¶ÁÒ»¸öÉÈÇø //read a sector
count=0;
while(count<512)
{
if(flag==0){if(keylen){Delay(100);keylen--;}}
else if(type == MID){if(keylen){Delay(100);keylen--;}}
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag) //¸ù¾ÝÐèÒªËÍÊý¾Ý //send data honoring DREQ
{
for(j=0;j<32;j++) //ÿ´ÎËÍ32¸öÊý¾Ý //32 Bytes each time
{
VS1003B_WriteDAT(buffer[count]);
count++;
}
if(keylen)keylen--; //ÓÃÓÚ¼ü´¦Àí //for key processing
if(sector == totalsect && count >= leftbytes) //Èç¹ûÎļþÒѽáÊø //if this is the end of the file
{
if(type == MID)//waiting the midi file was decoded
{//¶ÔÓÚmidÒôÀÖÒª½Ó×ÅËÍ2048¸öÁã
count=0;
while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
{
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00);
count++;
}
if(count == 2047)break;
}
}
}
i=SectorsPerClust;
break;
}//Îļþ½áÊø //file ended
if(count == 511){break;}//512×Ö½ÚËÍÍêÌø³ö //break if a sector was sent
}
if((PIND&STOP)==0 /*&& keylen==0*/)//²¥·ÅÔÝÍ£¼ü //key PLAY/PAUSE
{
Delay(100);
if(!(PIND&STOP))
{
while(!(PIND&STOP));
if(flag)flag=0;
else flag=1;
Delay(1000);
}
}
else if((!(PIND&MODE)) && keylen==0) //ģʽ //mode key
{
Delay(100);
if(!(PIND&MODE))
{
keylen=0xffff;
if(mode==REPET_ALL)
{
mode=REPET_ONE;
LED1_ON();
LED2_OFF();
}
else if(mode==REPET_ONE)//next mode is shuffle
{
mode=RANDOM;
LED1_OFF();
LED2_ON();
srandom(((uint32)TCNT1)<<16);//²úÉúËæ»úÊýµÄÖÖ×Ó
}
else
{
mode=REPET_ALL;
LED1_OFF();
LED2_OFF();
}
}
}
}
sector++;
free(buffer);
}
i=0;
p=FAT_NextCluster(p);//¶ÁÏÂÒ»´ØÊý¾Ý //read next cluster
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//Èç¹ûÎÞºóÐø´ØÔò½áÊø£¬ //no more cluster
{
if(mode==REPET_ALL)songs++;
if(songs>totalsongs)songs=1;
goto next;
}
}
}
//-----------------------------------------
//All to do with ADC......................
//-----------------------------------------
void analog_init(void){
ADCSRA|=(6<<ADPS0)|(1<<ADEN);
}
unsigned int analog10(unsigned char channel)
{
ADMUX &= ~0x1F;
ADMUX |= channel;
ADCSRA |= (1 << ADSC);
while (bit_is_set(ADCSRA, ADSC));
return (ADCL | ADCH << 4); // read ADC (full 10 bits);
}
unsigned int analog8(unsigned char channel)
{
return(analog10(channel) >> 2);
}
//-----------------------------------------
//Finish - All to do with ADC......................
//-----------------------------------------
unsigned int time_ms1 = 0;
unsigned int time_ms2 = 0;
unsigned int wheel_ms1 = 0;
unsigned int wheel_ms2 = 0;
volatile unsigned int timer_tick; //global timer variable MUST BE DECLARED VOLATILE
volatile unsigned int timer_tick_wheel; //global timer variable MUST BE DECLARED VOLATILE
//main function
int main()
{
uint8 retry = 0;
DDRD &= 0x03;//³õʼ»¯¶Ë¿Ú
PORTD |= 0xfc;
LED1_CON();
LED1_OFF();
LED2_CON();
LED2_OFF();
// Initialize the ADC:
analog_init();
OSCCAL = 0x00;//×îСRCÕñµ´ÆµÂÊ //in order to operate some low speed card the initialization should run at lowest speed
Delay(0xffff);
MMC_SD_Init();//³õʼ»¯spi¿Ú //SPI initialize
Delay(0xffff);
if(VS1003B_Init())
{
//LED1_ON();//ÅäÖÃVS1003 //config vs1003
while(1)
{
LED1_ON();
Delay(0xffff);
LED1_OFF();
Delay(0xffff);
}
}
Delay(0xffff);//Ìṩ×ã¹»µÄÑÓʱ //supply enough delay
Delay(0xffff);
Delay(0xffff);
Delay(0xffff);
Delay(0xffff);
while(MMC_SD_Reset())//³õʼ»¯SD¿¨ //sd card initialize
{
retry++;
if(retry>20)
{
// LED2_ON();
while(1)
{
LED2_ON();
Delay(0xffff);
LED2_OFF();
Delay(0xffff);
}
}
}
OSCCAL = 0xff;//×î´óRCÕñµ´ÆµÂÊ //normal operation maximum the frequency
Delay(0xffff); //wait for stable
if(FAT_Init())//³õʼ»¯Îļþϵͳ Ö§³ÖFAT16ºÍFAT32 //initialize file system FAT16 and FAT32 are supported
{
// LED1_ON();
// LED2_ON();
// while(1);
while(1)
{
LED1_ON();LED2_ON();
Delay(0xffff);
LED1_OFF();LED2_OFF();
Delay(0xffff);
}
}
Search(PATH,&MusicInfo,&totalsongs,&type);
//search the songs in the root directery on the SD card
//You can also specify the directery where the songs are placed
//eg: Search("\\new\\mp3",&MusicInfo,&totalsongs,&type);
// means search the file in the foler C:\new\mp3
DDRC &= ~(1 << PD6);
PORTD|=(1<<PD6);
DDRC &= ~(1 << PD7);
PORTD|=(1<<PD7);
DDRC &= ~(1 << PD5);
PORTD|=(1<<PD5);
//initialize timer 0
TCNT0=~(124);//preload counter to overflow after 1 ms (125 counts)
TIMSK0=(1<<TOIE0);//enable interrupt on timer0 overflow
TCCR0B=(1<<CS01)|(1<<CS00);//set timer to normal mode with CPU clock/64 (125 kHz)
sei();//enable all interrupts
// time an event:
timer_tick=0;
timer_tick_wheel=0; //start timer, clear global millisecond counter
TCNT0 = ~(124);
while(1){
//ball speed first
time_ms1 = 0;
time_ms2 = 0;
while (PIND&(1<<PD7)); // loop here until first button press
TCNT0 = 0;
timer_tick=0;// here is where we start timing
_delay_ms(1); // delay for 1 ms to debounce button press
while (!(PIND&(1<<PD7))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
while (PIND&(1<<PD7)); // loop here until second button press
time_ms1 = timer_tick; //get the value of the millisecond counter
timer_tick=0;// here is where reset the timer
_delay_ms(1); // delay for 1 ms to debounce button press
while (!(PIND&(1<<PD7))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
while (PIND&(1<<PD7)); // loop here until 3rd button press
time_ms2 = timer_tick; //get the value of the millisecond counter
// lcd_line1();// display the times
// lcd_time(time_ms1);
// lcd_line2();
// lcd_time(time_ms2);
_delay_ms(1000); // delay for 10 ms to debounce button release
// lcd_clear();
}
//wheel speed second
{
wheel_ms1 = 0;
wheel_ms1 = 0;
while (PIND&(1<<PD7)); // loop here until first button press
TCNT0 = 0;
timer_tick_wheel=0;// here is where we start timing
_delay_ms(1); // delay for 1 ms to debounce button press
while (!(PIND&(1<<PD7))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
while (PIND&(1<<PD7)); // loop here until second button press
wheel_ms1 = timer_tick_wheel; //get the value of the millisecond counter
timer_tick_wheel=0;// here is where reset the timer
_delay_ms(1); // delay for 1 ms to debounce button press
while (!(PIND&(1<<PD7))); // loop here until button is released
_delay_ms(10); // delay for 10 ms to debounce button release
while (PIND&(1<<PD7)); // loop here until 3rd button press
wheel_ms2 = timer_tick_wheel; //get the value of the millisecond counter
// lcd_line1();// display the times
// lcd_time(wheel_ms1);
//lcd_line2();
//lcd_time(wheel_ms2);
_delay_ms(1000); //for button debounce
//lcd_clear();
PlayMusic();
while(1)
{
while(1)
{
LED1_ON();LED2_OFF();
Delay(0xffff);
LED2_ON();LED1_OFF();
Delay(0xffff);
}
}
return 0;
}
}
/*
TIMER 0 overflow interrupt service routine
This routine is called every millisecond
Operation: increment global variable timer_tick, reload TCNT0 to count 125 clock cycles
*/
ISR(TIMER0_OVF_vect)
{
timer_tick++;
timer_tick_wheel++;
TCNT0 = ~(125); //preload counter to overflow after 1 ms (125 counts)
}
but that led does come on again with this program…