Last active
May 14, 2020 12:03
-
-
Save tiagohm/e6eff6aa1b080218de99678326c28cd3 to your computer and use it in GitHub Desktop.
Potenciômetro digital de 6 canais.
This file contains hidden or 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
/* | |
AD5206 - Potenciômetro Digital de 6 canais. | |
Autor: Tiago Melo | |
Blog: Microcontrolandos | |
Compilador: MikroC PRO PIC | |
Bibliotecas: Soft_SPI | |
*/ | |
// Pinos do AD5206 conectados ao PIC. | |
sbit SoftSpi_SDI at RB1_bit; | |
sbit SoftSpi_SDO at RB1_bit; | |
sbit SoftSpi_CLK at RB0_bit; | |
sbit AD5206_CS at RB2_bit; | |
sbit SoftSpi_SDI_Direction at TRISB1_bit; | |
sbit SoftSpi_SDO_Direction at TRISB1_bit; | |
sbit SoftSpi_CLK_Direction at TRISB0_bit; | |
sbit AD5206_CS_Direction at TRISB2_bit; | |
void AD5206_Init() { | |
// Inicia o pino CS como saída e valor inicial = 1. | |
AD5206_CS_Direction = 0; | |
AD5206_CS = 1; | |
} | |
void AD5206_Write(char canal, char valor) { | |
// Envia 16 bits (somente os últimos 11 bits serão utilizados). | |
AD5206_CS = 0; | |
Soft_SPI_Write(canal); | |
Soft_SPI_Write(valor); | |
AD5206_CS = 1; | |
} | |
void main() { | |
char canal = 0; | |
char valor = 0; | |
// Inicializa a comunicação SPI. | |
Soft_SPI_Init(); | |
// Inicializa os pinos conectados ao AD5206. | |
AD5206_Init(); | |
while(1) { | |
// Define o valor do potenciômetro de um canal específico. | |
// Neste caso, estamos incrementando o valor do canal 0 a cada 100 ms. | |
AD5206_Write(canal, 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