|
#include<regx52.h>
#include <absacc.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
//#define MT8888_CTRL_REG XBYTE[0x1ff]//P2.1=0
//#define MT8888_DATA_REG XBYTE[0x0ff]//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;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|