您的当前位置:首页PIC16F887单片机RB口矩阵按键中断唤醒睡眠模式

PIC16F887单片机RB口矩阵按键中断唤醒睡眠模式

2021-10-19 来源:爱问旅游网
#include

__CONFIG(HS & WDTDIS &DEBUGDIS& PWRTEN & MCLRDIS & UNPROTECT & DUNPROTECT & BORXSLP & IESODIS & FCMDIS & LVPDIS); #define uchar unsigned char #define uint unsigned int

static bank3 key_dat; static bank3 row; static bank3 line;

static bank3 keyvalue;

const uchar key_c[3] = {0x30,0x28,0x18}; //--------------------------------------- void delay50us(unsigned char z); void judge_keyvalue(void); void init(void);

//--------------------------------------- void delay50us(unsigned char z) {

unsigned char i,j; for(i=0;i//---------------------------------------- void judge_keyvalue(void) {

switch(key_dat) {

case 0x06:row = 1;break; //第一行 case 0x05:row = 2;break; //第二行 case 0x04:row = 3;break; //第三行 default:break; }

keyvalue = 3*line+row; //算键值 PORTD = ~keyvalue; }

//-------------------------

void interrupt RB_IO(void) {

uchar i; if(RBIF) {

key_dat = PORTB&0x07; if(key_dat!=0x07)

{

for(i=0;i<3;i++) {

PORTB = key_c[i]; line = i; NOP(); NOP();

key_dat = PORTB&0x07; if(key_dat!=0x07) {

judge_keyvalue(); break; } }

PORTB = 0x00; key_dat = PORTB ; RBIF = 0; }

else //键释放 {

PORTB = 0x00; key_dat = PORTB ; RBIF = 0; } } }

//---------------------------------------- void init(void) {

OSCCON = 0x61; OPTION = 0x00; WPUB = 0x07; INTCON = 0x88; ANSELH = 0x00; IOCB = 0x07; TRISB = 0x07; RB3 = 0; RB4 = 0; RB5 = 0;

TRISD = 0x00; PORTD = 0x55; }

//---------------------------------------- void main()

{

init(); while(1) {

SLEEP(); //进入睡眠模式;等待WDT溢出唤醒 NOP(); } }

因篇幅问题不能全部显示,请点此查看更多更全内容