xuwanzhao 发表于 2012-5-20 00:03:18

关于52扩展串口摄像头拍照不能传回正确程序的问题,看程序

本帖最后由 xuwanzhao 于 2012-5-20 00:09 编辑

扩展了52的8K内存,控制串口摄像头拍照,发送拍照命令,摄像头有反应,但发现内存里没有摄像头传应该传回的数据,(接线方式我是直接把串口摄像头9孔串口的TXD和RXD和地分别接到52单片机max232的8、7针和地上)程序如下,帮看下,谢谢
#include   <reg51.h>
//#include   <STDLIB.H> //包含头文件
#define   uint   unsigned   long int
#define   uchar   unsigned   char
//**********函数定义**********//
void   main(void);   //主函数
void   Ini_UART(void);   //串口初始化
void   Delay(void);      //延时
//void   CMGF(void);       //设置发送数据为TXET格式
void   CMGS(void);   //设置目的手机号码
void   SEND(void);   //发送字符串
sbit d1=P1^1;
sbit d2=P1^0;
sbit d3=P1^2;
uint Rx=0;
uint j=0;
uchar flag,a;
uint h,h1,bigain,end;
uchar xdata SystemBuf;
uchar   code   phone[]= {0x40,0x40,0x61,0x80,0xFF,0xFF,0xff,0xff,0x0D,0x0A,0x00};
//uchar   code   sms[]   = "AT+QFUPL=\"KKK.jpg\"";
void sendchar(uchar ch);
void sendstring(uchar *p);
void   Delay1(void);
void sendchar(uchar ch)
{
SBUF=ch;
while(TI==0);
TI=0;
}
void sendstring(uchar *p)
{

while(*p)
{
sendchar(*p);
p++;
}
}
/***********************************************************
函数名称:main
函数功能:主函数                                 入口参数:无         出口参数:无
***********************************************************/
void   main(void)
{
   Ini_UART();
   while(1)
{
   if(d2==0)
          Delay1();
          if(d2==0)
         {
      Ini_UART();   //串口初始化
      sendstring(phone);   //发拍照命令
                d2=1;

                }
       if(d3==0)
          Delay();
          if(d3==0)
       {
      sendchar(0xAA);
      for(h=0;h<3500;h++)
      {      
                   if(SystemBuf==0xff&&SystemBuf==0xd8)
                      bigain=h;
                   if(SystemBuf==0xff&&SystemBuf==0xd9)
                      end=h+1;
               }
       for(h1=bigain;h1<end+1;h1++)
            {
                SBUF=SystemBuf;
                while(!TI);
                TI=0;
                ES=1;
      }
      d3=1;
                sendchar(0xA0);
       }
       if(d1==0)
          Delay();
          if(d1==0)
       {
      sendchar(0x0A);
      Delay1();
       for(h1=0;h1<3500;h1++)//传回内存里3500个数看看
            {
                SBUF=SystemBuf;
                while(!TI);
                TI=0;
                ES=1;
      }
      d1=1;
       }
}
}

/***********************************************************
函数名称:Ini_UART
函数功能:串口初始化设置               入口参数:无         出口参数:无
***********************************************************/
void   Ini_UART(void)
{
      SCON   =   0x50;   //UART方式1:8位UART;   REN=1:允许接收
      PCON   =   0x00;   //SMOD=0:波特率不加倍

      TMOD   =   0x20;   //T1方式2,用于UART波特率

      TH1   =   0xFd;
      TL1   =   0xFd;   //UART波特率设置:9600
      TR1   =   1;
      // REN=1;
       SM0=0;
       SM1=1;   
       EA=1;
       ES=1;
}


/***********************************************************
函数名称:Delay1ms
函数功能:延时                                 入口参数:无         出口参数:无
**********************************************************    */      
void receive(void) interrupt 4
{
if(RI)
{
      if(Rx<3500)
      {
    SystemBuf=SBUF;
      Rx++;
      }
      RI=0;
}
}

void   Delay(void)
{      
      uint   i,j;

      for   (i=0;   i <10;   i++)
      {
            for(j=0;   j <1000;   j++);
      }
}

void   Delay1(void)
{      
      uint   i,j;

      for   (i=0;   i <100;   i++)
      {
            for(j=0;   j <1000;   j++);
      }
}

xuwanzhao 发表于 2012-5-20 14:07:14

现在可以存数据了,但存的数据不太不准确,传3000个少400个数,为什么?我怀疑是单片机SBUF存到外存时速度慢了。前面存不了数据是因为我在52的板子上还接了9针串口连上电脑,不连就可以了。但也不明白为什么
页: [1]
查看完整版本: 关于52扩展串口摄像头拍照不能传回正确程序的问题,看程序