中断程序访问全局变量与子程序访问的同一变量,内容不...
keil c中断程序访问全局缓冲区与子程序访问的同缓冲区,里面的内容为什么不一样?//uart.h
extern char Uart0_buf;
externint Uart0_buf_cnt;
//uart.c
static char Uart0_buf;
int Uart0_buf_cnt=0;
void Uart0_isr_p()
{
if(!TI0 ) //是发送中断还是接收中
{
/*清接收标志位*/
Uart0_temp1 =SBUF0; /*保存接收到的数据*/
Uart0_buf=Uart0_temp1;
Uart0_buf_cnt++;
if (Uart0_buf_cnt>=256) Uart0_buf_cnt=0;
Uart0_ReceiveBit=1; /*置接收标*/
RI0 = 0;
}
TI0 = 0; /*清发送标志位*/
}
//wavecom_gprs.c
#include "c8051f020.h"
#include <string.h>
#include ".\uart\uart.h"
#include ".\io_ToUart\SimUart.h"
#include ".\wavecom_gprs\wavecom_gprs.h"
#include ".\general\general.h"
//extern char Uart0_buf;
//extern int Uart1_buf_cn;
void WaveCom_TestGprsModule()
{
unsigned char *gprs_str1="AT\r\n";
unsigned char gprs_replay;
//Uart0_RCV_Enable(1);//禁用接收功能
CLR_buf(Uart0_buf,256);
CLR_buf(gprs_replay,20);
Uart0_buf_cnt=0;
//SimUart1_WriteString("\r\nGPRS Moudle Testing....",strlen("\r\nGPRS Moudle Testing...."));
//SimUart1_WriteString("\r\nSending \"AT\" Order....",strlen("\r\nSending \"AT\" Order...."));
//Uart0_RCV_Enable(1);
//SimUart1_WriteString(gprs_str1,strlen(gprs_str1));
SimUart1_WriteString("Testing GPRS Module,Sending 'AT' Order...\r\n",strlen("Testing GPRS Module,Sending 'AT' Order...\r\n"));
//SimUart1_WriteString(BodrateStr,strlen(BodrateStr));
Uart0_SendString(gprs_str1);
//打开接收功能
delayms(1000);//等待一秒钟,让uaet0的中断程序接收返回的数据
//Uart0_RCV_Enable(0);//禁用接收功能
if (Uart0_buf_cnt==0)
{
//printf("从站无响应");
SimUart1_WriteString("GPRS module is not Respond,please check CPU,uart0 line or GPRS module...\r\n",strlen("GPRS module is not Respond,please check CPU,uart0 line or GPRS module...\r\n"));
}
else
{
//Uart0_SendString("recived some data:\r\n");
//Uart0_SendString(Uart0_buf);
SimUart1_WriteString("Recving Replay String:...\r\n",strlen("Recving Replay String:...\r\n"));
SimUart1_WriteString(Uart0_buf,Uart0_buf_cnt);
//printf("从站返回的数据:%s",gprs_replay);
}
//SimUart1_WriteString("\r\nRecving Replay Sting:...\r\n",strlen("\r\nRecving Replay Sting:...\r\n"));
//SimUart1_WriteString(Uart0_buf,Uart0_buf_cnt);
}
Uart0_buf缓冲区不知道啥时候被更改了,返回的数据总是不对。 定义时加了static还能声明外部引用吗。
keil优化级最高时,在前面加volatile修饰。 去掉static还是不行 volatile 加在什么地方
页:
[1]