| Answer:
The first thing to change is to turn on the most
significant bit (BIT7) in PORTB. We do this by setting
x to 0x80.
Instead of left shifting, now we need to right
shift requiring us to change the statement;
x <<= 1
to x >>= 1.
Finally in the if statement x is checked against
0x08 and if true x is reset to 0x80. |
#include
<htc.h>
#include "delay.h"
//----------------------------------
// file: led4_4.c
// description: This is the C code
// for the 4 LED project
// author: Emicros
//----------------------------------
unsigned char x;
/*----------------------------------
** function: TimerISR
** description: This is just a place
** holder for now and isn't used
** in the program.
**--------------------------------*/
void interrupt TimerISR( void )
{
if( (TMR1IE)
&& (TMR1IF) )
{
TMR1IF
= 0;
}
}
/*----------------------------------
** function: main()
** description: Main function.
**---------------------------------*/
void main( void )
{
TRISB =
0x00;
x =
0x80;
while( 1
)
{
PORTB
= x;
delay_ms(
50 );
x
>>= 1;
if(
x == 0x08 )
{
x
= 0x80;
}
}
} |