板子:
功能描述:led灯L1不断闪烁,通过低电平触发中断,中断内容是点亮一段时间led灯L8,执行完毕之后继续执行闪烁L1。
代码实现:
- #include <STC15F2K60S2.H>
- #include "intrins.h"
-
- sbit L1 = P0^0;
- sbit L8 = P0^7;
-
- void Delay1ms(int x);
-
- void InitHC138(unsigned char n)
- {
- switch(n)
- {
- case 4:
- P2 = (P2 & 0x1f) | 0x80;
- break;
- case 5:
- P2 = (P2 & 0x1f) | 0xa0;
- break;
- case 6:
- P2 = (P2 & 0x1f) | 0xc0;
- break;
- case 7:
- P2 = (P2 & 0x1f) | 0xe0;
- break;
- }
- }
-
- void INT0Init()
- {
- IT0 = 1;
- EX0 = 1;
- EA = 1;
- }
-
- void ServiceINT0() interrupt 0
- {
- L8 = 0;
- Delay1ms(1000);
- L8 = 1;
- }
-
- void LEDInit()
- {
- L1 = 0;
- Delay1ms(200);
- L1 = 1;
- Delay1ms(200);
- }
- void main()
- {
- INT0Init();
- InitHC138(4);
- while(1)
- {
- LEDInit();
- }
- }
-
- void Delay1ms(int x) //@11.0592MHz
- {
- int y;
- y = x;
- while(x--)
- {
- unsigned char data i, j;
-
- _nop_();
- _nop_();
- _nop_();
- i = 11;
- j = 190;
- do
- {
- while (--j);
- } while (--i);
- }
- x = y;
- }