huasucatv 发表于 2011-8-5 15:45:25

MT8888 有一种CP模式可用来检测挂机信号,不过驱动我怎么弄都不对,希望大家帮我看看。

#include<regx52.h>
#include <absacc.h>
#include <intrins.h>
#define uchar unsigned char                                    
#define uintunsigned int
//#define MT8888_CTRL_REG    XBYTE//P2.1=0
//#define MT8888_DATA_REG    XBYTE//P2.1=0 P2.0=0
sbit RSE = P2^0;
sbit CSE = P2^1;
sbit MT_OE = P2^2;         //mt8870 OE
sbit WRE = P3^6;
sbit RDE = P3^7;
sbit OFF_HOOK = P3^5;
uchar count1=0,count2=0;

void delay(unsigned int z)
{
    unsigned int x,y;

        for(x=z; x>0; x--)
        for(y=110; y>0; y--);
}

unsigned char readsr(void)
{
           unsigned char b;   
           WRE=1;
           RDE=0;
           RSE=1;
           CSE=0;
           _nop_();
           _nop_();
           b=P0&0X0f;
           CSE=1;
           return(b);
}
void writesr(unsigned char a)
{
          WRE=0;
          RDE=1;
          RSE=1;
          CSE=0;
          _nop_();
          _nop_();
          P0=a;
          _nop_();
          _nop_();
          CSE=1;
}
unsigned char readdata(void)
{   
   unsigned char b;   
   WRE=1;   
   RDE=0;   
   RSE=0;   
   CSE=0;   
   _nop_();   
   _nop_();   
   b=P0&0x0f;   
   CSE=1;   
   return(b);   
}
void writedata(unsigned char a)   
{   
   WRE=0;   
   RDE=1;   
   RSE=0;   
    CSE=0;   
   _nop_();   
   _nop_();   
   P0=a;   
   _nop_();   
   _nop_();   
   CSE=1;   
}
void mt8888_init(void)
{
unsigned char i;

   MT_OE = 1;
   i = readsr();
   writesr(0x00);
   writesr(0x00);
   writesr(0x08);
   writesr(0x00);
   i = readsr();
   delay(100);

//   delay(100);
//i=readsr();
//        i=0x00;
//        writesr(i);
//        writesr(i);
//        i=0x08;
//        writesr(i);
//        i=0x00;
//        writesr(i);
//        i=readsr();
//        i=0x0e;//14;
//        writesr(i);
//        i=0x00;
//        writesr(i);
//        delay(100);
}
void set_mode(void)
{
writesr(0x0E);
writesr(0x00);
delay(2);
}


void main()
{
   IE0=1;
   IE1=1;
   IT0=1;

   IT1=1; //下降沿触发
   EX0=1;
   EX1=1;
   ET0=0;
   ET1=0;
   EA=1;

mt8888_init();
set_mode();
while(1);
//        {
//       while(1)
//               {
//               if(P3_2==1)
//                       {
//                       count2++;
//                       if(count2==2)
//                               {
//                               count2=0;
//                               OFF_HOOK=1;
//                               }
//                       }
//                }
//    }
}
void ext0() interrupt 0
{       
        count1++;
        if(count1==3)
        {
        EX0=0;
    count1=0;
    OFF_HOOK=0;       
        }
        EX0=1;
}

einfay 发表于 2012-8-7 11:42:44

硬件接线是怎么的?

zhou19852 发表于 2014-8-2 12:32:51

你好,我现在做MT8888,在CP模式下也有些问题需要请教一下,以下是我得求助帖,希望你指教http://www.amobbs.com/forum.php?mod=viewthread&tid=5590057&page=1#pid7732950
页: [1]
查看完整版本: MT8888 有一种CP模式可用来检测挂机信号,不过驱动我怎么弄都不对,希望大家帮我看看。