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

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

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







rs232 communi.... 12number send -> 4 hundred number reply
PostPosted: Wed Jan 18, 2006 8:17 pm     Reply with quote

pc 12 number send -> and splite pic 4 hundred number
012345678901 -> id(012) rvalue(345) gvalue(678) bvalue(901)

how do i?
#int_rda() function receive 12 number and store

// use device : comfile pic training kit
// RC6 -> RS232 송신
// RC7 -> RS232 수신

#include<16F874.H>
//#device pic16f874 *=16 adc=12

#priority rda,timer0

// 표시하고자 하는 데이터를 Ascii 코드 테이블로 만듬
const int8 Message_tbl[22] = {'P','r','e','s','s',' ','a','n','y',' ','k','e','y',
'(','0',' ','~',' ','9',')',13,10};

// rtcc_isr()함수에서 case문을 순서대로 실행하기 위한 차례지정 변수
char disp_seq = 0;
// rda_isr()함수에서 수신되는 데이터를 순서대로 받기 위한 차례지정 변수
char rcv_seq = 0;

int16 id1=0, id2=0,id3=0;
int16 rvalue1=0, rvalue2=0, rvalue3=0;
int16 gvalue1=0, gvalue2=0, gvalue3=0;
int16 bvalue1=0, bvalue2=0, bvalue3=0;
int16 id, id_temp;
int16 rvalue, rvalue_temp;
int16 gvalue, gvalue_temp;
int16 bvalue, bvalue_temp;

void num_set();

void Delay_500us(){
int i,j;
for(i=0;i<225;i++) j++; // j++는 시간을 맟추기 위함
}

#int_rda
rda_isr(){
int8 i;

if(OERR){
CREN = 0;
CREN = 1;
i = RCREG; // 한 번 읽음
i = RCREG; // 두 번 읽음
}
else if(FERR) {
CREN = 0;
CREN = 1;
}
else{
while(!TRMT); // TRMT가 비어 있나봐서
// TXREG = RCREG; // 받은 데이터 다시 전송
switch(rcv_seq){
case 0: // 수신된 값은 아스키 코드 값이므로 digit_font
rcv_seq = 1;
id1=RCREG-0x30;
break;

case 1:
rcv_seq = 2;
id2=RCREG-0x30;
break;
case 2:
rcv_seq = 3;
id3=RCREG-0x30;
break;
case 3:
rcv_seq = 4;
rvalue1=RCREG;
break;

case 4:
rcv_seq = 5;
rvalue2=RCREG;
break;
case 5:
rcv_seq = 6;
rvalue3=RCREG;
break;
case 6:
rcv_seq = 7;
gvalue1=RCREG;
break;
case 7:
rcv_seq = 8;
gvalue2=RCREG;
break;
case 8:
rcv_seq = 9;
gvalue3=RCREG;
break;
case 9:
rcv_seq = 10;
bvalue1=RCREG;
break;
case 10:
rcv_seq = 11;
bvalue2=RCREG;
break;
case 11:
rcv_seq = 0;
bvalue3=RCREG;
num_set();

// while(!TRMT);
TXREG=id;
TXREG=rvalue;
TXREG=gvalue;
TXREG=bvalue;

while(!TRMT); // TRMT가 비어 있나봐서
TXREG = 140; // CR(140)전송 공백입력
while(!TRMT); // TRMT가 비어 있나봐서
TXREG = 13; // CR(13)전송 Carriage Return
while(!TRMT); // TRMT가 비어 있나봐서
TXREG = 10; // LF(10)전송 Line Feed
break;
}
}
}

void num_set(){ // 12자리수를 -> 3자리수 4개 변환
id_temp=id1*100+id2*10+id3;
if(id_temp<512)
id=id_temp;
rvalue_temp=rvalue1*100+rvalue2*10+rvalue3;
if(rvalue_temp<256)
rvalue=rvalue_temp;
gvalue_temp=gvalue1*100+gvalue2*10+gvalue3;
if(gvalue_temp<256)
gvalue=gvalue_temp;
bvalue_temp=bvalue1*100+bvalue2*10+bvalue3;
if(bvalue_temp<256)
bvalue=bvalue_temp;
}

void Init_rtn()
{
TRISB = 0x00;
PORTB = 0xff;
TRISC = 0x80;
PORTC = 0x0f;
SPBRG = 23; // 9600
RCSTA = 0b10010000; // SPEN = 1,CREN=1
TXSTA = 0b00100000; // TX9=0,TXEN=1,SYNC=0,BRGH=0
// 내부클럭 사용,프리스케일러 TMR0에 할당,분주비 1:16
// 오버플로우 시간은 약 0.27126uS * 256 * 16(분주비) = 약1111uS = 1.1mS
OPTION_REG = 0b00000011;
TMR0 = 0; // 현재 TMR0를 0으로 초기화
PIE1 = 0b00100000; // RCIE=1,RXIE=0
INTCON = 0b11100000; // GIE=1,PIEI=1,T0IE=1
}

void main()
{
int8 i;
Init_rtn();
for(i=0;i<=21;i++){ // Message_tbl의 내용이 18개 이므로
while(!TRMT); // TRMT가 비어 있나봐서
// 테이블의 내용을 읽어 TXREG에 넣으면 전송 됩니다.
TXREG = Message_tbl[i];
Delay_500us();
Delay_500us();
Delay_500us();
}
while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 2:45 am     Reply with quote

First thing, learn how to use the CCS compiler functions.
You're using code that comes from Hi-Tech C, or CC5x,
or something like that. They use low level code for
rs232, and CCS has higher level code for those functions.

Learn how to use the #use rs232() statement, and the
associated functions, such as getc(), and learn how to
use delay_us(), etc.
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