
MCP3201 é um Conversor Analógico/Digital de 12 bits com interface SPI.
Características
- 12 bits de resolução;
- Comunicação via SPI;
- Tensão de operação: 2.7V - 5.5V;
Funcionamento
A comunicação com o dispositivo funciona através da interface SPI. Inicialmente habilitamos a comunicação colocando o pino CS
em nível lógico baixo. Iremos ler os 15 bits, dos quais 12 bits correspondem ao valor da entrada analógica, começando do bit MSB até o bit LSB. A leitura de cada bit é feita após cada borda de descida do pulso de clock. Por fim, desabilitamos a comunicação colocando o pino CS
em nível lógico alto.
O cálculo real da tensão de entrada é: Vin = ADC * Vref / 4096
, sendo Vin = [V+] – [V-]
. Caso V-
seja igual a 0V
, Vin = V+
.
Download
Código
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
/* | |
MCP3201 - Conversor Analógico/Digital de 12-bits. | |
Autor: Tiago Melo | |
Blog: Microcontrolandos | |
Compilador: MikroC PRO PIC | |
Bibliotecas: LCD, Lcd_Constants, Conversions, C_String | |
*/ | |
//Pinos do MCP3201. | |
sbit MCP3201_Clock at RB0_bit; | |
sbit MCP3201_Data at RB1_bit; | |
sbit MCP3201_CS at RB2_bit; | |
sbit MCP3201_Clock_Direction at TRISB0_bit; | |
sbit MCP3201_Data_Direction at TRISB1_bit; | |
sbit MCP3201_CS_Direction at TRISB2_bit; | |
//Pinos do LCD. | |
sbit LCD_RS at RC0_bit; | |
sbit LCD_EN at RC1_bit; | |
sbit LCD_D4 at RC2_bit; | |
sbit LCD_D5 at RC3_bit; | |
sbit LCD_D6 at RC4_bit; | |
sbit LCD_D7 at RC5_bit; | |
sbit LCD_RS_Direction at TRISC0_bit; | |
sbit LCD_EN_Direction at TRISC1_bit; | |
sbit LCD_D4_Direction at TRISC2_bit; | |
sbit LCD_D5_Direction at TRISC3_bit; | |
sbit LCD_D6_Direction at TRISC4_bit; | |
sbit LCD_D7_Direction at TRISC5_bit; | |
void MCP3201_Init() { | |
MCP3201_CS_Direction = 0; | |
MCP3201_Clock_Direction = 0; | |
MCP3201_Data_Direction = 1; | |
MCP3201_CS = 1; | |
MCP3201_Clock = 0; | |
} | |
unsigned int MCP3201_Read() { | |
char i; | |
unsigned value; | |
//Inicia a conversão. | |
MCP3201_Clock = 1; | |
MCP3201_CS = 0; | |
//Lê 15 bits. Os 3 primeiros serão ignorados. | |
for(i = 0; i < 15; i++) { | |
value <<= 1; | |
MCP3201_Clock = 1; | |
Delay_us(1); | |
MCP3201_Clock = 0; | |
Delay_us(1); | |
//Lê o valor após um pulso de descida do clock. | |
value |= MCP3201_Data; | |
} | |
MCP3201_Clock = 0; | |
MCP3201_CS = 1; | |
return (value & 0x0FFF); | |
} | |
float MCP3201_Convert(unsigned int raw, float vref) { | |
return raw * vref / 4096.0; | |
} | |
void main() { | |
char texto[12]; | |
//Inicializa o MCP3201. | |
MCP3201_Init(); | |
//Inicializa o LCD. | |
Lcd_Init(); | |
Lcd_Cmd(_LCD_CLEAR); | |
Lcd_Cmd(_LCD_CURSOR_OFF); | |
while(1) { | |
//Lê o valor. | |
unsigned valor = MCP3201_Read(); | |
//Converte o valor lido em um valor de tensão com 5V como referência. | |
float tensao = MCP3201_Convert(valor, 5); | |
//Converte em texto. | |
FloatToStr(tensao, texto); | |
//Escreve no LCD. | |
Lcd_Out(2, 1, texto); | |
Lcd_Chr_CP('V'); | |
//Faz nada por 1s. | |
Delay_ms(1000); | |
} | |
} |
Muito útil essa biblioteca, pra quem precisar de um ad melhor que o interno, vai ajudar demais. Obrigado por compartilhar.
ResponderExcluirPic: Mcp3201 - Microcontrolandos >>>>> Download Now
Excluir>>>>> Download Full
Pic: Mcp3201 - Microcontrolandos >>>>> Download LINK
>>>>> Download Now
Pic: Mcp3201 - Microcontrolandos >>>>> Download Full
>>>>> Download LINK fi
nice..
ResponderExcluirinplant training in chennai
inplant training in chennai
inplant training in chennai for it
hosting
india hosting
india web hosting
iran web hosting
technology 11 great image sites like imgur hosting
final year project dotnet server hacking what is web hosting
macao web hosting
Pic: Mcp3201 - Microcontrolandos >>>>> Download Now
ResponderExcluir>>>>> Download Full
Pic: Mcp3201 - Microcontrolandos >>>>> Download LINK
>>>>> Download Now
Pic: Mcp3201 - Microcontrolandos >>>>> Download Full
>>>>> Download LINK
İstanbul
ResponderExcluirSivas
Kırıkkale
Zonguldak
Iğdır
Y4O
Ankara
ResponderExcluirAntalya
istanbul
Ordu
izmir
WWDR
ağrı
ResponderExcluirvan
elazığ
adıyaman
bingöl
061CE
63E17
ResponderExcluirAmasya Evden Eve Nakliyat
Çerkezköy Evden Eve Nakliyat
Tekirdağ Fayans Ustası
testosterone propionat
buy oxandrolone anavar
parabolan
Ünye Evden Eve Nakliyat
buy masteron
masteron
FD4CD
ResponderExcluirÇorum Şehirler Arası Nakliyat
Mercatox Güvenilir mi
Bitlis Lojistik
Denizli Parça Eşya Taşıma
Hatay Şehir İçi Nakliyat
Hakkari Şehir İçi Nakliyat
Şırnak Şehir İçi Nakliyat
Kocaeli Parça Eşya Taşıma
Kars Parça Eşya Taşıma
B05C7
ResponderExcluirpeptides for sale
order turinabol
pharmacy steroids
Uşak Evden Eve Nakliyat
Ankara Asansör Tamiri
Kars Evden Eve Nakliyat
buy trenbolone enanthate
anapolon oxymetholone
sarms
088F4
ResponderExcluirGate io Borsası Güvenilir mi
Ceek Coin Hangi Borsada
Mexc Borsası Kimin
Dxgm Coin Hangi Borsada
Bitcoin Üretme Siteleri
Ergo Coin Hangi Borsada
Bitcoin Kazanma
Instagram Beğeni Hilesi
Binance Yaş Sınırı
شركة صيانة افران بعنيزة NpFyTBhu7e
ResponderExcluirرقم مصلحة المجاري بالاحساء N0d7o5c7ls
ResponderExcluirشركة رش مبيدات بالاحساء gdSxDcrF71
ResponderExcluirشركة تنظيف موكيت بالاحساء 5ZEqdHt13G
ResponderExcluirتنظيف افران الغاز بمكه qGgMzn8vNr
ResponderExcluir614815F52D
ResponderExcluirtakipçi fiyat
3D Car Parking Para Kodu
Google Yorum Satın Al
MFF Kupon Kodu
Google Yorum Satın Al
101 Okey Yalla Hediye Kodu
İdle Office Tycoon Hediye Kodu
Titan War Hediye Kodu
MLBB Hediye Kodu