62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
/*
|
|
PSCon.cpp
|
|
(c)2011 kou029w - MIT License [http://kou029w.appspot.com/mit-license.txt]
|
|
*/
|
|
|
|
#if defined(ARDUINO) && ARDUINO >= 100
|
|
#include <Arduino.h>
|
|
#else
|
|
#include <WProgram.h>
|
|
#endif
|
|
#include <PSCon.h>
|
|
|
|
void PSCon::clkPin(byte clkPin){
|
|
pinMode(clkPin, OUTPUT);
|
|
PSCon::_clkPin = clkPin;
|
|
}
|
|
|
|
void PSCon::selPin(byte selPin){
|
|
pinMode(selPin, OUTPUT);
|
|
PSCon::_selPin = selPin;
|
|
}
|
|
|
|
void PSCon::cmdPin(byte cmdPin){
|
|
pinMode(cmdPin, OUTPUT);
|
|
PSCon::_cmdPin = cmdPin;
|
|
}
|
|
|
|
void PSCon::datPin(byte datPin){
|
|
pinMode(datPin, INPUT);
|
|
PSCon::_datPin = datPin;
|
|
}
|
|
|
|
byte PSCon::_getByte(byte requestData){
|
|
for(byte i=0; i<8; i++){
|
|
digitalWrite(PSCon::_clkPin, LOW);
|
|
if(requestData & 0x01){
|
|
digitalWrite(PSCon::_cmdPin, HIGH);
|
|
}
|
|
else{
|
|
digitalWrite(PSCon::_cmdPin, LOW);
|
|
}
|
|
requestData >>= 1;
|
|
delayMicroseconds(1);
|
|
digitalWrite(PSCon::_clkPin, HIGH);
|
|
if(digitalRead(PSCon::_datPin)){
|
|
requestData |= 0x80;
|
|
}
|
|
delayMicroseconds(1);
|
|
}
|
|
digitalWrite(PSCon::_cmdPin, LOW);
|
|
delayMicroseconds(8);
|
|
return requestData;
|
|
}
|
|
|
|
void PSCon::get(byte requestData[8]){
|
|
digitalWrite(PSCon::_selPin, LOW);
|
|
PSCon::_getByte(0x01);
|
|
for(byte i=0; i<8; i++){
|
|
PSCon::data[i] = PSCon::_getByte(requestData[i]);
|
|
}
|
|
digitalWrite(PSCon::_selPin, HIGH);
|
|
}
|