2017年1月17日 星期二

lcd 16*2 spi 通訊練習(一)

Arduino UNO內定10,11,12,13為SPI通信界面使用
10 :SS chip select從設備致能信號,由主設備控制
11 : MOSI  主設備數據輸出,從設備數據輸入
12 : MISO  主設備數據輸入,從設備數據輸出
13 : CLOCK 時鐘信號,由主設備產生

9.

http://coopermaa2nd.blogspot.tw/2010/12/arduino-lab9-2x16-lcd-world.html
[image[20].png]

腳位編號名稱說明
1Vss接地 (0V)
2Vdd電源 (+5V)
3Vo 或稱 Vee對比(0-5V), 可接一顆 1k 電阻,或利可變電阻調整適當的對比
4RSRegister Select:
  1: D0 – D7 當作資料解釋
  0: D0 – D7 當作指令解釋
5R/WRead/Write mode:
  1: 從 LCD 讀取資料
  0: 寫資料到 LCD

因為很少從 LCD 這端讀取資料,可將此腳位接地以節省 I/O 腳位。
6EEnable
7D0Bit 0 LSB
8D1Bit 1
9D2Bit 2
10D3Bit 3
11D4Bit 4
12D5Bit 5
13D6Bit 6
14D7Bit 7 MSB
15A+背光(串接 330R 電阻到電源)
16K-背光(GND)


/* Lab9 - 在 2x16 LCD 上顯示 "Hello World" 訊息  
  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
 * 10K Potentiometer:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// 引用 LiquidCrystal Library
#include <LiquidCrystal.h>

// 建立 LiquidCrystal 的變數 lcd
//                 LCD 接腳:  rs, enable, d4, d5, d6, d7  
//      對應到 Arduino 接腳:  12,     11,  5,  4,  3,  2
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // 設定 LCD 的行列數目 (2 x 16)
  lcd.begin(16, 2);

  // 列印 "Hello World" 訊息到 LCD 上
  lcd.print("hello, world!");
}

void loop() {
  // 將游標設到 column 0, line 1
  // (注意: line 1 是第二行(row),因為是從 0 開始數起):
  lcd.setCursor(0, 1);

  // 列印 Arduino 重開之後經過的秒數
  lcd.print(millis()/1000);
}
============================

#include<Wire.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Hello,World!");

}
===========================
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  //lcd.clear;
  lcd.setCursor(0, 0);
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Serial.available()>0)
   {
   // String msg=Serial.readString();
 
    //lcd.print(msg);
    //lcd.print(millis()/1000);
    while (Serial.available()>0)
    {
      lcd.write(Serial.read());
    }
 
   }
}
=========================
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);
String msg;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  lcd.begin(16, 2);
  //lcd.clear;
  lcd.setCursor(0, 0);
  lcd.blink();
}
================================
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);
String msg;
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.clear();
}
void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(10,0);
  lcd.print("Hello");
  for(int i=0;i<10;i++)
  {
    lcd.scrollDisplayLeft();
    delay(500);
   }
   for(int i=0;i<10;i++)
  {
    lcd.scrollDisplayRight();
    delay(500);
   }
}
==============================
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11,10, 5, 4, 3, 2);
int count=0;
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);

}
void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(0,1);
  lcd.print(count);
  if (count<0)
  {
    count=0;
  }
  else
  {
    lcd.print(count);
  }
  delay(1000);
  count++;
  if (count==0)
  {
    count=10;
  }
}
===============================

沒有留言:

張貼留言