feat(MCU课设): 增加旋转编码器控制逻辑

This commit is contained in:
iridiumR 2022-06-05 20:26:03 +08:00
parent 69a1bf506c
commit aae1585b5c
8 changed files with 813 additions and 565 deletions

File diff suppressed because it is too large Load diff

View file

@ -84,8 +84,6 @@ void drawNAME()
for(j = 0; j < 48; j++)
{
CSA = 1;
CSB = 0;
RS = 0;
@ -113,26 +111,37 @@ void drawNAME()
write();
}
}
void drawFullIMG(unsigned char img[])
void drawMAINMENU()
{
unsigned int j,i;
unsigned int j;
for(j = 0; j < 64; j++)
for(i=0;i<8;i++)
for(j = 0; j < 32; j++)
{
CSA = 1;
CSB = 0;
RS = 0;
RW = 0;
P1 = 0xb8 + i;
P1 = 0xb8 + 0;
write();
P1 = 0X40 + j;
write(); //Ò³iÁÐjÆÁA
write(); //Ò³0ÁÐjÆÁA
RS = 1;
RW = 0;
P1 = img[j - 1];
P1 = MAINMANU_PAGE0[j - 1];
write();
RS = 0;
RW = 0;
P1 = 0xb8 + 1;
write();
P1 = 0X40 + j;
write(); //Ò³1ÁÐjÆÁA
RS = 1;
RW = 0;
P1 = MAINMANU_PAGE1[j - 1];
write();
}
}

View file

@ -3,5 +3,5 @@
void drawNAME();
void drawNUMBER();
void drawMAINMENU();
#endif

View file

@ -52,7 +52,15 @@ code unsigned char NUMBER_RPAGE1[]=
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
};
//第一行:菜单
code unsigned char MAINMANU_PAGE0[]={
0x04,0x04,0x44,0xC4,0x4F,0x44,0x44,0xC4,0x24,0x24,0x2F,0xB4,0x24,0x04,0x04,0x00,
0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,0x48,0x4C,0x4A,0x49,0xF8,0x00,0x00,0x00,
};
code unsigned char MAINMANU_PAGE1[]={
0x40,0x44,0x24,0x24,0x15,0x0C,0x04,0xFE,0x04,0x0C,0x15,0x24,0x24,0x44,0x40,0x00,
0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00,
};
//void writeData(unsigned char d)
//{

View file

@ -1,27 +1,90 @@
#include "delay.h"
#include "main.h"
#include "display.h"
#include "menu.h"
#include "draw.h"
#include "button.h"
extern Menu *NOW;
enum OPR opr=idle;
sbit RS = P2 ^ 0;
sbit RW = P2 ^ 1;
sbit E = P2 ^ 2;
sbit CSA = P2 ^ 4;
sbit CSB = P2 ^ 5;
#define RELOAD (65535-9216) //定时器填充值(1ms)
unsigned char TH, TL;
extern Menu *NOW; //菜单指针
enum OPR opr = idle; //按键状态
unsigned char freshScreenTriger = 0;
void int0() interrupt 0 //外部中断:检测左右旋钮
{
// IE0 = 0; //消抖
// delay(20);
// IE0 = 0;
//
// if(PIN_3 == 0)
// {
// delay(10);
// if(PIN_3 == 0)
// opr = left;
// }
// else if(PIN_3 == 1)
// {
// delay(10);
// if(PIN_3 == 1)
// opr = right;
// }
unsigned char LS, CS, flag = 0;
LS = PIN_3;
while(!PIN_1)
{
CS = PIN_3;
flag = 1;
}
if(flag == 1)
{
if((LS == 0) && (CS == 1))
opr = right;
if((LS == 1) && (CS == 0))
opr = left;
}
}
void time() interrupt 1 //定时中断:检测确认按键
{
EA = 0;
TH0 = TH;
TL0 = TL0 + TL;
TL0 = TL0 + 23;
if(PIN_4 == 0)
{
delay(10);
if(PIN_4 == 0)
opr = confirm;
}
EA = 1;
}
sbit LCDRST =P2^3;
int main()
{
menuInit();
TH = RELOAD / 256; //填充值预计算
TL = RELOAD - (RELOAD / 256) * 256;
TH0 = TH;
TL0 = TL;
TMOD = 0x01; //使用定时器T0高4位全为0,低4位GATE=0C/T=0采用工作方式1M1=0,M1=1
TR0 = 1; //启动定时器0
EA = 1; //打开中断总开关
ET0 = 1; //打开定时器0中断开关
IT0 = 1; //中断触发方式为下边沿触发
EX0 = 1; //打开外部中断0
EA = 1; //打开中断总开关
displayInit(); //屏幕初始化
clear();
menuInit(); //菜单及其他初始化
while(1)
{
NOW->f(NOW,opr);
{
}
NOW->f(NOW, opr);
}
}

View file

@ -5,7 +5,21 @@
#include <intrins.h>
#include <absacc.h>
#include "display.h"
#include "menu.h"
#include "draw.h"
#include "button.h"
#include "delay.h"
sbit RS = P2 ^ 0;
sbit RW = P2 ^ 1;
sbit E = P2 ^ 2;
sbit CSA = P2 ^ 4;
sbit CSB = P2 ^ 5;
sbit LCDRST =P2^3;
sbit PIN_CONFIRM=P3^5;
sbit PIN_1=P3^2;
sbit PIN_3=P3^4;
sbit PIN_4=P3^5;
#endif

View file

@ -2,34 +2,67 @@
#include "display.h"
#include "delay.h"
#include "draw.h"
Menu M_MAINMANU;//寮꽉데
#include <stdio.h>
Menu M_STARTUP;
Menu M_MAINMENU;//主菜单
Menu M_PLAYMODE1; //띤쭈薑렘욥
Menu* NOW; //뎠품꽉데寧濾
Menu* LAST=NULL;//上一个状态的菜单
//놓迦꽉데
void m_startup(struct _menu* this,enum OPR opr)
void m_startup(struct _menu* this, enum OPR opr)
{
displayInit();
clear();
drawNAME();
delay(1000);
drawNUMBER();
delay(3000);
// clear();
NOW=this->n;
if(LAST != &M_STARTUP)
{
LAST = &M_STARTUP;
drawNAME(); //绘制名字
delay(1000);
drawNUMBER(); //绘制学号
}
if(opr == confirm)
{
opr = idle;
NOW = this->n; //转向下一菜单
clear();
}
}
Menu M_STARTUP={&M_MAINMANU,m_startup};
void m_mainmenu(struct _menu* this, enum OPR opr)
{
if(LAST != &M_MAINMENU)
{
LAST = &M_MAINMENU;
drawMAINMENU();
}
if(opr == left)
{
opr = idle;
NOW = &M_STARTUP;
clear();
}
}
void menuInit()
{
NOW=&M_STARTUP;
M_STARTUP.n = &M_MAINMENU;
M_STARTUP.f = m_startup;
M_MAINMENU.f = m_mainmenu;
NOW = &M_STARTUP;
}

View file

@ -4,6 +4,8 @@
typedef struct _menu
{
unsigned char *local;
unsigned char *len;
struct _menu* n;
void(*f)(struct _menu* this, enum OPR opr);
}Menu;