Jump to content
Sign in to follow this  
bsnedek

need some input

Recommended Posts

Good Day All,

  Ok, got some goodies up and running in C. Real nice compiler C2C. Anyway

  Have a function I'm tring to build to read PortA pin 1 and build a char out of repeated reads. Found a snipit from a programmer using CCS. He uses a function called shift_right(data,n,input).

 

I am having trouble replicating this.

 

For(x=1;x<=num to read;x++) {

   data = data >> 1;

   data = input_pin_Port_a(1);

}

return (data>>8-x);

 

It seems to be simple enough but I get all kinds of missdirects

and general syntax issues.

 

TIA

  Brad  :D

Share this post


Link to post
Share on other sites
Guest ysj

try these code

//////////////////////////////////////////

//  ccs to c2c convet

//////////////////////////////////////////

#define output_high(x) set_bit(x)

#define output_low(x) clear_bit(x)

 

#define output_bit(x,y)  if(y) set_bit(portd,x); else clear_bit(portd,x);

#define input(x) input_pin_port_b(x)

/*******************************************

#define input(x,y) (x&(1<

output_bit(LED, input(data, bit)

********************************************/

#define ELEMT 3

char buffer[ELEMT];

 

 

/*********************************************/

char shift_left(char var, char bytes, char bit) {

/*********************************************/

buffer[0] = var;

asm {

bsf _status, C

btfss   param02_shift_left, 0

bcf _status, C

btfsc param01_shift_left, 0

goto $+3

btfsc param01_shift_left, 1

goto $+5

btfsc param01_shift_left, 1

goto $+6

rlf _buffer, F

goto $+7

rlf _buffer, F

rlf _buffer+1, F

goto $+4

rlf _buffer, F

rlf _buffer+1, F

rlf _buffer+2, F

btfss   _status, C

retlw 0

retlw   1

}

}

 

/*********************************************/

void shift_right(char var, char bytes, char bit) {

/*********************************************/

buffer[ELEMT-1] = var;

asm {

bsf _status, C

btfss   param02_shift_right, 0

bcf _status, C

btfsc param01_shift_right, 0

goto $+3

btfsc param01_shift_right, 1

goto $+5

btfsc param01_shift_right, 1

goto $+6

rrf _buffer, F

goto $+7

rrf _buffer+1, F

rrf _buffer, F

goto $+4

rrf _buffer+2, F

rrf _buffer+1, F

rrf _buffer, F

btfss   _status, C

retlw 0

retlw   1

}

}

/*********************************************/

// return : buffer[0] ~ buffer[ELEMT-1]]  limet ELEMT => 3

/*********************************************/

void main() {

   while (1) {    

      for ( i=0; i<8*ELEMT; i++)

         shift_right(buffer[ELEMT-1], ELEMT, input(PULSE_IN);

      for ( i=0; i<8*ELEMT; i++)

         shift_left(buffer[0], ELEMT, ShiftLeft(data));

  }

}

Share this post


Link to post
Share on other sites

Thanks ysj,

  I think I'll build these routines and add them to my toolbox. Why did you convert to C2C. My choice to use C2C was what looked like a more ANSI based system. I would like to see more binary, bolean, byte based operators though.

 

Thanks again

  Brad    :D

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...