.: EMICROS :.  Embedded Micro Software
Home CAN232 CANUSB I2C232 I2CUSB CanWiser Learn C
Add your text here
Contact

Email : info@emicros.com

Ordering Information

.: Ordering using our PayPal powered shopping cart (PayPal account not required).

CAN232 : $79
CANUSB : $89
I2C232 : $79

I2CUSB : $89

Click here to View Cart and check out.

 

 

 

 
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;
       }

   }
}

 
 
Copyright 2010 Embedded Micro Software. All rights reserved