Created
January 23, 2015 11:53
-
-
Save Microcontrolandos/9e8bff1736373111e4c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
MCP41XXX/MCP42XXX - Single/Dual Digital Potenciometer with SPI interface | |
Autor: Tiago | |
Compilador: MikroC PRO PIC | |
Criado em: 17/10/2014 por Tiago | |
Modificado em: 23/01/2015 por Tiago | |
- Suporte para o MCP42XXX | |
- Comandos disponíveis para o usuário | |
*/ | |
/* Command */ | |
#define MCP42XXX_WRITE_DATA 0b00010000 | |
#define MCP42XXX_SHUTDOWN 0b00100000 | |
/* Potentiometer Selections */ | |
#define MCP42XXX_NONE 0b00000000 | |
#define MCP42XXX_POT1 0b00000001 | |
#define MCP42XXX_POT2 0b00000010 //somente para MCP42XXX | |
#define MCP42XXX_ALL_POT 0b00000011 //somente para MCP42XXX | |
/* Pinos */ | |
extern sfr sbit MCP42XXX_CS; | |
extern sfr sbit MCP42XXX_CS_Direction; | |
/* Rotinas */ | |
void MCP42XXX_Set_Pot( char potentiometer, char value ); | |
/* Define o valor do(s) potenciômetro(s) */ | |
void MCP42XXX_Set_Pot( char potentiometer, char value ) | |
{ | |
MCP42XXX_CS_Direction = 0; //Define o pino de seleção como saída | |
MCP42XXX_CS = 0; //Habilita a comunicação com o dispostivo | |
Soft_SPI_Write( MCP42XXX_WRITE_DATA | potentiometer ); //Envia o comando para selecionar o potenciometro | |
Soft_SPI_Write( value ); //Define o valor do potenciometro | |
MCP42XXX_CS = 1; //Desabilita a comunicação com o dispostivo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment