Created
March 1, 2018 23:14
-
-
Save tiagohm/d0a6926d796f1063dcc7e31621bfb61a to your computer and use it in GitHub Desktop.
Potenciometro Digital de 256 posições e 1 canal.
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 - Potenciometro Digital de 256 posições e 1 canal. | |
Autor: Tiago Melo | |
Blog: Microcontrolandos | |
Compilador: MikroC PRO PIC | |
Bibliotecas: Soft_SPI | |
*/ | |
//Pinos do MCP41XXX. | |
sbit SoftSpi_SDI at RB1_bit; | |
sbit SoftSpi_SDO at RB1_bit; | |
sbit SoftSpi_CLK at RB0_bit; | |
sbit SoftSpi_SDI_Direction at TRISB1_bit; | |
sbit SoftSpi_SDO_Direction at TRISB1_bit; | |
sbit SoftSpi_CLK_Direction at TRISB0_bit; | |
sbit MCP41XXX_CS at RB2_bit; | |
sbit MCP41XXX_CS_Direction at TRISB2_bit; | |
void MCP41XXX_Init() { | |
//Inicia o pino CS como saída e valor inicial = 1. | |
MCP41XXX_CS_Direction = 0; | |
MCP41XXX_CS = 1; | |
} | |
void MCP41XXX_Write(char valor) { | |
MCP41XXX_CS = 0; | |
//Define o valor do potenciômetro 0. | |
Soft_SPI_Write(0b00010001); | |
Soft_SPI_Write(valor); | |
MCP41XXX_CS = 1; | |
} | |
void main() { | |
char valor = 0; | |
//Inicia a comunicação SPI. | |
Soft_SPI_Init(); | |
//Inicializa o MCP41XXX. | |
MCP41XXX_Init(); | |
while(1) { | |
//Define o valor do potenciômetro. | |
MCP41XXX_Write(valor++); | |
//Faz nada por 100ms. | |
Delay_ms(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment