|
学了51的掉电与空闲模式 写了一段代码 使用仿真 现象没有如预期 预期实验现象:5s后掉电/空闲,外部中断唤醒单片机;
实际实验现象:按下外部中断,没有唤醒。
代码如下:
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define digTube P0
- unsigned char code table[]=
- {0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,
- 0x39,0x5e,0x79,0x71};
- sbit DULA = P2^0;
- sbit WELA = P2^1;
- uchar time = 0;
- uchar tube = 0;
- void Init();
- void DelayMs(uint xms);
- void Display(uint num);
- void main()
- {
- Init();
-
- while (1)
- {
- Display(tube);
- }
- }
- void T0time() interrupt 1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
-
- time++;
- if (time == 20)
- {
- time = 0;
- tube++;
- if (tube == 6)
- {
- ET0 = 0;
- PCON = 0x01;
- }
- }
- }
- void EXIT0() interrupt 0
- {
- DelayMs(10);
-
- if (INT0 == 0)
- {
- PCON = 0;
- ET0 = 1;
- }
- }
- void EXIT1() interrupt 2
- {
- DelayMs(10);
-
- if (INT1 == 0)
- {
- PCON = 0;
- ET0 = 1;
- }
- }
- void Init()
- {
- TMOD = 0x01;
- TH0 = (65536-45872)/256;
- TL0 = (65536-45872)%256;
- TR0 = 1;
- ET0 = 1;
- EX0 = 1;
- EX1 = 1;
- EA = 1;
- }
- void DelayMs(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=114;j>0;j--);
- }
- void Display(uint num)
- {
- uint shi, ge;
-
- shi = num/10;
- ge = num%10;
- DULA = 0;
- digTube = table[shi];
- DelayMs(1);
- DULA = 1;
-
- WELA = 0;
- digTube = table[ge];
- DelayMs(1);
- WELA = 1;
- }
复制代码
仿真图如下:
|
|