Skip to content

Commit

Permalink
初步完成功能
Browse files Browse the repository at this point in the history
  • Loading branch information
rinscr3003 committed Jan 12, 2024
1 parent 8c9b391 commit ecc16be
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 11 deletions.
85 changes: 79 additions & 6 deletions Lib/GPIO.C
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,102 @@ void EC_Cfg()
// INT off
EX0 = 0;
EX1 = 0;
// Init gpios
// Init gpios
Port3Cfg(0, 4); // P3.4 EC_KEY
Port3Cfg(0, 2); // P3.2 EC_A
Port3Cfg(0, 3); // P3.3 EC_B
// Init ints
IT0 = 1; // FALLEDGE trig
IT1 = 1;
// INT on
// INT on
EX0 = 1;
EX1 = 1;
}

volatile short data ec_count = 0;
volatile bit data ec_rotating = 0;

void EC_IntA(void) interrupt INT_NO_INT0 using 2 // INT0中断服务程序,使用寄存器组2
{
;
if (ec_rotating)
{
// A相后动
if (EC_B == 1)
{
// 不合理的,丢步了
// LEDA = 1;
// LEDB = 1;
}
else
{
// 方向1转完了
ec_count++;
// LEDA = 1;
}
ec_rotating = 0;
}
else
{
// A相先动
if (EC_B == 1)
{
// 方向1起转
ec_rotating = 1;
// LEDA = 0;
}
else
{
// 不合理的,丢步了
ec_rotating = 0;
// LEDA = 1;
// LEDB = 1;
}
}
}

void EC_IntB(void) interrupt INT_NO_INT1 using 2 // INT0中断服务程序,使用寄存器组2
void EC_IntB(void) interrupt INT_NO_INT1 using 3 // INT1中断服务程序,使用寄存器组2
{
;
if (ec_rotating)
{
// B相后动
if (EC_A == 1)
{
// 不合理的,丢步了
// LEDA = 1;
// LEDB = 1;
}
else
{
// 方向2转完了
ec_count--;
// LEDB = 1;
}
ec_rotating = 0;
}
else
{
// B相先动
if (EC_A == 1)
{
// 方向2起转
ec_rotating = 1;
// LEDB = 0;
}
else
{
// 不合理的,丢步了
ec_rotating = 0;
// LEDA = 1;
// LEDB = 1;
}
}
}

short EC_Read()
{
return 0;

short cnt = ec_count;
// if (!ec_rotating)
ec_count = 0;
return cnt;
}
7 changes: 7 additions & 0 deletions Lib/GPIO.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
void Port1Cfg(UINT8 Mode, UINT8 Pin);
void Port3Cfg(UINT8 Mode, UINT8 Pin);

sbit EC_A = P3 ^ 2;
sbit EC_B = P3 ^ 3;
sbit EC_KEY = P3 ^ 4;

sbit LEDA = P1 ^ 4;
sbit LEDB = P1 ^ 5;

void EC_Cfg();
short EC_Read();
10 changes: 5 additions & 5 deletions SnapDial.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <string.h>
#include <stdio.h>

sbit EC_A = P3 ^ 2;
sbit EC_B = P3 ^ 3;
sbit EC_KEY = P3 ^ 4;

#define THIS_ENDP0_SIZE DEFAULT_ENDP0_SIZE
#define ENDP1_IN_SIZE 16

Expand Down Expand Up @@ -455,6 +451,10 @@ main()
CfgFsys();
mDelaymS(5); // 修改主频等待内部晶振稳定,必加

Port1Cfg(3, 4);
Port1Cfg(3, 5);
LEDA = 1;
LEDB = 1;
EC_Cfg();

// USBDeviceReset();
Expand All @@ -469,7 +469,7 @@ main()
{
FLAG_EP1 = 0;
HIDDial[1] = (EC_KEY) ? 0x00 : 0x01;
DialRotation = EC_Read();
DialRotation = EC_Read()*50;
HIDDial[2] = DialRotation & 0x00ff;
HIDDial[3] = ((DialRotation & 0xff00) >> 8);
Enp1IntIn();
Expand Down

0 comments on commit ecc16be

Please sign in to comment.