Lcd1602连接Arduino(uno)或Wemos D1接法与代码

LCD1602有16个引脚  使用1-6号与11-16号引脚

此处LCD1602:#1——#6   #11——#16

#1:负极

#2:正极

#3:1kΩ电阻调节对比度

#4:arduino7号引脚

#5:负极

#6:arduino6号引脚

#11:arduino5号引脚

#12:arduino4号引脚

#13:arduino3号引脚

#14:arduino2号引脚

#15:负极

#16:正极

(没错   GND确实有好多线被连到哈哈哈哈哈哈哈哈哈)

/*
  Wemos D1代码段
  LiquidCrystal Library - display() and noDisplay()

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD and uses the
 display() and noDisplay() functions to turn on and off
 the display.

 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = D7, en = D6, d4 = D5, d5 = D4, d6 = D3, d7 = D2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // Turn off the display:
  lcd.noDisplay();
  delay(500);
  // Turn on the display:
  lcd.display();
  delay(500);
}
/* Arduino UNO代码段  */
#include <LiquidCrystal.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9

MFRC522 mfrc522(10, RST_PIN);   // 创建MFRC实例
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  pinMode(8,OUTPUT);
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("系统开启,请将你的卡片放置感应区...");

  
}

void loop() {
  String content= "";
  lcd.setCursor(0,0);
  lcd.print("Welcome!");
  lcd.print(content);
  // 寻找新卡
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //显示卡号 b6a5eebc 182165238188
  //Serial.print("UID tag :");
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     //Serial.println(mfrc522.uid.uidByte[i]);
     //Serial.print(mfrc522.uid.uidByte[i], HEX);
     content+=mfrc522.uid.uidByte[i];
  }
  if(content!="")
  {
      lcd.setCursor(0,0);
      lcd.print("Your ID:");
      lcd.setCursor(0,1);
      lcd.print(content);
      Serial.println(content);
      digitalWrite(8,HIGH);
      delay(300);
      digitalWrite(8,LOW);
      delay(2000);
      content= "";
      lcd.clear();
  }
  
}
发布了9 篇原创文章 · 获赞 1 · 访问量 2916

猜你喜欢

转载自blog.csdn.net/Tony6666_/article/details/103936661