View previous topic :: View next topic |
Author |
Message |
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
sending integer pc to pic |
Posted: Thu Jan 19, 2017 5:13 am |
|
|
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
|
|
Posted: Thu Jan 19, 2017 7:20 am |
|
|
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
|
|
Posted: Thu Jan 19, 2017 8:17 am |
|
|
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
|
|
Posted: Fri Jan 20, 2017 7:15 am |
|
|
Thank you both. I use putty to receive and send data. I will search for get_int. |
|
|
|