Question

In: Electrical Engineering

This is a atmega128 source to make a clock using the timer interrupt. I want to...

This is a atmega128 source to make a clock using the timer interrupt. I want to add source if i press switch (PIND==0x0FE&&PIND==0x0FD) then below program would be running .

#include<io.h>
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 main()
{
DDRA=0xFF;
PORTA=0XFF;
DDRB=0xFF;
PORTB=0xFF;
TCCR0=0x04;
TIMSK=0x01;
SREG=0x80;
while(1){}
}
interrupt[TIM0_OVF]void timer0_ovf_isr()
{
TCNT0=0x06;
PORTA=BJT[position];
if(position==0)number=sec%10;
if(position==1)number=sec/10;
if(position==2)number=min%10;
if(postion==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;
}


Solutions

Expert Solution

/*
        Generating 10 ms delay pulse on PORTB using ATmega128 Timer interrupt
 */ 


#include <avr/io.h>
#include <avr/interrupt.h>

/* timer0 overflow interrupt */
ISR(TIMER0_OVF_vect)
{
        PORTB=~PORTB;           /* Toggle PORTB */
        TCNT0 = 0xB2;
}
(PIND==0x0FE&&PIND==0x0FD)
{

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 main()

{

DDRA=0xFF;

PORTA=0XFF;

DDRB=0xFF;

PORTB=0xFF;

TCCR0=0x04;

TIMSK=0x01;

SREG=0x80;

while(1){}

}

interrupt[TIM0_OVF]void timer0_ovf_isr()

{

TCNT0=0x06;

PORTA=BJT[position];

if(position==0)number=sec%10;

if(position==1)number=sec/10;

if(position==2)number=min%10;

if(postion==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;

}


}

}

int main( void )
{
if
{
        DDRB=0xFF;              /* Make port B as output */

        sei();
        TIMSK=(1<<TOIE0);         /* Enable Timer0 overflow interrupts */
                
        TCNT0 = 0xB2;           /* Load TCNT0, count for 10ms*/
        TCCR0 = (1<<CS02) | (1<<CS00); /* Start timer0 with /1024 prescaler*/
        while(1);
}

Related Solutions

We want to design a simple "four clock pulse" timer circuit. In addition to the clock...
We want to design a simple "four clock pulse" timer circuit. In addition to the clock input, the timer has a "Restart" input (R), three "data" outputs (ABC) which indicate the count, and one "beeper" output (D). The behavior of the circuit is as follows: Idle Mode The timer output is ABC=100 and the beeper is off (D=0) as long as R=0. If R=1 on any clock edge in this mode, the timer goes into the... Restart/Hold Mode The timer...
1-Which of the following algorithms cannot be implemented without using the timer interrupt? a. RR b....
1-Which of the following algorithms cannot be implemented without using the timer interrupt? a. RR b. SJF c. Priority d. FCFC 2-A program that performs mostly arithmetic or scientific calculations is considered as? a. CPU bound b. I/O bound 3-Operating System is: a. System processes that manages hardware resources b. System processes that provide services to the user application programs c. Interface between the hardware and user processes d. All the above e. Not of the above 4-A goal of...
V. How does ARM processor differentiate between a timer interrupt and an A/D interrupt? VI. What...
V. How does ARM processor differentiate between a timer interrupt and an A/D interrupt? VI. What does privileged mode mean and what is the major difference between this mode and non-privileged mode? VII. There are two interrupt pins on ARM microprocessor: IRQ and FIQ. Which one can interrupt the other one and why?
1. Design a clock generator using a 555 timer with a frequency of 1 Hz (any...
1. Design a clock generator using a 555 timer with a frequency of 1 Hz (any duty cycle is OK). Use resistor values between 1k and 1M and use capacitor values available in lab (see table in “Pinouts.doc available on course Canvas site). Show your calculations for RA, RB, and C. Clearly show all formulas and calculations and state when you are arbitrarily picking a value. (DONE) 2. Select the nearest standard 5% resistor values to the values for RA...
Atmega128 and Pic24e have the reset interrupt at the program address 0x0. Write a function reset()...
Atmega128 and Pic24e have the reset interrupt at the program address 0x0. Write a function reset() that works for both chips to reset a program.
Atmega128 and Pic24e have the reset interrupt at the program address 0x0. Write a function reset()...
Atmega128 and Pic24e have the reset interrupt at the program address 0x0. Write a function reset() that works for both chips to reset a program.
What is an interrupt vector table. How do I create an interrupt vector table in Arm...
What is an interrupt vector table. How do I create an interrupt vector table in Arm Architecture . Please include as much information as you can, including pictures, examples etc. Thank you very much.
Problem 2. Interrupt-driven I/O (20 pt.) Consider a system employing interrupt-driven I/O for a particular device...
Problem 2. Interrupt-driven I/O (20 pt.) Consider a system employing interrupt-driven I/O for a particular device that transfers data at an average of 2000 bytes/sec on a continuous basis. a. Assume that interrupt processing takes about 200 usec (i.e., the time to jump to the interrupt service routine (ISR), execute it, and return to the main program). Determine what fraction of processor time is consumed by this I/O device if it interrupts for every byte. b. Now assume that the...
Please perform the following tasks using a Timer Control: When an NO Push Button (I:0/0) is...
Please perform the following tasks using a Timer Control: When an NO Push Button (I:0/0) is pressed (I0) and released, a Pilot Light (O:0/0) will be on and after 7 seconds (T4:0), a single-active cylinder will be pushed forward. The piston will remain at its position for another 5 seconds (T4:1) and then it will automatically retract. The pilot light will be off and the timer will also be automatically reset. The whole cycle can then be repeated.
What is the viscosity of blood? I will make a fluid and I want to simulate...
What is the viscosity of blood? I will make a fluid and I want to simulate the viscosity of blood with glucose, how much glucose I will need?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT