Advertisement
AntonioVillanueva

RaspberryPi test mcp23s17 wiringPi tests...

Mar 1st, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. //g++ -Wall -o mini mini.cc -lwiringPi
  2. #include <wiringPi.h>
  3. #include <iostream>
  4. //#include <mcp23017.h> //Ii2c
  5. #include <mcp23s17.h>//spi
  6. using namespace std;
  7.  
  8. #define BASE    123
  9. void print(unsigned char c){
  10.     unsigned char count(8);
  11.     cout <<" IN = ";
  12.     do{
  13.         cout<<(int) (c & 1);
  14.         c/=2;//>>1
  15.     }while((count--)>1);
  16.     cout<<endl;
  17. }
  18.  
  19. int main(){
  20.  
  21.     unsigned char entree(0),tmp(0);
  22.     char touche('0');
  23.  
  24.     cout<<"Axisat mini "<< piBoardRev () <<endl;
  25.     wiringPiSetup();
  26.     mcp23s17Setup (BASE, 0, 0) ;
  27.  
  28. //Setup PORTA & PORTB
  29.  
  30.     for(int port=0;port<16;port++){
  31.     if (port<8){//PORTA OUT
  32.         cout<<"OUT "<<BASE+port<<" OUTPUT "<<endl;
  33.         pinMode (BASE+port,OUTPUT);
  34.         //delay(100);
  35.         digitalWrite(BASE+port,LOW);
  36.     }
  37.     else{//PORTB IN
  38.         cout<<"IN "<<BASE+port<<" IN"<<endl;
  39.         pinMode(BASE+port,INPUT);//Entree
  40.         //delay(100);
  41.         //pullUpDnControl (BASE+port, PUD_DOWN) ;//Pulldown
  42.         pullUpDnControl(BASE+port,PUD_OFF);
  43.         }
  44.     }
  45.  
  46.     cout <<endl<<"LECTURE PORT B INs"<<endl;
  47.  
  48. while(TRUE){
  49.     tmp=0;//Clear
  50.     for(int port=8;port<16;port++){//PORT B READ
  51.         tmp*=2;//<<1
  52.         tmp|=digitalRead(BASE+port);
  53.     }
  54.     if (tmp!=entree){entree=tmp;print(entree);}
  55.  
  56.  
  57.     if (touche>8){touche=0;}
  58.     delay(1000);
  59.  
  60.     digitalWrite(BASE+0,(touche & 0x01));cout<<"OUT_0 = "<< ((touche>>1) & 0x01)<<'\t';;
  61.     digitalWrite(BASE+1,((touche >>2) & 0x01) );cout<<"OUT_1 = "<<( (touche>>1) & 0x01)<<'\t';;
  62.     digitalWrite(BASE+2,((touche >>3) & 0X01));cout <<"OUT_2 = "<< ((touche>>2) & 0x01)<<endl;
  63.     touche++;
  64. }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement