我让代码从SIM900A内存中读取短信,但是没有正确接收字符串。我想在LCD 16 * 2上打印收到的字符,但是如果发送“ABCDEFGH”,那么只有“ABC”打印在LCD上后续字符被打印为垃圾。
#define led1 PORTC.F1
#define led PORTC.F0
#define RS PORTC.F1
#define RW PORTC.F2
#define EN PORTC.F3
unsigned char inchar;
unsigned char a[]={"#on"};
unsigned char b[]={"#of"};
unsigned int i=0,j,k=0,l=0,m;
char *buffer[80] ;
void Tx();
void rcv();
void cmd( unsigned char x);
void dat ( unsigned char x );
void int_lcd();
void main()
{
TRISD=0x00;
TRISC=0x80;
led=0;
led1=0;
UART1_Init(9600);
delay_ms(300);
UART1_Write(0x0D);
delay_ms(300);
UART1_Write_Text("AT+CMGF=1");
UART1_Write(0x0D);
delay_ms(300);
UART1_Write_Text("AT+CNMI=2,2,0,0" );
UART1_Write(0x0D);
delay_ms(300) ;
UART1_Write_Text("AT+CMGR=1");
UART1_Write(0x0D);`enter code here`
delay_ms(300);
PIR1.RCIF=0;
int_lcd();
while(1)
{ i=0;
while(UART1_Data_Ready()==1)
{ rcv();
}
if(UART1_Data_Ready()==0 )
{
for (j=0;j<i;j++)
{
dat(buffer[j]);
delay_ms(100);
if(j==15)
cmd(0xc0);
}
}
UART1_Write_Text("AT+CMGD=1,4");
}
}
void rcv()
{
while(PIR1.RCIF==1){
PIR1.RCIF=0;
inchar=UART1_Read();
buffer[i]=inchar ;
i++; }
if (RCSTA.OERR==1||RCSTA.FERR==1)
{
k = RCREG;
RCSTA.CREN = 0;
PIR1.RCIF = 0;
RCSTA.CREN = 1;
return;}
}
void cmd( unsigned char x)
{
PORTD=x;
RS=0;
RW=0;
EN=1;
delay_ms(100);
EN=0;
}
void dat ( unsigned char x )
{
PORTD=x;
RS=1;
RW=0;
EN=1;
delay_ms(100);
EN=0;
}
void int_lcd()
{
cmd(0x38);
cmd(0x0e);
cmd(0x01);
cmd(0x06);
cmd(0x80);
}
这是我的代码