/* * wPi00.c * * gcc wPi00.c -o wPi00 -lwiringPi * * wiringPi (wiringpi.com) should be installed in your Raspberry Pi * * based on wiringpi.com's test1.c: * Simple test program to test the wiringPi functions * * 20130812 - Testing electronics.cat boards */ #include // http://wiringpi.com/ #include #include #include #define P3_SETUP 0x00 /* 0 : Output, 1 : Input*/ #define P4_SETUP 0x00 /* 0 : Output, 1 : Input*/ // Assigning wiringPi pins to 3Bpi - http://electronics.cat/en/boards/set05_08/ uint8_t byP2wPiMaster[] = {19,20,15,16}, byP2wPiSlave[] = {20,19,16,15}; uint8_t byP3wPi[] = {18,17,1,11,10,12,13,14}; /* [0]:LSB, [7]:MSB*/ uint8_t byP4wPi[] = {9,8,5,6,4,2,3,7}; /* [0]:LSB, [7]:MSB*/ void v3BpiP3pinMode(uint8_t byIoMode){ // byIoMode is usually P3_SETUP // P3_SETUP is a constant with input/output modes for P3 3Bpi port int8_t i = 7; uint8_t byMask = 0x80; /* 10000000 */ while(byMask){ if(byIoMode & byMask) pinMode(byP3wPi[i],INPUT); else pinMode(byP3wPi[i],OUTPUT); byMask >>= 1; i--; } } void v3BpiP4pinMode(uint8_t byIoMode){ // byIoMode is usually P4_SETUP // P4_SETUP is a constant with input/output modes for P4 3Bpi port int8_t i = 7; uint8_t byMask = 0x80; /* 10000000 */ while(byMask){ if(byIoMode & byMask) pinMode(byP4wPi[i],INPUT); else pinMode(byP4wPi[i],OUTPUT); byMask >>= 1; i--; } } void v3BpiHighNibbleP3digitalWrite(by){ int8_t i = 7; uint8_t byMask = 0x80; /* 10000000 */ while(byMask > 0x08){ if(!(P3_SETUP & byMask)) digitalWrite(byP3wPi[i],by & byMask); byMask >>= 1; i--; } } void v3BpiLowNibbleP3digitalWrite(by){ int8_t i = 3; uint8_t byMask = 0x08; /* 00001000 */ while(byMask){ if(!(P3_SETUP & byMask)) digitalWrite(byP3wPi[i],by & byMask); byMask >>= 1; i--; } } void v3BpiP3digitalWrite(uint8_t by){ v3BpiHighNibbleP3digitalWrite(by); v3BpiLowNibbleP3digitalWrite(by); } void v3BpiHighNibbleP4digitalWrite(by){ int8_t i = 7; uint8_t byMask = 0x80; /* 10000000 */ while(byMask > 0x08){ if(!(P4_SETUP & byMask)) digitalWrite(byP4wPi[i],by & byMask); byMask >>= 1; i--; } } void v3BpiLowNibbleP4digitalWrite(by){ int8_t i = 3; uint8_t byMask = 0x08; /* 00001000 */ while(byMask){ if(!(P4_SETUP & byMask)) digitalWrite(byP4wPi[i],by & byMask); byMask >>= 1; i--; } } void v3BpiP4digitalWrite(uint8_t by){ v3BpiHighNibbleP4digitalWrite(by); v3BpiLowNibbleP4digitalWrite(by); } int main (void){ uint8_t byP3 = 0x80, byP4 = 0x01; printf ("3Bpi + Raspberry Pi wiringPi test program\n") ; if (wiringPiSetup () == -1) exit (1) ; v3BpiP3pinMode(P3_SETUP); v3BpiP4pinMode(P4_SETUP); while(1){ v3BpiP3digitalWrite(byP3); v3BpiP4digitalWrite(byP4); byP3 >>= 1; byP4 <<= 1; if(!byP3){ byP3 = 0x80; byP4 = 0x01; } delay(100); } return 0; }