|
|
View previous topic :: View next topic |
Author |
Message |
sophiadoll
Joined: 11 Sep 2009 Posts: 3
|
Interesting problem sending long data |
Posted: Fri Sep 11, 2009 10:33 am |
|
|
I am new to CCS. I am trying to send data from a master to a receiver. I am sending two things, the first is the character 'A', the second is a counter.
I want to send it as long data because I went to be able to differentiate the type of data by setting an extra bit on the data packet that is the character 'A'.
When I send data I receive something like this:
001000001 (Character 'A')
100000000 (Counter)
It appears the bit i set on A is being set on the counter instead. I imagine it has something to do with the way getc() works. Below are my codes.
Sender
Code: |
#include <18f252.h>
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=9, long_data, stream=PC)
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA0 PIN_B4
#define LCD_DATA1 PIN_B5
#define LCD_DATA2 PIN_B6
#define LCD_DATA3 PIN_B7
#include <lcd.h>
#define DE PIN_C4
#define RE PIN_C5
#define DI PIN_C6
#define RO PIN_C7
void main()
{
int16 i;
int j = 0;
lcd_init();
output_high(DE);
while(true)
{
i = ((int16)0x100|'A');
printf(lcd_putc, "\f%ld", i);
fputc(i, PC);
delay_ms(200);
lcd_gotoxy(1,2);
fputc(j, PC);
printf(lcd_putc, "%d", j);
j++;
delay_ms(800);
}
}
|
Receiver
Code: |
#include <18f252.h>
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock = 10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=9, long_data, stream=PC)
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA0 PIN_B4
#define LCD_DATA1 PIN_B5
#define LCD_DATA2 PIN_B6
#define LCD_DATA3 PIN_B7
#include <lcd.h>
#define DE PIN_C4
#define RE PIN_C5
#define DI PIN_C6
#define RO PIN_C7
#INT_RDA
void in()
{
int16 j, k;
j = getc();
printf(lcd_putc,"\f");
printf(lcd_putc, "%u", bit_test(j,8));
printf(lcd_putc, "%u", bit_test(j,7));
printf(lcd_putc, "%u", bit_test(j,6));
printf(lcd_putc, "%u", bit_test(j,5));
printf(lcd_putc, "%u", bit_test(j,4));
printf(lcd_putc, "%u", bit_test(j,3));
printf(lcd_putc, "%u", bit_test(j,2));
printf(lcd_putc, "%u", bit_test(j,1));
printf(lcd_putc, "%u", bit_test(j,0));
k = getc();
lcd_gotoxy(1,2);
printf(lcd_putc, "%u", bit_test(k,8));
printf(lcd_putc, "%u", bit_test(k,7));
printf(lcd_putc, "%u", bit_test(k,6));
printf(lcd_putc, "%u", bit_test(k,5));
printf(lcd_putc, "%u", bit_test(k,4));
printf(lcd_putc, "%u", bit_test(k,3));
printf(lcd_putc, "%u", bit_test(k,2));
printf(lcd_putc, "%u", bit_test(k,1));
printf(lcd_putc, "%u", bit_test(k,0));
}
void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init();
output_low(DE);
output_low(RE);
while(true)
{
output_low(PIN_B3);
delay_ms(200);
output_high(PIN_B3);
delay_ms(200);
}
}
|
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Sep 11, 2009 11:08 am |
|
|
Hi
I don't understand correctly your problem but, I have this example for comunicated with an GPS see if this help you..
Quote: |
#int_rda
void rda_isr(void)
{
char c, string[61];
int i,k;
c=getc(gpsport);
if (c=='C')
{
i=0;
k=0;
do
{
c=getc(gpsport);
i++;
string[i]=c;
}while(c!='*');
i=i-1;
fprintf(tlmport, "array size: %u\n\r",i);
//$GPRMC,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
for(k=2;k<=12;k++)
{
fprintf(tlmport, "time: %c\n\r",string[k]);
}
}
}
void main ()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1)
{
printf("wait for first character \n\r");
delay_ms(1000);
}
}
|
kind regards |
|
|
sophiadoll
Joined: 11 Sep 2009 Posts: 3
|
|
Posted: Fri Sep 11, 2009 1:05 pm |
|
|
Let me explain myself better.
I am trying to send 9 bits of data. There are two data packets. The first is the character 'A' with the ninth bit set. The ascii value for the character 'A' is 65 which translates to 1000001. Therefore with the ninth bit set the receiver should see 101000001. The second data packet is just a counter in binary, starting from 000000000 then 000000001 then 000000010 etc...
So I want to see on my LCD something like this:
101000001
000000000
and each second the second line should increment as so:
101000001
000000001
101000001
000000010
101000001
000000011
101000001
000000100
And so on. But what I'm getting instead is the ninth bit set on that second line (counter) as shown below and not on the character line
001000001 (character line)
100000000 (counter line)
001000001
100000001
001000001
100000010
001000001
100000011
I hope I explained myself better. Thanks in advance for any help. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Sep 11, 2009 6:38 pm |
|
|
is there some reason you don't send simply send 8 bit ascii, exactly as you want to display it on the LCD ???
like send literally
"Annnn"<cr> where nnn is the ascii presentation of the number
and you just receive it in a string buffer and
stream it thru to the LCD as you receive it ?
been there - done that - got a wardrobe od tee shirts for it
i think U R MAKING IT HARDER THAN IT HAS TO BE
|
|
|
sophiadoll
Joined: 11 Sep 2009 Posts: 3
|
|
Posted: Mon Sep 14, 2009 8:33 am |
|
|
Yes there is a reason why I don't just literally send the 8 bit ascii character. I am designing my own version of a communication protocol. On certain data packets I need to set a ninth bit to be able to differentiate types of data, and I need to be able to check that ninth bit. That is the reason I am outputting my data in binary so that I can check what is happening bit by bit.
I believe the problem lies in the way I am declaring the #use rs232 (...bits = 9, long data). From the manual I understood I could send 16 bit data using the long data parameter. Does anyone have any samples or a good explanation on who to properly send and receive 16-bit data? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 14, 2009 12:03 pm |
|
|
You don't need #int_rda interrupts to do the test. Get rid of the #int_rda
and put the code in main(). Get rid of the code that enables interrupts.
Also, don't do a continuous test. Just send two 9-bit words, then stop.
See if you can receive just those two words.
In other words, simplify everything down to almost nothing. Make that
work. Then add complexity. |
|
|
|
|
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
|