Question
I usually use atmega128 codevision I finally finished coding and exactly write the speaker code sound scale output if i press swtich Please help me.
I usually use atmega128 codevision I finally finished coding and exactly write the speaker code sound scale output if i press swtich Please help me. #include #include int AD_volt=0; int position=0,BJT[4]={0xFE,0xFD,0xFB,0xF7}; int number=0,segment[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; int msec=0, sec=0, min=0;
void delay(int i) //time delay function { while(i--); }
void main() { ADMUX=0x00; ADCSRA=0x87; delay_ms(5); DDRE=0x03; DDRC=0xFF; //LED control PORTC=0xFF; // DDRD=0x00; // DDRG=0xFF; //setting speaker a DDRA=0xFF; PORTA=0XFF; DDRB=0xFF; PORTB=0xFF; DDRD=0x00; TCCR0=0x04; TIMSK=0x01; SREG=0x80; while(1){ PORTE=0x01; delay_ms(5000); PORTE=0x00; delay_ms(5000); PORTE=0x02; delay_ms(5000); PORTE=0x00; delay_ms(5000);} } interrupt[TIM0_OVF]void timer0_ovf_isr() { TCNT0=0x06; if(PIND==0xFC) { AD_volt=(ADCL)+(ADCH<<8); //??10??????? ADCSRA=0xC7; PORTC=(AD_volt>>2); PORTA=BJT[position]; if(position==0)number=sec%10; if(position==1)number=sec/10; if(position==2)number=min%10; if(position==3)number=min/10; PORTB=segment[number]; position++; if(position>3)position=0; msec++; if(msec==1000) { msec=0; sec++; } if(sec==60) { sec=0; min++; } if(min==60)min=0; } if (PIND==(0x7F)) { PORTC=0x7F; PORTG=0x00; delay(3906*0.5); PORTG=0x01; delay(3906*0.5); } if (PIND==0xBF) { PORTC=0xBF; PORTG=0x00; delay(3906*0.5333); PORTG=0x01; delay(3906*0.5333); } if (PIND==0xDF) { PORTC=0xDF; PORTG=0x00; delay(3906*0.6); PORTG=0x01; delay(3906*0.6); } if (PIND==0xEF) { PORTC=0xEF; PORTG=0x00; delay(3906*0.6666); PORTG=0x01; delay(3906*0.6666); } if (PIND==0xF7) { PORTC=0xF7; PORTG=0x00; delay(3906*0.75); PORTG=0x01; delay(3906*0.75); } if (PIND==0xFB) { PORTC=0xFB; PORTG=0x00; delay(3906*0.8); PORTG=0x01; delay(3906*0.8); } if (PIND==0xFD) { PORTC=0xFD; PORTG=0x00; delay(3906*0.8888); PORTG=0x01; delay(3906*0.8888); } if (PIND==0xFE) { PORTC=0xFE; PORTG=0x00; delay(3906); PORTG=0x01; delay(3906); }
}
#include
void delay(int i) //time delay function { while(i--); }
void main() { ADMUX=0x00; ADCSRA=0x87; delay_ms(5); DDRE=0x03; DDRC=0xFF; //LED control PORTC=0xFF; // DDRD=0x00; // DDRG=0xFF; //setting speaker a DDRA=0xFF; PORTA=0XFF; DDRB=0xFF; PORTB=0xFF; DDRD=0x00; TCCR0=0x04; TIMSK=0x01; SREG=0x80; while(1){ PORTE=0x01; delay_ms(5000); PORTE=0x00; delay_ms(5000); PORTE=0x02; delay_ms(5000); PORTE=0x00; delay_ms(5000);} } interrupt[TIM0_OVF]void timer0_ovf_isr() { TCNT0=0x06; if(PIND==0xFC) { AD_volt=(ADCL)+(ADCH<<8); //??10??????? ADCSRA=0xC7; PORTC=(AD_volt>>2); PORTA=BJT[position]; if(position==0)number=sec%10; if(position==1)number=sec/10; if(position==2)number=min%10; if(position==3)number=min/10; PORTB=segment[number]; position++; if(position>3)position=0; msec++; if(msec==1000) { msec=0; sec++; } if(sec==60) { sec=0; min++; } if(min==60)min=0; } if (PIND==(0x7F)) { PORTC=0x7F; PORTG=0x00; delay(3906*0.5); PORTG=0x01; delay(3906*0.5); } if (PIND==0xBF) { PORTC=0xBF; PORTG=0x00; delay(3906*0.5333); PORTG=0x01; delay(3906*0.5333); } if (PIND==0xDF) { PORTC=0xDF; PORTG=0x00; delay(3906*0.6); PORTG=0x01; delay(3906*0.6); } if (PIND==0xEF) { PORTC=0xEF; PORTG=0x00; delay(3906*0.6666); PORTG=0x01; delay(3906*0.6666); } if (PIND==0xF7) { PORTC=0xF7; PORTG=0x00; delay(3906*0.75); PORTG=0x01; delay(3906*0.75); } if (PIND==0xFB) { PORTC=0xFB; PORTG=0x00; delay(3906*0.8); PORTG=0x01; delay(3906*0.8); } if (PIND==0xFD) { PORTC=0xFD; PORTG=0x00; delay(3906*0.8888); PORTG=0x01; delay(3906*0.8888); } if (PIND==0xFE) { PORTC=0xFE; PORTG=0x00; delay(3906); PORTG=0x01; delay(3906); }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started