AC VOLTAGE MEASURING BY USING DSPIC30FF2010 AND 16X1 LCD

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
HAREESH
Posts: 2
Joined: 05 Apr 2018 06:53

AC VOLTAGE MEASURING BY USING DSPIC30FF2010 AND 16X1 LCD

#1 Post by HAREESH » 05 Apr 2018 07:01

HI,
AM NEW TO HERE.
AM DOING AC VOLTAGE MEASURING BY USING DSPIC30FF2010 AND 16X1 LCD.
MY PROBLEM IS ,THE LCD SHOWING ONLY 8 CHARACTERS.
AND I CANT TAKE READINGS.ONLY SHOWING V:0.00V.
AM USING MIKROC COMPILER
HERE IS MY PROGRAM



// LCD module connections
sbit LCD_RS at LATD0_bit;
sbit LCD_EN at LATD1_bit;
sbit LCD_D4 at LATE0_bit;
sbit LCD_D5 at LATE1_bit;
sbit LCD_D6 at LATE2_bit;
sbit LCD_D7 at LATE3_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISE0_bit;
sbit LCD_D5_Direction at TRISE1_bit;
sbit LCD_D6_Direction at TRISE2_bit;
sbit LCD_D7_Direction at TRISE3_bit;
// End LCD module connections

unsigned char ch;
unsigned int adc_rd;
char *text;
long tlong;

void main() {
ADPCFG = 0x0000; // Configure AN pins as digital
TRISB = 0xFFFF;
ADC1_Init();
Lcd_Init();
LCD_Cmd(_LCD_CURSOR_OFF); // send command to LCD (cursor off)
LCD_Cmd(_LCD_CLEAR); // send command to LCD (clear LCD)

text = "AUREEMAS"; // assign text to string
LCD_Out(1,1,text); // print string a on LCD, 1st row, 1st column
Delay_ms(2000);
LCD_Cmd(_LCD_CLEAR);
text = "ADC EXAMPLE"; // assign text to string
LCD_Out(1,1,text); // print string a on LCD, 2nd row, 1st column
Delay_ms(2000);
LCD_Cmd(_LCD_CLEAR);
text = "V:"; // assign text to string
while (1) {
adc_rd = ADC1_read(10); // get ADC value from 2nd channel
LCD_Out(1,1,text); // print string a on LCD, 2nd row, 1st column
tlong = (long)adc_rd * 5000; // covert adc reading to milivolts
tlong = tlong / 4011; // 0..1023 -> 0-5000mV

ch = tlong / 1000; // extract volts digit
LCD_Chr(1,3,48+ch); // write ASCII digit at 2nd row, 9th column
LCD_Chr_CP('.');

ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point

ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Chr_CP(48+ch); // write ASCII digit at cursor point

LCD_Chr_CP('V');

Delay_ms(1);
}
}


AM BLOCKED HERE.
PLEASE HELP ME.
THANKS.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: AC VOLTAGE MEASURING BY USING DSPIC30FF2010 AND 16X1 LCD

#2 Post by filip » 10 Apr 2018 10:15

Hi,

First of fall, use a debugger to see which voltage are you reading on the analog pin.

Then, if this is OK, pay attention to the string conversion and displaying on the Lcd.

Regards,
Filip.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”