wiki:wade/embedded/arduino/example/example_3-3

Version 1 (modified by wade, 14 years ago) (diff)

--

/*                           
 *              08 07 06 05 04 03 02 01
 *                                   *
 * 74HC595  PIN 09 10 11 12 13 14 15 16
 *                    SH ST    DS
 *                    棕 白    紫
 * Arduino  PIN       3  2     4 
 *     
 */

#define data_ascii_Y {0x03, 0x04, 0x78, 0x04, 0x03} // Y 89
#define data_ascii_Z {0x61, 0x59, 0x49, 0x4D, 0x43} // Z 90
//byte data_0[5]={0x03E, B00111110, 0x049, 0x045, 0x03E};
byte data_0[8]={0x03E, 0x051, 0x049, 0x045, 0x03E, 0x0FF, 0x0FF, 0x0FF};
// ascii 5x7 dot font
byte data_ascii[][8] = {
                       data_ascii_Z
                       }; // 9

//Pin connected to ST_CP of 74HC595 for scanning
int scan_latch_pin = 5;
//Pin connected to SH_CP of 74HC595 for scanning
int scan_clock_pin = 6;
//Pin connected to DS of 74HC595 for scanning
int scan_data_pin = 7;
//Pin connected to ST_CP of 74HC595 for data
//int data_latch_pin = 5;
//Pin connected to SH_CP of 74HC595 for data
//int data_clock_pin = 6;
//Pin connected to DS of 74HC595 for data
//int data_data_pin = 7;


void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(scan_latch_pin, OUTPUT);
  pinMode(scan_clock_pin, OUTPUT);
  pinMode(scan_data_pin, OUTPUT);
  Serial.begin(9600);
  for (int i = 0; i< 8; i++)
    data_ascii[0][i] ^= 0xFF; 
  
}

void loop() {
  //count up routine
  for (int j = 0; j < 8; j++) {
    //ground scan_latch_pin and hold low for as long as you are transmitting
    digitalWrite(scan_latch_pin, LOW);
    shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(1 << j));
    shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(data_ascii[0][j] ));
    //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(scan_latch_pin, HIGH);
    //Serial.println(data_ascii[0][j] ^= 0xFF, HEX);
    delay(1);
  }
}

void scan_line()
{
  //count up routine
  for (int j = 1; j <= 256; j <<= 1) 
  {
    //ground scan_latch_pin and hold low for as long as you are transmitting
    digitalWrite(scan_latch_pin, LOW);
    shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, j);   
    //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(scan_latch_pin, HIGH);
    delay(500);
  }
}