Question

17. Write a C program to toggle bits PB1 and PB7. - 18. Write a C program to toggle only bit PBO. 19. Write a C program to co
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please upvote ,comment if any query . Thanks .

Note : code compiled and tested in programmer's notepad AVR.

Question 17 : toggle PB1 and PB7

/*

if we connect LED on PB1 and PB7 it will turn on and off led at every second.

*/

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


int main(void)
{
  
DDRB|=(1<<DDB1)|(1<<DDB7); //set output pin PB1 and PB7
PORTB^=((1<<PB1)|(1<<PB7)); //toggle pin PB1 and PB7
  
   while(1)
   {
       //in while loop it will toggle PB1 and PB7 pin every second
      
       PORTB^=((1<<PB1)|(1<<PB7));
       _delay_ms(1000);
   }

}

Question 18 : toggle only PB0

//it will turn on and off PB0 pin connected LED at every second

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


int main(void)
{
  
DDRB|= (1<<DDB0); //set output pin PB0
PORTB^=(1<<PB0); //toggle the pin PB0
  
  
   while(1)
   {
       //in while loop it will toggle PB0 pin every second
      
       PORTB^=(1<<PB0);
       _delay_ms(1000);
   }

}

Question 19 : set counter value from 0-99 on PORTB

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


int main(void)
{
  
int i;

DDRB= 0xff; //set output complete PORTB

PORTB=0x00; //set low on PORTB
  
  
   for(i=0;i<=99;i++)
   {
       PORTB=i; //assign value to PORTB every 200ms
      
       _delay_ms(200);
      
   }

}

Program 17 :

#include<avr/io.h> #include<util/delay.h> #include<avr/interrupt.h> int main(void) { DDRB |=(1<<DDB1) |(1<<DDB7); //set outpu

Program 18 :

#include<avr/io.h> #include<util/delay.h> #include<avr/interrupt.h> int main(void) DDRB = (1<<DDBO); PORTBA=(1<<PB0); //set o

Program 19 :

#include<avr/io.h> #include<util/delay.h> #include<avr/interrupt.h> int main(void) { int i; DDRB= Oxff; PORTB=0x00; //set out

Add a comment
Know the answer?
Add Answer to:
17. Write a C program to toggle bits PB1 and PB7. - 18. Write a C...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT