Question
can you please solve in c and clear
1 - General purpose eneral purpose 1/0 [30 pts re going to use the DDR, PORT, and PIN registers from your AVR device ions are
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer : please up vote or comment for any query i will update the same . Thanks.

Note : ---- please disable JTAG using FUSE bit while compiling program or manually setting fuse bit otherwise program will not work on PORTC .

Program Plan :

1. set Switch as INPUT and turn on pull up resistor

2. set OUTPUT all three LED PINS

3. check for switch PIN went LOW to TURN ON LED

4. increment count variable when switch pressed and write count value to PORTC

Program :

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

void PORTInit(void);

int main(void)
{
int count=0;
PORTInit();
  
  
while(1) //infinite loop
{
if(PINC & (1<<PC3) == 0) //If switch is pressed detect LOW
{
count++;//increment count
PORTC=count;//write switch counter to port c
  
PORTC|=(1<<PC3); //above line may reset pull up so re initialize
if(count==8) //more than 8 will not affect PORTC LED PINS so again zero
{
count=0;   
}
  
_delay_ms(300); //300 milli second delay for debounce
}
}
}


void PORTInit(void)
{
DDRC|=(1<<PC0)|(1<<PC1)|(1<<PC2); //set LED0 ,LED1 and LED2 as output
DDRC&=~(1<<PC3); //set switch as input PORTC pin3
PORTC|=(1<<PC3); //pull up enable for switch
  
}

Add a comment
Know the answer?
Add Answer to:
can you please solve in c and clear 1 - General purpose eneral purpose 1/0 [30...
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