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

PIC's variable changing through PC
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PIC's variable changing through PC
PostPosted: Tue Jan 15, 2008 3:09 am     Reply with quote

Hi, is it possible to do that? I never try it but it's in my mind. If can, how? or may be there are links for that. Actually I want to change
Code:
 delay_ms (x)[
through VB.
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Tue Jan 15, 2008 3:44 am     Reply with quote

Assuming that you use port COM of your computer to connect to the RS232 of your PIC, you just have to scan for incoming characters (using int_rda or just kbhit() function), extract the desired value for the delay and copy it in a global variable or in EEPROM or wherever you want. Then you can use this value for anything in your programme... Wink
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 15, 2008 9:14 am     Reply with quote

Be careful tho, as it says in the help file
Quote:
time - a variable 0-255 or a constant 0-65535

if you make it a variable you only can go 0-255
ckielstra



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

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 11:31 am     Reply with quote

treitmey wrote:
Be careful tho, as it says in the help file
Quote:
time - a variable 0-255 or a constant 0-65535

if you make it a variable you only can go 0-255
The V4 compiler improved this and allows the variable to be int16 (0 - 65535) as well.
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

generate ~16khz pulses ???
PostPosted: Thu Feb 14, 2008 2:58 am     Reply with quote

Hi, thanks for the ideas. I've tried out. but its not work. when I send any 0-255 from VB it generates ~16kHz. then it doesnt want to change the second value (from VB). seems like int_rda doesnt work. here the codes
Code:
 

int8 x;
int8 j;
int8 y;

#int_rda
void rda_isr(void)
{
char c;
char string[10];

   c = getc(); // Get character from PC
   putc(c);    // Send it back to the pc
 
   strcpy(string,"c");
   x=atoi(String);
}   

void main()
{    x=145;                            //initial value

while(1)
 {   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   for(y=0; y<=x; y++);{
   output_b(0b00000001);
   delay_us(10);
   }
   
   for(j=0; j<=x; j++);{
   output_b(0b00000000);
   delay_us(10);
   }
 }
}

. I want to try get_string() function but I dont know how.
Embarassed
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Thu Feb 14, 2008 3:04 am     Reply with quote

No matter what character you send, you copy the string "c" to your string variable, and not the character stored in c !
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

see output/result
PostPosted: Tue Feb 19, 2008 3:39 am     Reply with quote

thanks D-Kens. I add few function. seems like it work.
Code:
   c_ptr=&c;
   strcpy(string,c_ptr);
   x=atoi(string);


but how can I see the result of x, since I only have CCS and MPLAB.
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Tue Feb 19, 2008 4:05 am     Reply with quote

Don't you have the Serial Port Monitor in the "Tools" of your compiler, or Hyperterminal on your computer ? You can ask your main() to write to the console :
Code:
printf("x=%d\n\r", x) ;

For test purpose, you should also add a delay of a few seconds, else you'll flood the screen with lines and lines of "x=..." ! Wink
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PostPosted: Wed Feb 20, 2008 4:00 am     Reply with quote

many thanks. I try to use siow but nothing happen. what i did was, open siow --> open file **.c --> send hex number.
How to use siow correctly?
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Feb 20, 2008 7:18 am     Reply with quote

I have a major problem with your code.

Quote:

c_ptr=&c;
strcpy(string,c_ptr);
x=atoi(string);


strcpy relies on NULL terminated strings. c is a single char in memory, there is no way of knowinf what value comes after it in memory. you seem to have been very lucky in that a null terminating character must come quite soon after the initial char otherwise the string array would overrun and you will corrupt memory.

you can either use strncpy(string, &c, 1) to copy just the 1 char or
string[0] = c;
string[1] = '\0';
and then use atoi(string).

The other option is to just do x = c - '0'; to retrieve the single digit.

A better method for what you are trying to do is:-

Code:

char buffer[10];
int index = 0;

#int_rda
void rda_isr(void)
{
  char c;
  c = getc();
  if (c == '\r') {
    buffer[index] = '\0';
    x = atoi(buffer);
    index = 0;
  } else
    buffer[index++] = c;
}


Note there are no checks to see if index becomes 10 or greater which would cause a buffer overrun.
casandralam



Joined: 26 Jan 2008
Posts: 15

View user's profile Send private message

can receive integer from 0-255?working?
PostPosted: Sun Mar 02, 2008 7:09 am     Reply with quote

Wayne, do your code support for integer from 0-255?
Thanks..
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Mar 03, 2008 2:38 am     Reply with quote

The atoi function converts an ascii string of "0" to "255" to an integer so "0" becomes 0 and "255" becomes 255.

Integers in CCS are 8 bit so my code should work for a string value of 0 to 255.
casandralam



Joined: 26 Jan 2008
Posts: 15

View user's profile Send private message

where is the output shown?
PostPosted: Tue Mar 04, 2008 3:10 am     Reply with quote

I'm a newbie.Please forgive me if you feel my question is stupid..

Which pin of the pic is the output?can i set myself for example port b0 as our output?

Then,
how can we observe the output?using lcd or 7 segment display?or any program can do for it?can you suggest me some method to do do?
Thanks you very much
casandralam



Joined: 26 Jan 2008
Posts: 15

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 3:16 am     Reply with quote

Why arys put x=145 as initial value in his main program?what does it means?
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Mar 04, 2008 3:31 am     Reply with quote

yes, it's initial value. then i hope i can change the x value through pc.


Which pin of the pic is the output?can i set myself for example port b0 as our output?
--> actually we can each pin either become input or output. you can find it out in the CCS manual how to set IO.

how can we observe the output?
-->i'm usually use ossciloscope or you can put the LED at the output.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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