Question

In: Computer Science

Answer the following question from the perspective of AVR (C language) How to set the data...

Answer the following question from the perspective of AVR (C language)

How to set the data direction (output/input) in (AVR, c language)?

Write a statement to turn ON a pin, say D3.

Write a statement to turn OFF a pin, say D3.

How to toggle a pin?

Solutions

Expert Solution

Answer: Please upvote if its upto your expectation or comment for any Query. Thanks

Note :-

1. We are using Atmega32 avr micro controller .

2. LED connected on pin number 3 of PORTD please check image for hardware connection.

3. To blink led we have to make this pin Output .

Program Plan :

1. Define Header file of AVR.

2. Define Micro controller frequency .

3. Make output to the pin .

4. set high on pin to turn on led ,low for turn off led and for blinking for a period make it toggle

Program :

1. Set output the Pin -> set 1 in DATA Direction Register(DDRD) of PORTD

  DDRD|=(1<<3); //output the PORTD.3 pin   

D3 means PIN 4 of PORTD so to effect particular pin we are shifting lef by 1 for 4 number pin . using OR sign to not effect the other pin of PORT.

  

2. Set Input -> set 0 in DDRD of PORTD

DDRD&=~(1<<3) //input the PORTD.3 pin

it will set 0 the D3 pin using AND operation to do not effect other pin .

3. Turn on D3 pin of PORTD

PORTD|=(1<<3) //set 1 to turn on led

4. Turn of D3 pin of PORTD

PORTD&=~(1<<3) //set 0 to turn off led

5. toggle the D3 pin

PORTD^=(1<<3) //toggle the D3 means EX-OR of status of pin

it will EXOR the value of PORTD3 pin value .

Program :

this program will turn on and off the led for 1 second .

#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif

#include <avr/io.h> //avr header file
#include <util/delay.h>

int main(void)
{
DRRD|=(1<<3) //Output
  
while(1) //infinite loop
{
PORTD|=1<<3 //turn on led
_delay_ms(1000); //1 second delay
PORTD&=~1<<3 //turn off led
_delay_ms(1000); //1 second delay
     
}


Related Solutions

Question 1: Answer the following questions related to AVR Timer/counter: Write an AVR program that flashes...
Question 1: Answer the following questions related to AVR Timer/counter: Write an AVR program that flashes an LED (PC0) every 6 ms using CPU clock frequency of 32 kHz and TIMER0. Use Timer/Counter0 Overflow Flag (TOV0) in your code. Write an AVR program that flashes an LED (PC0) every 2 seconds using XTAL clock frequency of 16MHz and Timer1. Use Timer/Counter1 Overflow Flag (TOV1) in your code.
How effective is monetary policy? Answer this question from the perspective of (a) keynes, (b) the...
How effective is monetary policy? Answer this question from the perspective of (a) keynes, (b) the classical economists, (c) the monetarists and (d) modern money theory . How would you judge “ effectiveness”?
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and...
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and Port B and LED’s with PORTD. Write a code to read input from PortB and C and perform following. Addition of both inputs, Subtraction, Multiplication, Division, And, Or, Nor,Xor. (b)- A switch is connected to PD0 and LED’s to Port B and Port C. Write a code to perform following: When switch is 0 send your roll number to Port B. When Switch is...
Use the following set of data to answer the question: is there a significant association between...
Use the following set of data to answer the question: is there a significant association between an immigrant’s length of time in the country and his/her level of acculturative stress, as measured by a well-being scale? The data are listed in the table below. Years Well-being In country score X Y 12 6 15 8 9 4 7 5 18 9 24 10 15 7 16 6 21 3 15 9 M = 15.20 M = 6.70 SSx = 235.60...
Answer the following bootstrap question by showing the R code : A set of data X...
Answer the following bootstrap question by showing the R code : A set of data X contains the following numbers: 119.7 104.1 92.8 85.4 108.6 93.4 67.1 88.4 101.0 97.2 95.4 77.2 100.0 114.2 150.3 102.3 105.8 107.5 0.9 94.1 We generated n = 20 observations Xi = 10 Wi+100, where Wi has a contaminated normal distribution with proportion of contamination 20% and σc = 4. Suppose we are interested in testing: H0 : μ = 90 versus H1 :...
The data set for this question set (Tab Q1 in the Excel data file) comes from...
The data set for this question set (Tab Q1 in the Excel data file) comes from a research project that tracks the elderly residents in a community to monitor their cognitive function and general health. Based on the literature, education is considered a protective factor against dementia, and memory decline is usually the first sign of dementia. So the researchers would like to know whether education level (measured in number of years of formal schooling) is correlated with memory function...
From a recreational perspective/class, please answer the following in a thoughtful way (One paragraph per question):...
From a recreational perspective/class, please answer the following in a thoughtful way (One paragraph per question): *How is individual identity devlopment influenced by leisure or what effect/influence does leisure have in individual identity development? -Describe how leisure activities might look like through a person's lifespan and how they change as a person ages. -Describe how identity symbols can indicate a person's leisure interests. -Describe how leisure can influence a persons's identity development.
Question Set 5: Economic Growth Explain how each of the following elements from Question Set 1...
Question Set 5: Economic Growth Explain how each of the following elements from Question Set 1 will affect long-run economic growth in the United States: American’s low savings rate. Rising government deficits in the U.S. Foreign savings flowing into the U.S. U.S. business firms’ unwillingness to undertake domestic investment.
Using c programming language How do you put data from a text file into a 2d...
Using c programming language How do you put data from a text file into a 2d array For example a text file with names and age: john 65 sam 34 joe 35 sarah 19 jason 18 max 14 kevin 50 pam 17 bailey 38 one 2d array should have all the names from the file and one 2d array should have all the ages and both arrays should be printed out separately and be 3x3
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT