STC 官方有例程 平时想用什么功能呢个先看看ISP软件上有没有自己需要的,
#include "reg51.h"
#include "intrins.h"
sfr INTCLKO = 0x8f;
#define EX2 0x10
#define EX3 0x20
#define EX4 0x40
sbit P10 = P1^0;
sbit P11 = P1^1;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
void INT0_Isr() interrupt 0
{
P10 = !P10; //测试端口
}
void INT1_Isr() interrupt 2
{
P10 = !P10; //测试端口
}
void INT2_Isr() interrupt 10
{
P10 = !P10; //测试端口
}
void INT3_Isr() interrupt 11
{
P10 = !P10; //测试端口
}
void INT4_Isr() interrupt 16
{
P10 = !P10; //测试端口
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
IT0 = 0; //使能INT0上升沿和下降沿中断
// IT0 = 1; //使能INT0下降沿中断
EX0 = 1; //使能INT0中断
IT1 = 0; //使能INT1上升沿和下降沿中断
// IT1 = 1; //使能INT1下降沿中断
EX1 = 1; //使能INT1中断
INTCLKO = EX2; //使能INT2下降沿中断
INTCLKO |= EX3; //使能INT3下降沿中断
INTCLKO |= EX4; //使能INT4下降沿中断
EA = 1;
PCON = 0x02; //MCU进入掉电模式
_nop_(); //掉电模式被唤醒后,MCU首先会执行此语句
//然后再进入中断服务程序
_nop_();
_nop_();
_nop_();
while (1)
{
P11 = ~P11;
}
}
|