BASIC4MCU | 8051/PIC | DT-516 강좌 | DT516-087.c 시리얼인터럽트 문자열수신->문자열전송(에코)
페이지 정보
작성자 키트 작성일2017-08-23 14:25 조회2,590회 댓글0건첨부파일
본문
//-------------------------------------------------------------
// 82G516 E/V BOARD ( DT-516 )
//-------------------------------------------------------------
// XTAL : 22.1184Hz
//-------------------------------------------------------------
// filename: DT516-087.c
// 시리얼인터럽트 문자열수신->문자열전송(에코)
//-------------------------------------------------------------
#include <REG_MPC82G516.H>
//
#include "DT516-main.h"
//
//
U_C key_buf=0;
bit PushFlg=0, Key_Flg=0;
//
U_C FND_buf[4]={0,0,0,0};
//
bit Rx0_Flg=0;
XU_C Rx0_buf[100];
U_C Rx0_Cnt=0;
//
void Serial_Com_0_Interrupt(void) interrupt 4{ // Serial_Com_0_Interrupt:
U_C ch;
if(RI){ RI=0;
ch=SBUF;
if(ch=='\r'){
Rx0_buf[Rx0_Cnt++]=ch;
Rx0_Flg=1;
Rx0_Cnt=0;
}
else{
if(Rx0_Cnt<97)Rx0_buf[Rx0_Cnt++]=ch;
}
//
FND_buf[2]=ch>>4; FND_buf[3]=ch&0x0F;
}
}
//
void Timer_0_Interrupt(void) interrupt 1{ // 7200Hz=138.89us 주기
P4=0xFF; // FND OFF
//
switch(FND_CNT){
case 0: P0=Seg_Data[FND_buf[0]]; FND_COM1=0; break;
case 1: P0=Seg_Data[FND_buf[1]]; FND_COM2=0; break;
case 2: P0=Seg_Data[FND_buf[2]]; FND_COM3=0; break;
case 3: P0=Seg_Data[FND_buf[3]]; FND_COM4=0; break;
}
if(++FND_CNT>3)FND_CNT=0;
//
if(delay_buf){ if(--delay_buf==0)delay_flg=1; }
}
//
CU_C test[]=" 82G516 강좌입니다.\r\n";
//
void TX0_CH(U_C ch){ SBUF=ch; FND_buf[0]=ch>>4; FND_buf[1]=ch&0x0F; while(!TI); TI=0; }
void TX0_STR(char *pt){ while(*pt)TX0_CH(*pt++); }
//
void main(){
U_I i;
TMOD=0x22; SCON=0x50; TCON=0x55; TH1=0xFA; TL1=0xFA; // 9600bps
ET0=1; TR0=1; TR1=1; ES=1; EA=1;
delay_ms(1000);
TX0_STR((char*)test);
while(1){
if(Rx0_Flg){ Rx0_Flg=0;
i=0; while(Rx0_buf[i]!='\r')TX0_CH(Rx0_buf[i++]);
TX0_CH('\r'); TX0_CH('\n');
}
}
}
//-------------------------------------------------------------//-------------------------------------------------------------
//FND 1,2자리는 마지막 송신 데이터
//FND 3,4자리는 마지막 수신 데이터
//
//PC 키보드를 입력하고 마지막 엔터키를 누르면 수신된 데이터를 PC로 송신 합니다.
//-------------------------------------------------------------
댓글 0
조회수 2,590등록된 댓글이 없습니다.