Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,252
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Lcd_Init(); // Initialize LCD only once while(1) { adc_rd = ADC_Read(0); // here is the correct point to assign the result to the char array but you need to convert it from an integer to individual characters that can be shown in the display, // you can either use a custom function or sprinf function Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,txt1); // Write text in first row Lcd_Out(2,1,txt2); // Write text in second row Delay_ms(100); // Lcd_Cmd(_LCD_CLEAR); no need for that , the lcd is already cleared in line number 8, one clear is enough for each loop }
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 43 44 45 46 47 48 49 // LCD module connections unsigned int adc_rd; sbit LCD_RS at PORTD2_bit; sbit LCD_EN at PORTD3_bit; sbit LCD_D4 at PORTD4_bit; sbit LCD_D5 at PORTD5_bit; sbit LCD_D6 at PORTD6_bit; sbit LCD_D7 at PORTD7_bit; sbit LCD_RS_Direction at DDD2_bit; sbit LCD_EN_Direction at DDD3_bit; sbit LCD_D4_Direction at DDD4_bit; sbit LCD_D5_Direction at DDD5_bit; sbit LCD_D6_Direction at DDD6_bit; sbit LCD_D7_Direction at DDD7_bit; // End LCD module connections char txt1[] = "Voltage = "; char txt2[5]; char i; // Loop variable void Move_Delay() { // Function used for text moving Delay_ms(10); // You can change the moving speed here } void main() { Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off while(1) { adc_rd = ADC_Read(0); txt2[0]=(adc_rd/1000) +48; txt2[1]=((adc_rd/100)%10) +48; txt2[2]=((adc_rd/10)%10) +48; txt2[3]=(adc_rd%10) +48; txt2[4]=0; Lcd_Out(1,1,txt1); // Write text in first row Lcd_Out(2,1,txt2); // Write text in second row Delay_ms(1000); // Delay_ms(100); using higher delay Lcd_Cmd(_LCD_CLEAR); // Clear display } }
Code C - [expand] 1 2 3 4 adc_rd = ADC_Read(0); adc_rd = (unsigned long)(adc_rd*5000)/255 // then this result can still fit in a unsigned integer variable, assuming 8bit ADC result (255*5000)/255=5000 //or adc_rd = (unsigned long)(adc_rd*5000)/1023// then this result can still fit in a unsigned integer variable, assuming 10bit ADC result(1023*5000)/1023=5000
tlong = (long)adc_rd * 5000; // *Convert the result in millivolts* [COLOR="#FF0000"]this is not in mV, it is just multiplied with 5000[/COLOR]
tlong = tlong / 255; // 0..1023 -> 0-5000mV [COLOR="#FF0000"]do you have an 8 bit ADC result? is so then this is the result in mV but I think the result will be 10bit so you have to divide with 1023 [/COLOR]
ch = tlong / 1000; // Extract volts (thousands of millivolts) [COLOR="#FF0000"]this is the result in volts not mV but you will loose the decimals unless ch is float variable[/COLOR]
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?