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

ccs example EX_SISR.C modify problem....?

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



Joined: 17 Jan 2006
Posts: 1
Location: korea

View user's profile Send private message MSN Messenger

ccs example EX_SISR.C modify problem....?
PostPosted: Mon Feb 06, 2006 12:12 am     Reply with quote

rs232 communi.... 12number send -> 4 hundred number reply

Buffered data => 123 456 789 012 <--- (send data )

id=8, r=152, g=229, b=220 <---(receive data)

send char -> receive char -> change int
above problem?.....
I can't find it...... help me

/////////////////////////////////////////////////////////////////////////
//// EX_SISR.C ////
#if defined(__PCM__)
#include <16F877a.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=14745600)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif

#define cr 13
#define lf 10

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;

int8 id1=0,id2=0,id3=0,r1=0,r2=0,r3=0;
int8 id11=0,id22=0,id33=0,r11=0,r22=0,r33=0;
int8 g1=0,g2=0,g3=0,b1=0,b2=0,b3=0;
int16 id=0, r=0, g=0, b=0;
byte temp;
void number();
void num_print();

#int_rda
void serial_isr() {
int t;


buffer[next_in]=getc();
number();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
BYTE c;

while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}



void main() {

enable_interrupts(global);
enable_interrupts(int_rda);

printf("\r\n\Running...\r\n");

// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay

do {
num_print();
delay_ms(5000);
printf("\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE);
}

void number() {
if(next_in==0)
id11 = (int8)buffer[next_in];
id1 = atoi(id11);
if(next_in==1)
id22 = (int8)buffer[next_in];
id2 = atoi(id22);
if(next_in==2)
id33 = (int8)buffer[next_in];
id3 = atoi(id33);
if(next_in==4)
r1 = (int8)buffer[next_in];
if(next_in==5)
r2 = (int8)buffer[next_in];
if(next_in==6)
r3 = (int8)buffer[next_in];
if(next_in==8)
g1 = (int8)buffer[next_in];
if(next_in==9)
g2 = (int8)buffer[next_in];
if(next_in==10)
g3 = (int8)buffer[next_in];
if(next_in==12)
b1 = (int8)buffer[next_in];
if(next_in==13)
b2 = (int8)buffer[next_in];
if(next_in==14)
b3 = (int8)buffer[next_in];
}
void num_print(){
putchar(cr);
putchar(lf);

// printf(" id1=%c, id2=%c, id3=%c", id1, id2, id3);
// printf(" r1=%c, r2=%c, r3=%c", r1, r2, r3);
// printf(" id1=%d, id2=%d, id3=%d", id1, id2, id3);
// printf(" r1=%d, r2=%d, r3=%d", r1, r2, r3);
putchar(cr);
putchar(lf);

id=id1*100+id2*10+id3;
r=r1*100+r2*10+r3;
g=g1*100+g2*10+g3;
b=b1*100+b2*10+b3;
printf(" id=%lu, r=%lu, g=%lu, b=%lu", id, r, g, b);
// printf(" g1=%d, g2=%d, g3=%d", g1, g2, g3);
// printf(" b1=%d, b2=%d, b3=%d", b1, b2, b3);

putchar(cr);
putchar(lf);
}

thanks... read.......
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 06, 2006 1:20 pm     Reply with quote

You're not using the EX_SISR.C code in the correct way. You should
use the bgetc() function to get bytes from the receive buffer. Don't
try to access the buffer directly.
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