There are 2 parts for this Code. 1. Add a delay at the appropriate point in this
ID: 3632107 • Letter: T
Question
There are 2 parts for this Code.1. Add a delay at the appropriate point in this program to make the binary value displayed change in an easy-to-predict way each time you activate dipswitch 8.
2. Add a 2 second delay in the while loop to slow the counter down. This is enough time to set switch 8 in intervals that causes the LEDs to count up one at a time.
Here is the code to modify:
//RAM variables
char var1; // holds current value of incrementing variable
//function prototypes
void init_PortH_INT(void);
void delay(int); // you figure out where to use it!
//Main Function
void main(){
DDRB = 0xff; // initialize Port B
DDRJ = 2;
PTJ = 0;
init_PortH_INT();
while(1){ // resume auto-incrementing value in var1
var1++;
} /* a repetitive task is performed by main */
}
/***************** function *******************/
#pragma CODE_SEG NON_BANKED
interrupt 25 void PortH_ISR (void){ //(((0x10000-Vporth)/2)-1)
PORTB = var1; // latch current value of var1 to Port B
PIFH |= 0x80; // clear port interrupt flag
}
#pragma CODE_SEG DEFAULT
void init_PortH_INT( ){ // dipswitch 8 becomes FE trig for INT
asm(sei);
DDRH &= ~0x80; // PH7 inputs (dipswitch 8)
PPSH = 0x00; // define FE trigger for INT (PH7, etc.)
PIFH |= 0x80; // clear port INT flag by sending a '1'
PIEH |= 0x80; // enable PH7 for port INT
asm(cli);
}
void delay(int del){ // delay for 'del' msecs
int i,j;
for(i=0; i<del; i++)
for(j=0; j<4000; j++);
}
Explanation / Answer
//RAM variables
char var1; // holds current value of incrementing variable
//function prototypes
void init_PortH_INT(void);
void delay(int); // you figure out where to use it!
//Main Function
void main(){
DDRB = 0xff; // initialize Port B
DDRJ = 2;
PTJ = 0;
init_PortH_INT();
/******* Here is modification**************/
while(1){ // resume auto-incrementing value in var1
var1++;
} /* a repetitive task is performed by main */
}
/***************** function *******************/
#pragma CODE_SEG NON_BANKED
interrupt 25 void PortH_ISR (void){ //(((0x10000-Vporth)/2)-1)
PORTB = var1; // latch current value of var1 to Port B
PIFH |= 0x80; // clear port interrupt flag
}
#pragma CODE_SEG DEFAULT
void init_PortH_INT( ){ // dipswitch 8 becomes FE trig for INT
asm(sei);
/*********** use diyal hare***********/
DDRH &= ~0x80; // PH7 inputs (dipswitch 8)
PPSH = 0x00; // define FE trigger for INT (PH7, etc.)
PIFH |= 0x80; // clear port INT flag by sending a '1'
PIEH |= 0x80; // enable PH7 for port INT
asm(cli);
}
void delay(int del){ // delay for 'del' msecs
int i,j;
for(i=0; i<del; i++)
for(j=0; j<4000; j++);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.