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

sending integer pc to pic

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



Joined: 05 Oct 2016
Posts: 120

View user's profile Send private message

sending integer pc to pic
PostPosted: Thu Jan 19, 2017 5:13 am     Reply with quote

Hello everyone,

I am trying to send an integer value to a pic from a pc. I managed to send and receive an integer between to 18f2550s. It worked, but i can't send integer from pc. I can't send 123 for example.
Here are my codes.

Transmit code:
Code:

#include <18F2550.h>
#DEVICE ADC=10
#fuses INTRC_IO,NOWDT,NOMCLR,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,CPUDIV1,VREGEN
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)

#define toint(c) ((int)((c)-'0'))
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void main()
{
setup_oscillator(OSC_8MHz);
int sayi=253;

while (TRUE)
{
   output_high(PIN_A0); //1. pic haber veriyor
   delay_ms(1000);
   output_low(PIN_A0);
   delay_ms(1000);
   putc(sayi);
}
}


rcv code
Code:

#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#define toint(c) ((int)((c)-'0'))
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void main()
{

setup_oscillator(OSC_8MHz);
int sayi=0;
while (TRUE)
{
sayi = getc();

   if (sayi==253)
   {
      output_high(PIN_A1);  //blink green led
      delay_ms(1000);
      output_low(PIN_A1);
      delay_ms(1000);   
   }
   else
   {
      output_high(PIN_A0);  //blink red led
      delay_ms(1000);
      output_low(PIN_A0);
      delay_ms(1000);   
   }

}
}


So i tried to send an integer from pc but no luck. The moment when i press a button it sends it automatically since it waits for a char. How can i send an integer? Why it works between 2 pics but not with pc?

thank you so much!
best wishes

Doğuhan
newguy



Joined: 24 Jun 2004
Posts: 1908

View user's profile Send private message

PostPosted: Thu Jan 19, 2017 7:20 am     Reply with quote

What program are you using on the PC to send data to the PIC? CCS' SIOW has a "hex window" at the bottom of its screen. For instance, to send 0xff, you just type "ff" into that window and hit the send button to the right.

I suspect that you need to first translate your number to hex, then type that hex equivalent into whatever program you're using.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Jan 19, 2017 8:17 am     Reply with quote

or (of course), if you want to convert ASCII text to a 'number', then look at the CCS supplied functions in input.c 'get_int' for example....
doguhanpala



Joined: 05 Oct 2016
Posts: 120

View user's profile Send private message

PostPosted: Fri Jan 20, 2017 7:15 am     Reply with quote

Thank you both. I use putty to receive and send data. I will search for get_int.
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