⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rot_module.c

📁 PIC_Hi-Tech_C_Mike_Pearces_I2C_routines Microchi PIC_Hi-Tech C_I2C_for_EEPROM_24LC01B Code
💻 C
字号:
#define ROT1      RB7#define ROT0      RB6#define ROT1_IN  TRISB7=1#define ROT0_IN  TRISB6=1#define ROT_S0 0#define ROT_S1 1#define ROT_S2 2#define ROT_S3 3volatile unsigned char state,last_state,rotcount,last_rotcount;volatile unsigned char rotdir,rot_min,rot_max;void update_rotary_state(void){  state = 0;  if (ROT0) state = state | 0x01;  //set LSb  if (ROT1) bitset(state,1);  switch(state) {  case ROT_S0:    if (last_state == ROT_S1) {      rotcount++; rotdir = 1; last_state = state;    }else if (last_state == ROT_S2) {      rotcount--;rotdir = 0; last_state = state;    }break;  case ROT_S1:    if (last_state == ROT_S3) {      rotcount++;rotdir=1; last_state = state;    }    else if (last_state == ROT_S0) {      rotcount--; rotdir=0; last_state = state;    }break;  case ROT_S2:    if (last_state == ROT_S0) {      rotcount++; rotdir=1;last_state = state;    }    else if (last_state == ROT_S3) {      rotcount--;rotdir=0;last_state = state;    }break;  case ROT_S3:    if (last_state == ROT_S2) {      rotcount++; rotdir=1;last_state = state;    }    else if (last_state == ROT_S1) {      rotcount--; rotdir=0;last_state = state;    }break;  }  if (rotdir){    // incremented    if (rotcount == (rot_max+1)) rotcount = rot_min;  } else {    //decremented    if (!rot_min && (rotcount > rot_max)) rotcount = rot_max;    else if (rotcount == (rot_min-1)) rotcount = rot_max;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -