Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

mplab programe for ADC converter (pic16f884)

Status
Not open for further replies.

jey86

Newbie level 3
Newbie level 3
Joined
Dec 12, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,318
I wrote a ADC program for pic16f884.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <pic.h>
#define _XTAL_ FREQ 4000000
void cp2102_out(unsigned char data);
unsigned int a2d_result;
unsigned int voltage;
unsigned char dig1;
unsigned char dig2;
 
void main()
{
TRISA=0X01; //RA0 is analogue input
TRISB=0;
TRISC=0X80; //RC6 as TX, RC7 as RX
PORTC=0;
 
ADCON0=0X41;    //Fosc/8 , ch-0 , AD ON
ADCON1=0X0E;    //left justify, RA0 analogue , VDD & VSS Vref
OPTION=0X07;    
TMR0=0;
 
TXSTA=0X24; //transmitting control
RCSTA=0X90; //receiving control
SPBRG=25;   //boud rate
 
T0IF=0; //interrupt controlls
T0IE=1; //      ''
ADIF=0; //      ''
ADIE=1; //      ''
PEIE=1; //      ''
GIE=1;  //interrupt controlls
 
dig1=voltage/10;
dig2=voltage%10;
 
while(1)
{
cp2102_out(dig1+0x30);  //data out to usb
cp2102_out('.');
cp2102_out(dig2+0x30);  //data out to usb
}
}
 
void interrupt isr()
{
double temp;
 
if(T0IF==1){    //wait for capacitor charging
    GO=1;       //A2D convertion start
    T0IF=0;
}
if(ADIF==1){    //digital convertion
    a2d_result=0;
    a2d_result=ADRESH;
    a2d_result=a2d_result<<2;
    ADRESL=ADRESL>>6;
    a2d_result=a2d_result + ADRESL;
ADIF==0;
}
temp=(double)50/(double)1023;
voltage = temp * (double)a2d_result;
}
 
void cp2102_out(unsigned char data)
{
while(!TXIF){
}
TXREG=data;
}



i received this error.

Code:
Make: The target "C:\Users\jey\Desktop\pic\bdd.p1" is out of date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\jey\Desktop\pic\bdd.c -q --chip=16F884 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Error   [192] C:\Users\jey\Desktop\pic\bdd.c; 18.1 undefined identifier "OPTION"
Warning [356] C:\Users\jey\Desktop\pic\bdd.c; 60.36 implicit conversion of float to integer

********** Build failed! **********

please help me.
 
Last edited by a moderator:

You get the output:
Make: The target "C:\Users\jey\Desktop\pic\bdd.p1" is out of date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.83\bin\picc.exe" --pass1 C:\Users\jey\Desktop\pic\bdd.c -q --chip=16F884 -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
Error [192] C:\Users\jey\Desktop\pic\bdd.c; 18.1 undefined identifier "OPTION"
Warning [356] C:\Users\jey\Desktop\pic\bdd.c; 60.36 implicit conversion of float to integer

The error is the part I've highlighted in red.

It says that OPTION can not be identified by the compiler. This means it is not defined in the header file. Probably you have to use OPTION_REG instead of OPTION. Try it and post the result.

Try to identify the header file for 16F884 in the directory where all the header files are and check in that file.

Hope this helps.
Tahmid.

---------- Post added at 21:21 ---------- Previous post was at 21:18 ----------

I have checked and it's the file "pic16f887.h".
Which version of Hi-Tech C are you running? In the header file "pic16f887.h" for my installed version of Hi-Tech C (9.60), I can see that the OPTION register is defined.

Try with OPTION_REG.
Also tell us which version of the compiler you're running.

---------- Post added at 21:22 ---------- Previous post was at 21:21 ----------

If you still get the error, comment out the line, build it and see if you still get the error. Post your results here.
 

:smile:
Hi , Tahmid
Thank you very much. keep in touch.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top