| 
 
| 小弟在使用STC12时延时程序设置的500毫秒,没有加串口2的中断程序void UART2_Routine(void)    interrupt 8 时延时程序正常使用,加上后不知道为什么延时扩大了8倍,变成了4s。程序如下:#include<STC12C5A60S2.H> #define uint unsigned int
 #define uchar unsigned char
 
 uchar code RecNum00[6]="102000"
 void init()//初始化串口2
 {
 S2CON= 0x50;//方式1允许串口2接收
 BRT  = 0xFD;//设置独立波特率发生器 BRT 的自动重装数
 AUXR= 0x10;//BRTR位=1启用独立波特率发生器
 AUXR1= 0x00; //可取缺省为P1
 
 IE2  = 0x01;//开串口2中断ES2=1;
 ES=1;
 EA   = 1;//开总中断
 }
 
 /****************************串口发送GPRS字符串(数组)**********************/
 
 void delayms(uint t)
 {
 uint i,j;
 for(i=t;i>0;i--)
 for(j=920;j>0;j--);
 }
 void send(uchar *str)
 {
 uint i;
 for(i=0;i<6;i++)
 {
 S2BUF=*str++;
 while(S2CON&0x02==0);
 S2CON = S2CON & 0xFD;
 delayms(100);
 
 }
 }
 main()
 {
 
 init();
 IE2  = 0x00;//开串口2中断ES2=1;
 send(RecNum00);
 S2BUF=0x30;
 while(S2CON&0x02==0);
 S2CON = S2CON & 0xFD;
 IE2  = 0x01;//开串口2中断ES2=1;
 P2=0x0f;
 delayms(500);
 P2=0xf0;
 }
 void UART2_Routine(void)    interrupt 8
 {
 
 }
 我用P2口连接的8个LED观察延时效果,  谢谢。
 | 
 |