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

variable getting 4 bit in size after function

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



Joined: 15 May 2008
Posts: 3

View user's profile Send private message

variable getting 4 bit in size after function
PostPosted: Thu May 15, 2008 6:26 am     Reply with quote

Hello PIC users,

I can't figure out what I'm doing wrong. Maby someone can help me.

I'm sending a value (16 bits in size) to a function. The function never gets a value above 4 bit (max 0x0f). What am I doing wrong? Here is some code which gives the error..

With kind regards

Arnoud

Code:

define DAC_CLK PIN_B1
#define DAC_DI PIN_C2
#define DAC_FS PIN_E1
#define DAC_nPRE PIN_E2
#define DAC_nLDAC PIN_E0
 
#include <stdlib.h>
#include <STDLIB.H>
 

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=RS232,bits=8)
 
//=============================================================
 
void write_TL(int16 data)
   {
        BYTE cmd[2];
        BYTE i;
       
   printf("%Lx\n\r",data);       [b][color=red][b]<--- DATA is max 0x00f (only 4 bit?)[/b][/color][/b]
 

        output_high(DAC_nLDAC);
        output_low(DAC_CLK);
        output_low(DAC_FS);
 
        for(i=0; i<16; ++i)
           {
            output_bit(DAC_DI, shift_left(data,2,0));
            output_high(DAC_CLK);
           delay_us(50);
            output_low(DAC_CLK);
             }
 

      output_high(DAC_FS);
 
      output_low(DAC_nLDAC);
      delay_us(10);
 
      output_HIGH(DAC_nLDAC);
   }
 
 

//==========
 
 
 

void main() {
 
int16 k;

 
 while (true)
  {
  for(k=0; k< 0xffff ; k++)      // sending an 16 bit value = max 0xffff
   {
   
     write_TL(k);
     printf("%Lx\n\r",data);       [b][color=red][b]<--- DATA is max 0x00f (only 4 bit?)[/b][/color][/b]
     }
 

  delay_us(500000);
 }
 
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 15, 2008 6:54 am     Reply with quote

The variable 'data' is unknown in main().

What is your compiler version number?

Code:
output_bit(DAC_DI, shift_left(data,2,0));
This is a bug changing random memory. Change to
Code:
output_bit(DAC_DI, shift_left(&data,2,0));
citroenie



Joined: 15 May 2008
Posts: 3

View user's profile Send private message

worked
PostPosted: Fri May 16, 2008 3:40 am     Reply with quote

Thanks,

Your solution worked "&"

With kind regards

Arnoud
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