Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //g++ -Wall -o mini mini.cc -lwiringPi
- #include <wiringPi.h>
- #include <iostream>
- //#include <mcp23017.h> //Ii2c
- #include <mcp23s17.h>//spi
- using namespace std;
- #define BASE 123
- void print(unsigned char c){
- unsigned char count(8);
- cout <<" IN = ";
- do{
- cout<<(int) (c & 1);
- c/=2;//>>1
- }while((count--)>1);
- cout<<endl;
- }
- int main(){
- unsigned char entree(0),tmp(0);
- char touche('0');
- cout<<"Axisat mini "<< piBoardRev () <<endl;
- wiringPiSetup();
- mcp23s17Setup (BASE, 0, 0) ;
- //Setup PORTA & PORTB
- for(int port=0;port<16;port++){
- if (port<8){//PORTA OUT
- cout<<"OUT "<<BASE+port<<" OUTPUT "<<endl;
- pinMode (BASE+port,OUTPUT);
- //delay(100);
- digitalWrite(BASE+port,LOW);
- }
- else{//PORTB IN
- cout<<"IN "<<BASE+port<<" IN"<<endl;
- pinMode(BASE+port,INPUT);//Entree
- //delay(100);
- //pullUpDnControl (BASE+port, PUD_DOWN) ;//Pulldown
- pullUpDnControl(BASE+port,PUD_OFF);
- }
- }
- cout <<endl<<"LECTURE PORT B INs"<<endl;
- while(TRUE){
- tmp=0;//Clear
- for(int port=8;port<16;port++){//PORT B READ
- tmp*=2;//<<1
- tmp|=digitalRead(BASE+port);
- }
- if (tmp!=entree){entree=tmp;print(entree);}
- if (touche>8){touche=0;}
- delay(1000);
- digitalWrite(BASE+0,(touche & 0x01));cout<<"OUT_0 = "<< ((touche>>1) & 0x01)<<'\t';;
- digitalWrite(BASE+1,((touche >>2) & 0x01) );cout<<"OUT_1 = "<<( (touche>>1) & 0x01)<<'\t';;
- digitalWrite(BASE+2,((touche >>3) & 0X01));cout <<"OUT_2 = "<< ((touche>>2) & 0x01)<<endl;
- touche++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement