Skip to content

Instantly share code, notes, and snippets.

@gresan-gits
Created February 2, 2020 11:02
Show Gist options
  • Save gresan-gits/0d44fa635b16a0fbac5765b01d95fd1c to your computer and use it in GitHub Desktop.
Save gresan-gits/0d44fa635b16a0fbac5765b01d95fd1c to your computer and use it in GitHub Desktop.
CCS C ADC
#include <main.h>
#use rs232(UART1,baud=9600,parity=N,stream=UART,errors)
INT16 value, value2;
float vol;
void test(){
float a=5;
float b=1024;
float v=(float)a/b;
float ff1;
int8 open=60;
//ff1=(float)5/1024;
fprintf (UART, "Gia tri V= %2.7grn", 0.00048);
}
void tinh_Vol(INT16 adc_doc_duoc)
{
//5V ung voi 1024 muc(ADC)
//1ADC=5/1024=
FLOAT one_adc=0.00244;//=5/1024;
vol=adc_doc_duoc*one_adc;
fprintf (UART, "Gia tri VOL = %2.2grn", vol);
}
void main()
{
setup_adc (ADC_CLOCK_INTERNAL);
// setup_adc_ports(AN0, VSS_VDD);
setup_adc_ports(AN0, VREF_VREF);
WHILE (TRUE)
{
set_adc_channel (0);
delay_us (10);
value = read_adc ();
fprintf (UART, "Gia tri ADC = %lurn", value);
delay_ms (1000);
tinh_Vol (value) ;
// test();
//TODO: User Code
}
}
#include <18F4520.h>
#device *=16
#device adc=10//Khai bao su dung ADC 10 bit
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment