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

Need Help with Long Int

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







Need Help with Long Int
PostPosted: Fri Oct 05, 2001 1:56 pm     Reply with quote

Hello Everyone,

The following is a code snip from a project I'm working on. I hope someone can tell me why the printf statement in the main function reports that my long int 'x_delay' is some negative number like -3438 after I have expicitly set it to 62000??

Looking for help,

Eric

P.S. Using comiler PCM 2.734


///-----------------------------------------------------------------
// xy_table.c --
//
//
//
//--------------------------------------------------------------------------
// INCLUDE FILES

#include <16f876.H>

//---------------------------------------------------------------------------
// COMPILER AND CHIP CONFIGURATION DIRECTIVES

#fuses RC, NOWDT, NOPROTECT, NOBROWNOUT
#use Delay(Clock=4000000) // We're using a 4 MHz crystal
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7) // Use built-in USART
#priority timer1,rda

//---------------------------------------------------------------------------
// DEFINITIONS

#define RECV_FIFO_SIZE 30


//---------------------------------------------------------------------------
// GLOBAL VARIABLES


char recv_fifo[RECV_FIFO_SIZE]; // Fifo for the RS-232 receive data isr
char *recv_fifo_head; // Pointers for the recv fifo
char *recv_fifo_tail;
char recv_fifo_byte_count; // Number of bytes in the recv fifo

// My Globals

char CmdArray[RECV_FIFO_SIZE]; // Array for storing commands from PC
int index=0; // Index of array storing serial commads B4 parsing

long x_dist=0; // X Axis Distance(steps)
long x_delay=62000; // X Axis Step Delay--Delay between steps

//---------------------------------------------------------------------------
// FUNCTION DECLARATIONS

void init_rs232_recv_buffer(void);
char get_rs232_char(void);
char is_rs232_char_ready(void);
void rs232_recv_data_isr(void);

void move_x(void); //ISR for X Axis step code

long ConvertToLong(*string,len); //Converts ascii number to long int
int ConvertToInt(*string,len); //Convert ascii number to int

//====================== Main Function ================================================


void main(void)
{

char value;

printf("Delay at Start=\%ld\n\r",x_delay);

init_rs232_recv_buffer(); // Init pointers to recv fifo

setup_timer_1(T1_Internal|T1_DIV_BY_1);
set_timer1(x_delay);
//enable_interrupts(INT_TIMER1); //will interrupt processor and run code to step motor


while(1)
{
if(is_rs232_char_ready() == TRUE) // Did we receive an RS-232 char ?
{
value = get_rs232_char(); // If so, get the byte
putc(value); // echo it back to host
}

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 552
Richard Henry
Guest







Re: Need Help with Long Int
PostPosted: Fri Oct 05, 2001 2:12 pm     Reply with quote

Try unsigned long.


:=Hello Everyone,
:=
:=The following is a code snip from a project I'm working on. I hope someone can tell me why the printf statement in the main function reports that my long int 'x_delay' is some negative number like -3438 after I have expicitly set it to 62000??
___________________________
This message was ported from CCS's old forum
Original Post ID: 553
DominicB
Guest







Re: Need Help with Long Int
PostPosted: Fri Oct 05, 2001 2:38 pm     Reply with quote

Try using \%lu instead of \%ld, 'd' stands for signed int while 'u' is unsigned.

Best regards


:=Hello Everyone,
:=
:=The following is a code snip from a project I'm working on. I hope someone can tell me why the printf statement in the main function reports that my long int 'x_delay' is some negative number like -3438 after I have expicitly set it to 62000??
:=
:=Looking for help,
:=
:=Eric
:=
:=P.S. Using comiler PCM 2.734
:=
:=
:=///-----------------------------------------------------------------
:=// xy_table.c --
:=//
:=//
:=//
:=//--------------------------------------------------------------------------
:=// INCLUDE FILES
:=
:=#include <16f876.H>
:=
:=//---------------------------------------------------------------------------
:=// COMPILER AND CHIP CONFIGURATION DIRECTIVES
:=
:=#fuses RC, NOWDT, NOPROTECT, NOBROWNOUT
:=#use Delay(Clock=4000000) // We're using a 4 MHz crystal
:=#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7) // Use built-in USART
:=#priority timer1,rda
:=
:=//---------------------------------------------------------------------------
:=// DEFINITIONS
:=
:=#define RECV_FIFO_SIZE 30
:=
:=
:=//---------------------------------------------------------------------------
:=// GLOBAL VARIABLES
:=
:=
:=char recv_fifo[RECV_FIFO_SIZE]; // Fifo for the RS-232 receive data isr
:=char *recv_fifo_head; // Pointers for the recv fifo
:=char *recv_fifo_tail;
:=char recv_fifo_byte_count; // Number of bytes in the recv fifo
:=
:=// My Globals
:=
:=char CmdArray[RECV_FIFO_SIZE]; // Array for storing commands from PC
:=int index=0; // Index of array storing serial commads B4 parsing
:=
:=long x_dist=0; // X Axis Distance(steps)
:=long x_delay=62000; // X Axis Step Delay--Delay between steps
:=
:=//---------------------------------------------------------------------------
:=// FUNCTION DECLARATIONS
:=
:=void init_rs232_recv_buffer(void);
:=char get_rs232_char(void);
:=char is_rs232_char_ready(void);
:=void rs232_recv_data_isr(void);
:=
:=void move_x(void); //ISR for X Axis step code
:=
:=long ConvertToLong(*string,len); //Converts ascii number to long int
:=int ConvertToInt(*string,len); //Convert ascii number to int
:=
:=//====================== Main Function ================================================
:=
:=
:=void main(void)
:={
:=
:=char value;
:=
:=printf("Delay at Start=\%ld\n\r",x_delay);
:=
:=init_rs232_recv_buffer(); // Init pointers to recv fifo
:=
:=setup_timer_1(T1_Internal|T1_DIV_BY_1);
:=set_timer1(x_delay);
:=//enable_interrupts(INT_TIMER1); //will interrupt processor and run code to step motor
:=
:=
:=while(1)
:= {
:= if(is_rs232_char_ready() == TRUE) // Did we receive an RS-232 char ?
:= {
:= value = get_rs232_char(); // If so, get the byte
:= putc(value); // echo it back to host
:= }
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 554
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