[PIC] Woking with internal ADC of PIC16f877a

Status
Not open for further replies.

IKPE80

Newbie level 4
Joined
Aug 25, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
29
Can any one help me on this. I am working on voltmeter using the adc of pic6f877a with lcd , my code works perfect on proteus but when i implement it, it won't respond fine. At times it display, at times it don't. Pls i need help.
 

Check the delay for display LCD, the delay might be low or high in your code. In proteus delay not a problem. What you seen in the display.
 

Can any one help me on this. I am working on voltmeter using the adc of pic6f877a with lcd , my code works perfect on proteus but when i implement it, it won't respond fine. At times it display, at times it don't. Pls i need help.

No one can help you better with out your code and hardware connection.Post the code and circuit.
 

No one can help you better with out your code and hardware connection.Post the code and circuit.
I am using mickroC compiler so my code and the proteus design are below

Code:
                              // LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
//char look(int a);
void main()
{

  int v;
  char volt[5];
  ADC_INIT();
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);

  do
  {
       v = ADC_Read(2);
       v = v*0.2246;

       IntToStr(v,volt);
       LTrim(volt);
       Lcd_Out(1,1,"Voltage = ");
       Lcd_Out(1,11,volt);
       Lcd_Out(1,16,"V");
  } while(1);

}


 

Check the delay for display LCD, the delay might be low or high in your code. In proteus delay not a problem. What you seen in the display.
Pls I am using MickroC compiler how do i check the LCD delay of their library because I am using their own library not my own function for LCD.
 

if you have same connections in real hardware as you posted in the simulation then you need some pot at pin 3 for contrast and VCC for pin 2in the real hardware.

What is your real hardware output you getting?
 

Fixed code.


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
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
 
int v;
char volt[17];
 
void main() {
 
  CMCON = 0x07;
  ADCON0 = 0x40;
  ADCON1 = 0b10000010;
  CVRCON = 0x00;
 
  TRISA = 0x02;
  PORTA = 0x00;
 
  Lcd_Init();
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1,1,"Voltage = "); 
 
  do {
       v = ADC_Read(2) * 0.2246;       
       IntToStr(v, volt);
       LTrim(volt);       
       Lcd_Out(1,11,volt);
       Lcd_Out(1,16,"V");
  } while(1);
}

 
Reactions: IKPE80

    IKPE80

    Points: 2
    Helpful Answer Positive Rating
Thanks, the fixed code worked, but i have to change the TRISA = 0x02 to TRISA = 0xff. Please what does CMCON and CVRCON mean?
 

CMCON = Comparator Control
CVRCON = Comparator Voltage Reference Control
 
Reactions: IKPE80

    IKPE80

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…