感谢您的响应。请查找下面的代码,其中只发送相关的部分,*定义eSuART1xTXA BuffelySub 16μ定义EuSARTAR1RxBuffelySosig 256定义EuSART1O1DATARADY(EASARTAR1RXCOUNT)易失性无符号char EUSATAR1TXHORD=0;易失性无符号char EUSATAR1TXTRAY=0;易失签名char EUARTAR1TXBuff[EUARART1OXTXBAUBRIZHORIZ];易失性无符号CHAREUARTAR1RXHORD=0;易失性CHAR未签名EUARTAR1RXTRAY=0;易失性CHAR无符号EUARTAR1RXBuff[ESOART1ORXBuffelySimple ];易失性无符号char EUSATAR1RXCOUNT;CHAB HBSPLASE(48);无效在改变状态RC1IEA比特=0之前,EUARTAR1X初始化(空隙){//禁止中断;BUD1CONE=0x08;RC1STA= 0x90;TX1Reg=0x0;TX1STA= 0x25;SP1BRGL= 0x0;SP1BRGH=0x0;/ /初始化驱动状态EUARTAR1TXHORD=0;EUARTAR1TXTRAY=0;ESOART1TXBUFFER剩余= SIZEOF(E)USAART1RXHORD=0;EUARTAR1RXTRAY=0;EUARTAR1RXCOUNT=0;RC1IEHIT比特=1;}虚振器初始化(空隙){//SCS FoC;SPLLN禁用;IrCF 8MHZYHF;OSCCon=0x70;//TUN 0;OSCUNTY=0x00;/ /设置二级振荡器OSCSTAT=0x00;/ /等待PLL稳定(PLLR==)x00=0x00;LATA= 0x20;LATF=0x00;LATD= 0x01;LATC= 0x1a;LATG=0xFd;TPISF=0x01;TrISG= 0x24;TrISD=0B000 0 01;TrISE=0xF0;TrISB=0xFD;TrISC= 0xBC;TrISA=0xC0;ANSELE=0x00;Audio=0x00;ANSELG=0;0){}}空隙PixMauner-Read初始化(空隙){APFCON= 0OSCCon=0x70;OSCSTAT=0x00;OSCTUNE=0x00;//(PLLRL比特=0){空隙}{PEIEA位=1;GieZeBit=1;PinsiMaungRixAlpIZILIZE();WDTTIX初始化();EUTART1IX初始化();T1CONN=0x21;T1GCONN=0x0;TMR1IFN1比特=0;TMR1H=0xFF;TMR1L= x00;ANSELLA=0x00;opthy.Re.b7= 0x0CDayIn();Delay-Fix=(200);TMR1IEHEL比特=1;计数=0;TuthiVar=0;I=0;LCDY-CMD(Y-LCDA清除);char EuSART11Read(空隙){Car Read Value= 0;而(0=eSARTAR1RXCOUNT){}读值=EUARTAR1RXBuff[ESOART1RXTUR++];IF(SIUART1RxBuffels:lt=;EUSATAR1RXTAI)0x0A;尾=0;} rC1IExBIT=0;RC1IE1比特=1;返回读取值;}空隙EUARART1IORIVEVIO.ISR(空隙){RC1IFNITBIT==0;IF(1=RC1STA.OErr){//EUSATAR1错误-重新启动RC1STA.CREN=0;RC1STA.CREN=1;} EUARTAR1RXBuff[ESOART1RXCHIDE]=RC1Reg;CMDyBoe= EUSATAR1RXBuff[EUSA] L){EuSART1RX如果(SIUART1RxBuffels<= EUSATAR1RXHORD){EUARTAR1RXCHILD=0;} EUTARTAR1RXCOUNT++;}空Time1IsR(空隙){TMR1IFN1比特=0;塌陷时间+++;如果(塌陷时间T>333)/读过滤按钮输入{if(Purb.B0==0)ButoOnClut+++;如果(ButoOnng&G.&&Po.B.B==1){PUL)RT1RXHead} //更新4x7段DISPADSDSPBFFF(0)=计数/ 1000;DSPBuff[1 ]=(计数/ 10)%10;DSPBuff[3 ]=计数%10;DISSPORK0=10;DISSPORK1=α;DISSPORK2=;DSPSIRA++;如果(DSPSIRA==γ){DSPSIRA=;} DAT= DSPDATACONV[DSPBuff[DSPSIRA] ];SeeOK=TRUE;ButoOnCub计数=0;S塌陷时间=0;}= DAT.B4;O-SEGF=DAT.B5;Y SeGG=DAT.B6;开关(DSPSIRA){{ DISSPORK0=1;中断;} DISSPORK1=1;中断;} DISSPORK2=1;中断;} PaseK3=1;中断;} TMR1H=0XFF;TMR1L=0x0A;KyyRead(&;TuSuVar);和/或读取16输入键盘3无效。DAT.B0;γSEGB= DAT.B1;Y-SeCc=DAT.B2;//中断处理程序if(PeeAdBIT=1和AMP;RC1IEHYBIT=1和&;RC1IF1位=1){EntART1ILAccEvEvIsR();}否则(ItNo.Peee=1和&;PIE1.TX1IE=1和&;PIR1.TX1IF=1){EuSART11EngulixISR();}否则(PEEAYBIT=1和AMP&TMR1IEYBIT=1和&);中断(空){(1){ Time1IsIr-();} }无效的主(){init();}(/)1,{ / /如果定时器1中断在常规工作下被禁用,否则它会松动USAT 115200 IF(EUARTAR1A DATAARADY){字符=0=0,读写=EUARTAR1A读()的字符/ /波特率;{De}{HBsPlas[j]=EuStAR1YRE(+);j++;}(EUARTAR1RXCOUNT!)= 0);} LCDIOUT(2,1,&HBSBuffer(6));MeMSET(HBSBuffer,0,StLLEN(HBSBuffer));
以上来自于百度翻译
以下为原文
Thanks for your response.Please find below the code where only the related parts are sent,
#define EUSART1_TX_BUFFER_SIZE 16
#define EUSART1_RX_BUFFER_SIZE 256
#define EUSART1_DataReady (eusart1RxCount)
volatile unsigned char eusart1TxHead = 0;
volatile unsigned char eusart1TxTail = 0;
volatile unsigned char eusart1TxBuffer[EUSART1_TX_BUFFER_SIZE];
volatile unsigned char eusart1TxBufferRemaining;
volatile unsigned char eusart1RxHead = 0;
volatile char unsigned eusart1RxTail = 0;
volatile char unsigned eusart1RxBuffer[EUSART1_RX_BUFFER_SIZE];
volatile unsigned char eusart1RxCount;
char HBSBuffer[48];
void EUSART1_Initialize(void)
{
// disable interrupts before changing states
RC1IE_bit=0;
TX1IE_bit=0;
BAUD1CON = 0x08;
RC1STA = 0x90;
TX1REG=0X0;
TX1STA = 0x25;
SP1BRGL = 0x44;
SP1BRGH = 0x0;
// initializing the driver state
eusart1TxHead = 0;
eusart1TxTail = 0;
eusart1TxBufferRemaining = sizeof(eusart1TxBuffer);
eusart1RxHead = 0;
eusart1RxTail = 0;
eusart1RxCount = 0;
RC1IE_bit=1;
}
void OSCILLATOR_Initialize(void)
{
// SCS FOSC; SPLLEN disabled; IRCF 8MHz_HF;
OSCCON = 0x70;
// TUN 0;
OSCTUNE = 0x00;
// Set the secondary oscillator
OSCSTAT = 0x00;
// Wait for PLL to stabilize
while(PLLR == 0)
{
}
}
void PIN_MANAGER_Initialize(void)
{
APFCON = 0x00;
LATB =0x00;
LATA =0xDF;
WPUG =0x20;
LATF =0x00;
LATE =0x00;
LATD =0x01;
LATC =0x1A;
LATG =0x00;
WPUB =0xFD;
TRISF=0x01;
TRISG =0x24;
TRISD =0B00000001;
TRISE =0xF0;
TRISB =0xFD;
TRISC =0xBC;
TRISA =0xC0;
ANSELE =0x00;
ANSELF =0x00;
ANSELG =0x00;
ANSELA =0x00;
OPTION_REG.B7 = 0x0;
OSCCON = 0x70; OSCSTAT = 0x00; OSCTUNE = 0x00;//
while (PLLR_bit==0) {}
}
void init (void)
{
peie_bit=1;
gie_bit=1;
PIN_MANAGER_Initialize();
OSCILLATOR_Initialize();
WDT_Initialize();
EUSART1_Initialize();
T1CON = 0x21;
T1GCON=0X0;
TMR1IF_bit = 0;
TMR1H = 0XFF;
TMR1L = 0x0A;
INTCON = 0xC0;
lcd_init();
delay_ms(200);
BUZZER=false;
TMR1IE_bit = 1;
count=0;
tus_var=0;
i=0;
lcd_cmd(_lcd_clear);
readletter=0;
}
char EUSART1_Read(void)
{
char readValue = 0;
while(0 == eusart1RxCount)
{
}
readValue = eusart1RxBuffer[eusart1RxTail++];
if(sizeof(eusart1RxBuffer) <= eusart1RxTail)
{
eusart1RxTail = 0;
}
RC1IE_bit = 0;
eusart1RxCount--;
RC1IE_bit = 1;
return readValue;
}
void EUSART1_Receive_ISR(void)
{
RC1IF_bit == 0;
if(1 == RC1STA.OERR)
{ // EUSART1 error - restart
RC1STA.CREN = 0;
RC1STA.CREN = 1;
}
eusart1RxBuffer[eusart1RxHead] = RC1REG;
cmd_letter=eusart1RxBuffer[eusart1RxHead];
if (sizeof(eusart1RxBuffer)<=eusart1RxHead)
{
eusart1RxHead = 0;
}
eusart1RxCount++;
}
void Timer1_ISR(void)
{
TMR1IF_bit=0;
collapsed_time++;
if(collapsed_time > 333) //Reading filtered button input
{
if(PORTB.B0==0)button_count++;
if(button_count > 21 && PORTB.B0==1){PULSE_OK=true;button_count=0;collapsed_time=0;}
}
//Updating 4x7 segment displays
dspbuff[0]=count/1000;
dspbuff[1]=(count/100)%10;
dspbuff[2]=(count/10)%10;
dspbuff[3]=count % 10;
disp_k0=0;
disp_k1=0;
disp_k2=0;
disp_k3=0;
dspsira++; if (dspsira==4 ) {dspsira=0;}
dat= dsp_dataconv[dspbuff[dspsira]];
_sega=dat.b0;
_segb=dat.b1;
_segc=dat.b2;
_segd=dat.b3;
_sege=dat.b4;
_segf=dat.b5;
_segg=dat.b6;
switch(dspsira)
{
case 3:{disp_k0=1;break;}
case 2:{disp_k1=1;break;}
case 1:{disp_k2=1;break;}
case 0:{disp_k3=1;break;}
}
TMR1H=0XFF;
TMR1L=0X0A;
key_read(&tus_var); // Reading 16 input keypad
}
void interrupt(void)
{
// interrupt handler
if(PEIE_bit == 1 && RC1IE_bit == 1 && RC1IF_bit == 1)
{
EUSART1_Receive_ISR();
}
else
if(INTCON.PEIE == 1 && PIE1.TX1IE == 1 && PIR1.TX1IF == 1)
{
EUSART1_Transmit_ISR();
}
else if(PEIE_bit == 1 && TMR1IE_bit == 1 && TMR1IF_bit == 1)
{
Timer1_ISR();
}
}
void main()
{
init ();
}
while(1)
{
//If Timer 1 interrupt is disabled below routine works otherwise it looses some characters
//Baud rate of the USART 115200
if(EUSART1_DataReady)
{ j=0;
readletter=EUSART1_Read();
if(readletter=='<'){
do{
HBSBuffer[j]=EUSART1_Read();
j++;
}while( eusart1RxCount!=0);
}
}
lcd_out(2,1,&HBSBuffer[6]);
memset(HBSBuffer,0,strlen(HBSBuffer));