The following c pro includes at least 10 basic either as: syntax errors code the
ID: 2084378 • Letter: T
Question
The following c pro includes at least 10 basic either as: syntax errors code the compiler will not understand) or simple programming/logic errors. (code that will compile but not work as expected) The purpose of this program is to produce a pulse Width Modulated output on a pin, where the ON time is proportional to the 8 bit value read from PORTB. The shortest pulse is produced for an input value 1 and longest pulse for an input value 255. The program is to loop endlessly turning on (1) PORTC bit 1 at count 0, then turning off (0) PORTC bit 1 when count equals the value read in from PORTB. The counter is to count on to 255 before the This is shown diagrammatically as an example below. include void main(void) { initialise 0: PORTB = val: while(0) { for (count 0: countExplanation / Answer
First Lets start my identifying the mistakes :
Thus I have given below the corrected code for your reference :
#include<xc.h>
void main(void)
{
int initialise();
char val = 0 ,count = 0;
while(0)
{
val = PORTB ;
for(count = 0;count <= 255;count++)
{
if(count <= val)
PORTC = 0x01
else
PORTC = 0x00 ;
}
}
}
int initialise(void)
{
TRISB = 0xFF;
TRISC = 0x00;
return 0;
}
Comment if any further assistance required.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.