|
|
(未显示2个用户的4个中间版本) |
第7行: |
第7行: |
| | | |
| ==设备== | | ==设备== |
− | *'''[[Microduino-Core]]''' | + | *'''[[Microduino-Core/zh]]''' |
− | *'''[[Microduino-FT232R]]''' | + | *'''[[Microduino-USBTTL/zh]]''' |
| *其他硬件设备 | | *其他硬件设备 |
| **面包板跳线 一盒 | | **面包板跳线 一盒 |
第22行: |
第22行: |
| | | |
| ==原理图== | | ==原理图== |
− | [[File:第二十七课-Microduino 8*8点阵静态显示原理图.jpg|600px|center|thumb]] | + | [[File:第二十七课-Microduino 8_8点阵静态显示原理图.jpg|600px|center|thumb]] |
| | | |
| | | |
第67行: |
第67行: |
| | 8 || 9 || 7 || Q7 | | | 8 || 9 || 7 || Q7 |
| |} | | |} |
− |
| |
| | | |
| ==程序== | | ==程序== |
− | <source lang="cpp">
| |
− |
| |
− |
| |
− | //Pin 连接到 74HC595的ST_CP
| |
− | int latchPin = 8;
| |
− | //Pin 连接到 74HC595的SH_CP
| |
− | int clockPin = 12;
| |
− | ////Pin 连接到 74HC595的DS
| |
− | int dataPin = 11;
| |
− |
| |
− |
| |
− |
| |
− | void setup() {
| |
− | //波特率为9600,用于调试
| |
− | Serial.begin(9600);
| |
− | //设置 latchpin 为 output
| |
− | pinMode(latchPin, OUTPUT);
| |
− |
| |
− | }
| |
− |
| |
− | void loop() {
| |
− | //Smile for 8x8 Matrix LED
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B01111111); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B00111100); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B10111111); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B01000010); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B11011111); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B10100101); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B11101111); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B10000001); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B11110111); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B10100101); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B11111011); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B10011001); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B11111101); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B01000010); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− | digitalWrite(latchPin, 0);
| |
− | shiftOut(dataPin, clockPin, B11111110); //掩盖的列(col)
| |
− | shiftOut(dataPin, clockPin, B00111100); //行row
| |
− | digitalWrite(latchPin, 1);
| |
− |
| |
− |
| |
− | }
| |
− |
| |
− | void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
| |
− |
| |
− | //初始化设置
| |
− | int i=0;
| |
− | int pinState;
| |
− | pinMode(myClockPin, OUTPUT);
| |
− | pinMode(myDataPin, OUTPUT);
| |
− |
| |
− | //clear everything out just in case to
| |
− | //prepare shift register for bit shifting
| |
− | digitalWrite(myDataPin, 0);
| |
− | digitalWrite(myClockPin, 0);
| |
− |
| |
− | //for each bit in the byte myDataOut�
| |
− | //NOTICE THAT WE ARE COUNTING DOWN in our for loop
| |
− | //This means that %00000001 or "1" will go through such
| |
− | //that it will be pin Q0 that lights.
| |
− | for (i=7; i>=0; i--) {
| |
− | digitalWrite(myClockPin, 0);
| |
− |
| |
− | //if the value passed to myDataOut and a bitmask result
| |
− | // true then... so if we are at i=6 and our value is
| |
− | // %11010100 it would the code compares it to %01000000
| |
− | // and proceeds to set pinState to 1.
| |
− | if ( myDataOut & (1<<i) ) {
| |
− | pinState= 1;
| |
− | }
| |
− | else {
| |
− | pinState= 0;
| |
− | }
| |
− |
| |
− | //Sets the pin to HIGH or LOW depending on pinState
| |
− | digitalWrite(myDataPin, pinState);
| |
− | //register shifts bits on upstroke of clock pin
| |
− | digitalWrite(myClockPin, 1);
| |
− | //zero the data pin after shift to prevent bleed through
| |
− | digitalWrite(myDataPin, 0);
| |
− | }
| |
− |
| |
− | //stop shifting
| |
− | digitalWrite(myClockPin, 0);
| |
− | }
| |
− |
| |
| | | |
− | </source>
| + | [https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Advanced/Microduino8_8static Microduino8_8static] |
| | | |
| ==调试== | | ==调试== |
第185行: |
第76行: |
| | | |
| 步骤二:电路连接如下图: | | 步骤二:电路连接如下图: |
− | [[File:第二十七课-Microduino 8*8点阵静态显示连接图.jpg|600px|center|thumb]] | + | [[File:第二十七课-Microduino 8_8点阵静态显示连接图.jpg|600px|center|thumb]] |
| 为了更好的保护电路,可以在其中一个74HC595芯片连接8*8点阵之间的八条线中各加一个220欧姆电阻,本例中没有加入电阻所以LED特别亮,如果点阵的质量不好的话很容易坏掉。 | | 为了更好的保护电路,可以在其中一个74HC595芯片连接8*8点阵之间的八条线中各加一个220欧姆电阻,本例中没有加入电阻所以LED特别亮,如果点阵的质量不好的话很容易坏掉。 |
| | | |