Question: I already finished the source but i couldnt combine these source please help me ( i use atmega 128 program at codevision. And simulate at

I already finished the source but i couldnt combine these source please help me
( i use atmega 128 program at codevision. And simulate at Proteus)
1. if any button SW0~SW7 ,Create a program that sound and LED like a button on a scale.
#include
void delay(int I) //time delay function
{
while(i--);
}
void main(void)
{
DDRC=0xFF; //LED control setting
PORTC=0xFF; //Setting LED as a Output port
DDRD=0x00; //Setting tact swtich as a input Port
DDRG=0xFF; //setting speaker as a output port
while(1)
{
if (PIND==(0x7F)) //If press button SW7 create a program that sounds like a button on a scale and LED
{
PORTC=0x7F;
PORTG=0x00;
delay(3906*0.5);
PORTG=0x01;
delay(3906*0.5);
}
if (PIND==0xBF) ////If press button SW6 create a program that sounds like a button on a scale and LED
{
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);
}
}
}
2. If press button SW0&SW1 create a program that time clock would be shown.
#include
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;
int switch [8]={0x7E, 0xBF, 0xDF, 0xE7, 0xFB, 0xFD, 0xFE};
void main()
{
DDRA=0xFF;
PORTA=0XFF;
DDRB=0xFF;
PORTB=0xFF;
DDRD=0x00;
TCCR0=0x04;
TIMSK=0x01;
SREG=0x80;
while(1){}
}
interrupt[TIM0_OVF]void timer0_ovf_isr()
{
TCNT0=0x06;
if(PIND==0xFC)
{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;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!