Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to add 16 bit timer here is my program . timer0 is 8bit timer only work f

ID: 3902753 • Letter: I

Question

I want to add 16 bit timer here is my program . timer0 is 8bit timer only work for FND i want to add 16 bit timer which is only work for buzzer (PORTG) how can i add ? soundscale C (do)'s frequency is 3906. #include<io.h> #include<delay.h> 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); }
} I want to add 16 bit timer here is my program . timer0 is 8bit timer only work for FND i want to add 16 bit timer which is only work for buzzer (PORTG) how can i add ? soundscale C (do)'s frequency is 3906. #include<io.h> #include<delay.h> 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); }
} I want to add 16 bit timer here is my program . timer0 is 8bit timer only work for FND i want to add 16 bit timer which is only work for buzzer (PORTG) how can i add ? soundscale C (do)'s frequency is 3906. #include<io.h> #include<delay.h> 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); }
}

Explanation / Answer

Sol: Try this. It should work.

#include<io.h>

#include<delay.h>

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);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote