不知道程序哪出问题了,想要用DS12C887的闹钟功能产生闹钟中断,进入外部中断关闭LED。比如支持最小定时1分钟,但是IRQ就是不产生下降沿,没法进入中断,到底咋回事?大神们帮忙看看啊! #include <reg52.h> #define uint unsigned int #define uchar unsigned char sbit DIM=P2^0; sbit dscs=P1^1; sbit dsas=P1^2; sbit dsrw=P1^3; sbit dsds=P1^4; sbit dsirq=P3^3; uchar tmp,temp,flagding,scale,flag; uchar Buffer[1]={0x00}; void init(); void init_USART(); uint TQ(uchar n); void set_time(); void set_alarm(uchar,uchar,uchar); uchar read_ds(uchar); void write_ds(uchar,uchar); void main() { scale=100; init(); init_USART(); DIM=1; while(1) { if(flag==1) { scale=TQ(tmp); flag=0; } else scale=scale; if(flagding==1) { uchar shi,fen; flagding=0; shi=(temp&0xf0)>>4; fen=temp&0x0f; set_time(); set_alarm(shi,fen,0); write_ds(0x0B,0x26); dscs=0; EX1=1; } } } void init() { TMOD=0X22; TH0=0xD2; //定时初值设置为50us TL0=0xD2; EA=1; ET0=1; TR0=1;
} void init_USART() //串口初始化 { SCON=0x50; //设置串口通信数据位为8位 TMOD=0x22; //设置定时器1 TH1=0xFD; //设置波特率为9600 TL1=0xFD; TR1=1; EA=1; ES=1; read_ds(0x0c); EX1=1; //开外部中断1 IT1=1; //跳沿触发 } void timer0() interrupt 1 //定时器0产生PWM波,周期5ms { static uint t; t++; if(t==100) { t=0; DIM=1; } if(t<=scale) DIM=1; else DIM=0; } void USART() interrupt 4 //串口通信,接收蓝牙信息 { uchar n; if(RI) { RI=0; EA=0; n=SBUF; if(Buffer[0]!=0x00) { temp=n; //定时时间 Buffer[0]=0x00; EA=1; flagding=1; } else if(n==0x7A) //0x7A为定时信号,下一字符将要接收定时时间 { Buffer[0]=n; EA=1; } else { tmp=n; EA=1; flag=1; } } } unsigned int TQ(uchar n)//将字符转换成数字 { uint date,shu; if(n==0x6F) //如果接收字符为'o',开灯 return 100; else if(n==0x73) //如果接收字符为's',关灯 return 0; else if(n>=0x00 && n<=0x63) //如果接收的字符在指定的范围内 { date=n/10; shu=n%10; shu=date*10+shu; return shu; } else return scale; //否则保持之前状态 }
void write_ds(uchar add,uchar date) //写时钟芯片 { dscs=0; dsas=1; dsds=1; dsrw=1; P0=add; dsas=0; dsrw=0; P0=date; dsrw=1; dsas=1; dscs=1; } uchar read_ds(uchar add) //读时钟芯片 { uchar ds_date; dsas=1; dsds=1; dsrw=1; dscs=0; P0=add; dsas=0; dsds=0; P0=0xff; ds_date=P0; dsds=1; dsas=1; dscs=1; return ds_date; }
void set_time() //设置时间为零点零分零秒,为定时关灯设置时间基准 { write_ds(4,0); write_ds(2,0); write_ds(0,0); } void set_alarm(uchar ashi,uchar afen,uchar amiao) //设置关灯时间 { write_ds(1,amiao); write_ds(3,afen); write_ds(5,ashi);
} void exter() interrupt 2 { uchar c; c=read_ds(0x0c); scale=0; dscs=1; EX1=0; }
|