求助:1602显示字符乱码,编码器选择到第七选项五显示-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 695|回复: 2

[未解决] 求助:1602显示字符乱码,编码器选择到第七选项五显示

[复制链接]
发表于 2022-2-3 21:32 | 显示全部楼层 |阅读模式
网上下载的Arduino程序,使用的LCD1602A显示字符。程序下载到板子,开机显示英文和数字都正常,只是在后面的单位ML却显示乱码。用编码器选择到第七选项时,显示器直接显示全屏的小方块。我把程序相关部分贴到下面,有高手给我指点指点,到底什么原因造成的。
// include the library code:
#include <LiquidCrystal.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
#include <EEPROM.h>


//LCD -----------------------------------------------------------------------------------
#define LCD_PIN_D4 8
#define LCD_PIN_D5 9
#define LCD_PIN_D6 10
#define LCD_PIN_D7 11
#define LCD_PIN_RS 13
#define LCD_PIN_EN 12
#define LCD_COLUMNS 16
#define LCD_ROWS 2
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(LCD_PIN_RS, LCD_PIN_EN, LCD_PIN_D4, LCD_PIN_D5, LCD_PIN_D6, LCD_PIN_D7);

//ENCODER --------------------------------------------------------------------------------
#define ENCODER_PIN_BUTTON 2
#define ENCODER_PIN_A 3
#define ENCODER_PIN_B 4
ClickEncoder *encoder;
int16_t last, value;

//STEP MOTOR -----------------------------------------------------------------------------
#define MOTOR_STEP_PIN 7
#define MOTOR_DIR_PIN 6
#define STEP_MODE 4 // (1: Full Step, 2: Half Step, 4: Quarter Step, ...)
#define STEPS_PER_FULL_ROT 200 // @ full steps
long delay_us;
long steps;
long step_counter = 0;

//CALIBRATION -----------------------------------------------------------------------------
#define CALIBR_ROTATIONS 30
#define CALIBR_DURATION 30 // seconds
#define CALIBR_DECIMALS 3
const int CALIBR_DECIMAL_CORR = pow(10,CALIBR_DECIMALS);

//SERIAL COMMUNICATION ---------------------------------------------------------------------
#define BAUD 9600
String inputString = "";         // a String to hold incoming data
boolean stringComplete = false;  // whether the string is complete
long vol_uL=0;
long rate_uL_min =0;
int cal=0;
boolean usb_start=0;
char inChar;


//STATE ------------------------------------------------------------------------------------
boolean in_menu=0;
volatile boolean in_action=0;
boolean menu_entered=0;
boolean menu_left=0;

//GENERAL -----------------------------------------------------------------------------------
#define MICROSEC_PER_SEC 1000000

const unsigned int CALIBR_STEPS = CALIBR_ROTATIONS * STEPS_PER_FULL_ROT * STEP_MODE;
const unsigned int CALIBR_DELAY_US = (CALIBR_DURATION * MICROSEC_PER_SEC)/(CALIBR_STEPS*2);


//MENU ---------------------------------------------------------------------------------------
#define MAX_NUM_OF_OPTIONS 4
#define NUM_OF_MENU_ITEMS 10
#define VALUE_MAX_DIGITS 4
int menu_number_1=0;
int menu_number_2=1;
boolean val_change =0;
double value_dbl;
char value_str[VALUE_MAX_DIGITS+1];

enum menu_type {
  VALUE,
  OPTION,
  ACTION
};

typedef struct
{
  const char* name_;
  menu_type type; //0: value type, 1ption type, 2:action type
  int value;
  int decimals;
  int lim;
  const char* options[4];
  const char* suffix;
}menu_item;
int menu_items_limit = 10-1;
menu_item menu[10];


//███ SETUP ████████████████████████████████████████████████████████████████████████████████████████████████████
void setup(){

pinMode(MOTOR_STEP_PIN,OUTPUT);
pinMode(MOTOR_DIR_PIN,OUTPUT);
digitalWrite(MOTOR_DIR_PIN,LOW);
digitalWrite(MOTOR_STEP_PIN,LOW);

menu[0].name_ = "Start";
menu[0].type = ACTION;
menu[0].value = 0;
menu[0].lim = 0;
menu[0].suffix = "RUNNING!";

menu[1].name_ = "Volume";
menu[1].type = VALUE;
menu[1].value = 0;
menu[1].decimals = 1;
menu[1].lim = 9999;
menu[1].suffix="mL";

menu[2].name_ = "V.Unit:";
menu[2].type = OPTION;
menu[2].value = 0;
menu[2].lim = 3-1;
menu[2].options[0] = "mL";
menu[2].options[1] = "uL";
menu[2].options[2] = "rot";

menu[3].name_ = "Speed";
menu[3].type = VALUE;
menu[3].value = 0;
menu[3].decimals = 1;
menu[3].lim = 999;
menu[3].suffix="mL/min";

menu[4].name_ = "S.Unit:";
menu[4].type = OPTION;
menu[4].value = 0;
menu[4].lim = 3-1;
menu[4].options[0] = "mL/min";
menu[4].options[1] = "uL/min";
menu[4].options[2] = "rpm";

menu[5].name_ = "Direction:";
menu[5].type = OPTION;
menu[5].value = 0;
menu[5].lim = 2-1;
menu[5].options[0] = "CW";
menu[5].options[1] = "CCW";

menu[6].name_ = "Mode:";
menu[6].type = OPTION;
menu[6].value = 0;
menu[6].lim = 3-1;
menu[6].options[0] = "Dose";
menu[6].options[1] = "ump";
menu[6].options[2] = "Cal.";

menu[7].name_ = "Cal.";
menu[7].type = VALUE;
menu[7].value = 0;
menu[7].decimals = CALIBR_DECIMALS;
menu[7].lim = 20000;
menu[7].suffix="mL";

menu[8].name_ = "Save Sett.";
menu[8].type = ACTION;
menu[8].value = 0;
menu[8].lim = 0;
menu[8].suffix = "OK!";

menu[9].name_ = "USB Ctrl";
menu[9].type = ACTION;
menu[9].value = 0;
menu[9].lim = 0;
menu[9].suffix = "ON!";

字符单位显示乱码

字符单位显示乱码


选择到第七项全屏方块

选择到第七项全屏方块

 楼主| 发表于 2022-2-8 18:02 | 显示全部楼层
没人能帮我一下吗?如果付费是不是有人可以帮呢?
发表于 2022-2-9 16:45 | 显示全部楼层
你这程序就到setup,关键部分全没有
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 15:38 , Processed in 0.174916 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表