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 CCS Technical Support

HCTL-2017 HighByte LowByte

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



Joined: 04 Aug 2013
Posts: 1

View user's profile Send private message

HCTL-2017 HighByte LowByte
PostPosted: Sun Aug 04, 2013 7:30 am     Reply with quote

Hello all,

I'm trying to read HCTL-2017 Quad Decoder/Counter chip. I got it working in BS2. However, I can't get it working in CCS C compiler, which does not have HighByte-LowByte functions? And i'm kinda puzzled with the make() functions as well. Below is my code -
Code:

#include <16F877A.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT         //Code not protected from reading
#FUSES NODEBUG            //No Debug mode for ICD
#FUSES BROWNOUT         //Reset when brownout detected
#FUSES NOLVP                //No low voltage prgming,
#FUSES NOCPD               //No EE protection
#FUSES NOWRT               //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//#use fast_io(A)
//#use fast_io(B)
//#use fast_io(C)
//#use fast_io(D)
//#use fast_io(E)


void Encoder(void);

int16 encoderLastL,encoderThisL;
int16 encoL,encoH;

void main()
{
       
  setup_comparator(NC_NC_NC_NC);
  setup_vref(0);
  set_tris_a(0b01100001);                  // 0 = Analog
  set_tris_b(0b11111111);                  // HCTL1 Inputs
  set_tris_c(0b10000000);
  set_tris_d(0b11111111);
  set_tris_e(0b00000000);
  setup_adc_ports(AN0);
  setup_adc(ADC_CLOCK_INTERNAL);
  setup_ccp2(CCP_PWM);
  setup_timer_2(T2_DIV_BY_4, 255, 1);       // 4.88 kHz PWM
  set_pwm1_duty(0);                        // initialize PWM off

  output_low (PIN_C0);                     //Motor DIR.
  output_high(PIN_A1);                    //Reset HCTL-1
  output_high(PIN_A4);                    //Reset HCTL-2
 
  delay_ms(100);
 
  while(1)
  {
   
   output_high(pin_E0); //OE HCTL-1
   output_high(pin_E1); //SEL HCTL-1 (L-Bytes,H-Bytes)
   
   encoH = input_b();
   
   output_low(pin_E1);  //SEL HCTL-1
   
   encoL = input_b();
   
   output_low(pin_E0);  //OE HCTL-1
   
   encoderThisL = make16(encoL,encoH);
   
   encoderLastL = encoderThisL;
   
   printf("EncoderLast: %Lu \n\r",encoderLastL);
   
   //printf("\n\r");
   //printf("EncoderThis: %d \n\r",encoderThisL);   
   
  }
 
}



Can anyone help me?Or how to read the HighBytes & LowBytes straight from the pins?

Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Sun Aug 04, 2013 7:47 am     Reply with quote

CCS can deal with high/low bytes, using standard C.
Code:

struct bytes {
   int8 low;
   int8 high;
};
   
union {
   struct bytes b;
   int16 word;
} val;


Then val.b.low is the low byte, val.b.high is the high byte, and val.word is the 16bit word.
So val.b.high = input_b(); will read the high byte directly.

Make16 though also does it, and should work as you show.

If it doesn't work, you probably have something else wrong...

The obvious fault is basic. You are putting OE high. This disables the output. OE is an active low signal (read the data sheet.....). Similarly you have the byte select the wrong way round. '0' (low) gives the high byte. You are selecting high.....

Best Wishes
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Sun Aug 04, 2013 8:32 am     Reply with quote

Quote:

Code:

encoderThisL = make16(encoL,encoH);



One possible issue with how you are using make16() is the order of your parameters. make16() takes high byte first.
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