#include <p18cxxx.h>/*包含PIC18系列单片机头文件*/
#include "k18.h"
#include "delay.h"
#include "UART.h"
#include "string.h"
#define uchar unsigned char
#define uint unsigned int
#define uchar unsigned char
void PIC18F_High_isr(void);
void PIC18F_Low_isr(void);
#pragma code high_vector_section=0x8
void high_vector (void)
{
_asm goto PIC18F_High_isr _endasm
}
#pragma code
#pragma code low_vector_section=0x18
void low_vector (void)
{
_asm goto PIC18F_Low_isr _endasm
}
#pragma code
#pragma interrupt PIC18F_High_isr
#pragma interruptlow PIC18F_Low_isr
uchar DDR[150]={0};
uchar Rx=0;
uchar Tx=0,Send=0;
void main(void)/*主函数*/
{
k18_init();
ComIni();
TRISD=0X00;
COL1=1;
PORTD=0;
PIR1bits.RCIF=0;
PIR1bits.TXIF=0;
INTCONbits.INT0IF=0;
INTCONbits.TMR0IF=0;
INTCONbits.RBIF=0;
INTCONbits.GIEH=1;
INTCONbits.INT0IE=1;
PIE1bits.RCIE=1;
INTCONbits.GIEL=1;
while(1){
PORTD=0x01;
if(Send==1){
Send=0;
Tx=0;
while(DDR[Tx]!='\0'){
while(! TXSTAbits.TRMT);
TXREG = DDR[Tx++];
while(! PIR1bits.TXIF);
}
TXREG=Tx;
}
}
}
void PIC18F_High_isr (void)
{
if(PIR1bits.RCIF&&PIE1bits.RCIE){
PORTD=0x0b;
while(PIR1bits.RCIF){
DDR[Rx++]=RCREG;
PORTD=0x10;
if(Rx>149) Rx=0,memset(DDR,0,sizeof(DDR));break;
}
Send=1;
}
INTCONbits.INT0IF=0;
INTCONbits.TMR0IF = 0;
INTCONbits.RBIF=0;
}
void PIC18F_Low_isr (void)
{
/*同上*/
PIR1bits.RCIF=0;
PIR1bits.TXIF=0;
INTCONbits.RBIF=0;
INTCONbits.TMR0IF=0;
INTCONbits.INT0IF=0;/*清除中断标记*/
}
现在程序接发都能实现 但是返回的数据不对 发送的是123456789 返回的是1 123456789 123456789 不知道是哪里的问题 求指教 |