Advertisement
Electgpl

PIC - Potenciometro Digital MCP41010

Nov 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <16F883.h>
  2. #FUSES HS
  3. #FUSES MCLR
  4. #use delay(clock=4000000)
  5. #use rs232(baud=9600, xmit=pin_c6, rcv=pin_c7, bits=8, parity=N)
  6. #define CS   PIN_B2
  7. #define SCLK PIN_B1
  8. #define SI   PIN_B0
  9. void setPote(int valor)
  10. {
  11.    int8 i;
  12.    int8 palabra[2];
  13.    palabra[0]=valor;
  14.    palabra[1]=0x11;                             //Posicion 0x11 asigna el valor, 0x21 guarda el valor
  15.    output_low(SCLK);
  16.    output_low(CS);
  17.    for(i=1;i<=16;++i) {
  18.       output_bit(SI, shift_left(palabra,2,0));
  19.       output_high(SCLK);
  20.       output_low(SCLK);
  21.    }
  22.    output_high(CS);
  23. }
  24. int8 valPote=0;
  25. void main()
  26. {
  27.    printf("Listo!\r");
  28.    while(true){
  29.       if(input(PIN_C0)==1)
  30.       {
  31.          if(valPote<255)
  32.          {
  33.             valPote++;
  34.             setPote(valPote);
  35.             printf("valPote: %3u \r",valPote);
  36.          }
  37.       }
  38.       if(input(PIN_C1)==1)
  39.       {
  40.          if(valPote>0)
  41.          {  
  42.             valPote--;
  43.             setPote(valPote);
  44.             printf("valPote: %3u \r",valPote);
  45.          }
  46.       }
  47.    }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement