CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Code conversion

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

Code conversion
PostPosted: Sat Apr 22, 2006 12:46 pm     Reply with quote

Hi does any know how to convert this code to ccs code ? i want scan knight rider light left to right . I have tried but faild ! Sad

[/code]void main()
{
trisb = 00000000b; // set port b to output
trisa= 11111111b; // set port a to inputs
char data = 00000001b; // initial data.
bool movingRight = true;

while( 1 )
{
bit button = porta.0;
// portb = 00111111;//data; // update port

delay_ms( 50 );
// if (button==1)
portb=data; // update port


{
if( movingRight )
{
data <<= 1;
if( data.5 ) // msb set
movingRight = false;
}
else
{
data >>= 1;

if( data.0 ) // lsb set
movingRight = true;
}
}
}
}
Code:
Guest








PostPosted: Sat Apr 22, 2006 1:59 pm     Reply with quote

This should do want you want. Uncomment to control activity on port B through a logic level input to pin A0.

Code:

#include <your_mcu_here.h>
#use delay(clock=your_oscillator_frequency_here)


void main(void)
{
   int data;
   int1 movingRight;

   set_tris_a(0xFF);      // Set port A to all input
   set_tris_b(0x00);      // Set port B to all output

   data = 1;            
   movingRight = FALSE;

   while(TRUE)
   {
//      if(input(PIN_A0))
//      {
         output_b(data);
      
         if(movingRight)
            data >>= 1;
         else
            data <<= 1;

         if(data == 0x80)
            movingRight = TRUE;
         else if(data == 0x01)
            movingRight = FALSE;
      
         delay_ms(50);
//      }
      }
}
deltatech



Joined: 22 Apr 2006
Posts: 87

View user's profile Send private message

PostPosted: Sat Apr 22, 2006 4:10 pm     Reply with quote

Who ever you are . Your are great many thanks . I spent all day and i couldnt get it to work . but then i am a newbie . Once again many thanks Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group