jskil7
Joined: 17 Jan 2006 Posts: 1 Location: korea
|
ccs example EX_SISR.C modify problem....? |
Posted: Mon Feb 06, 2006 12:12 am |
|
|
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....... |
|