alaalwi11
Member level 1
- Joined
- Nov 30, 2010
- Messages
- 32
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Al khurtum-Sudan
- Activity points
- 1,626
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 //LCD: configuración de pines sbit lcd_rs at rb2_bit; sbit lcd_en at rb3_bit; sbit lcd_d7 at rb7_bit; sbit lcd_d6 at rb6_bit; sbit lcd_d5 at rb5_bit; sbit lcd_d4 at rb4_bit; //LCD: direccionamiento de pines sbit lcd_rs_direction at trisb2_bit; sbit lcd_en_direction at trisb3_bit; sbit lcd_d7_direction at trisb7_bit; sbit lcd_d6_direction at trisb6_bit; sbit lcd_d5_direction at trisb5_bit; sbit lcd_d4_direction at trisb4_bit; unsigned long adc_value; unsigned char d1,d2,d3,d4; #define printV lcd_chr(2,11,48+d1); lcd_chr_cp(d2+48); \ lcd_chr_cp('.'); lcd_chr_cp(48+d3); \ lcd_chr_cp(48+d4); lcd_chr_cp('V'); #define calcV d1=adc_value/1000; d2=(adc_value%1000)/100; \ d3=((adc_Value%1000)%100)/10; d4=((adc_value%1000)%100)%10; void main() { ADCON1=0b10000010; TRISA=0XFF; Lcd_Init(); lcd_cmd(_LCD_CLEAR); lcd_cmd(_LCD_CURSOR_OFF); Lcd_Out(1,2,"EVA PROYECT's"); lcd_out(2,1,"voltage:"); for(;;){ adc_value=ADC_Read(0); adc_value=adc_value*5000/1023; calcV printV delay_ms(20); } }
sbit lcd_rs at rb2_bit;
sbit lcd_en at rb3_bit;
what is your ref volt?
//PIC16F887
// Clock 20 MHz
// LCD 16x2
int dat = 0;
float volts;
char txt1[6];
char txt2[13];
char *text1 = "ADC=";
char *text2 = "Volt=";
void main()
{
TRISA = 0xFF; // PORTA => input
ANSEL = 0xFF; // PORTA => Analog
ADCON1 = 0x00; // Select Verf and Right Justify
ADCON0 = 0B11001001; // Select Analog1 RC_Mode and ADON
Lcd_Init(&PORTD);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
while(1)
{
ADCON0.GO = 1;
while(ADCON0.GO);
dat = (ADRESH*4)+(ADRESL/64);
WordToStr(dat,txt1);
Lcd_Out(1,1,text1);
Lcd_Out(1,10,txt1);
volts = (dat*5)/1023.0;
FloatToStr(volts,txt2);
Lcd_Out(2,1,text2);
Lcd_Out(2,7,txt2);
Delay_ms(1000);
Lcd_cmd(LCD_CLEAR);
}
}
//PIC16F887
// Clock 20 MHz
// LCD 16x2
int dat = 0;
float n = 1023;
float volts;
char txt1[6];
char txt2[13];
char *text1 = "ADC=";
char *text2 = "V=";
char *text3 = "mV=";
char OUT;
void main()
{
TRISA = 0xFF; // PORTA => input
ANSEL = 0xFF; // PORTA => Analog
ADCON1 = 0x00; // Select Verf and Right Justify
ADCON0 = 0B11001001; // Select Analog1 RC_Mode and ADON
Lcd_Init(&PORTD);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
while(1)
{
ADCON0.GO = 1;
while(ADCON0.GO);
dat = (ADRESH*4)+(ADRESL/64);
WordToStr(dat,txt1);
Lcd_Out(1,1,text1);
Lcd_Out(1,10,txt1);
volts = (dat*5/n);
if (dat < 205 ) {volts = (dat*5/1.023); OUT = text3;}else{OUT = text2;}
FloatToStr(volts,txt2);
Lcd_Out(2,1,OUT);
Lcd_Out(2,7,txt2);
Delay_ms(1000);
Lcd_cmd(LCD_CLEAR);
}
}
Hi nudrat,
for voltage devider I just use for adjust inputV to MCU only...
In fact no need to use it.
and for you want display in mV I have change some code as below
Code://PIC16F887 // Clock 20 MHz // LCD 16x2 int dat = 0; float n = 1023; float volts; char txt1[6]; char txt2[13]; char *text1 = "ADC="; char *text2 = "V="; char *text3 = "mV="; char OUT; void main() { TRISA = 0xFF; // PORTA => input ANSEL = 0xFF; // PORTA => Analog ADCON1 = 0x00; // Select Verf and Right Justify ADCON0 = 0B11001001; // Select Analog1 RC_Mode and ADON Lcd_Init(&PORTD); Lcd_Cmd(LCD_CURSOR_OFF); Lcd_Cmd(LCD_CLEAR); while(1) { ADCON0.GO = 1; while(ADCON0.GO); dat = (ADRESH*4)+(ADRESL/64); WordToStr(dat,txt1); Lcd_Out(1,1,text1); Lcd_Out(1,10,txt1); volts = (dat*5/n); if (dat < 205 ) {volts = (dat*5/1.023); OUT = text3;}else{OUT = text2;} FloatToStr(volts,txt2); Lcd_Out(2,1,OUT); Lcd_Out(2,7,txt2); Delay_ms(1000); Lcd_cmd(LCD_CLEAR); } }
display in volt (in case of Volt > 1V)
**broken link removed**
display in mV (in case of Volt < 1V)
**broken link removed**
Hope this help :-D
ok but with 5v vref how you will get .001 v (1 mv) resolution/ it will be (4.9 mv)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?