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.

PIC16f877A C program help

Status
Not open for further replies.

Exan

Newbie level 5
Joined
Jan 4, 2011
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,355
I am trying to convert two Analog signals to Digital using a pic16f877A and outputting it to a transmitter. I don't have much experience programing in C but this is what i have so far. I'm using Sourceboost to compile and it states that i have an undefined identifier 'adcin'. Need help.


#include <system.h>
#define pPIC16f877A
#define adc_bits 10
#define adc_clock 3
#define adc_sampleus 10

void main()
{
trisa=11111111b;
trisd=00000000b;
adcon1=10000010b;
char convert1, convert2;
while(1)
{
adcin 0,convert1;
portd =10000000b;
portd = convert1;

}
}
 

Hi,

You may go trough you compiler-help and PIC-datasheet to find
how to define analog-input for PIC,
how to select analog in put pin for ADC conversion,
how to perform the conversion,

You have not defined adcin and may be not in the library also.
What you expected to do "adcin 0,convert1" ?

Find answers, you can proceed,
 

I used the adcin 0, convert1 using this webpage as reference

**broken link removed**

should i not use ADCIN? like it shows on that page?
Ive already looked into the data sheet and i still dont understand how to write it in C

I simply want to obtain an analog voltage signal and convert it to digital so i can transmit it in serial
 

ADCIN is a buiilt in function of the PIC BASIC Pro compiler (according to the webpage you gave us). You are using the SourceBoost C compiler, which obviously does not have this function. You will have to search the SourceBoost manual to see if they have something similar.

You cannot use a compiler to build code written for a different compiler. Also note that the code you used for a reference is BASIC, and you are compiling in C.

r.b.
 
Last edited:

Ok I finally understood the language of the compiler and this is what i have come up with. It isn't working. What i did was output the conversion to port D and port B to test it but it doesn't seem to work. Eventually i want to send the info to a transmitter via Serial but i want to make sure the conversion is working. I installed LEDs to the ports so that it would show the binary result. As you can tell from the script i placed a three second delay so that it gives me time to see the change visually. Please help i dont know if the script is incorrect or i have a hardware problem.


#include <system.h>
#define pPIC16f877A
#define adc_bits 10
#define adc_clock 3
#define adc_sampleus 10

void main()
{
trisa=11111111b;
trisd=00000000b;
trisb=00000000b;

//char ct1a,ct1b,ct2a,ct2b,ct3a,ct3b,ct4a,ct4b;
//short ct1,ct2,ct3,ct4;
char firstA,firstB,secondA,secondB,thirdA,thirdB,fourthA,fourthB;
while(1)
{
portb=00000000b;
portd=00000000b;
pie1=00000000b;
adcon0=00000001b;
adcon1=11000011b;
nop();
nop();
nop();
adcon0=00000101b;
if (adcon0==00000001b)
{pir1=00000000b;}
firstA=adresl;
firstB=adresh;

portb=firstA;
portd=firstB;
delay_s(3);
//adresl= ct1b;
//adresh= ct1a;
//ct1=ct1a+ct1b;

portb=00000000b;
portd=00000000b;
pie1=00000000b;
adcon0=00001001b;
adcon1=11000011b;
nop();
nop();
nop();
adcon0=00001101b;
if (adcon0==00001001b)
{pir1=00000000b;}

secondA=adresl;
secondB=adresh;
portb=secondA;
portd=secondB;
delay_s(3);
//adresl= ct2b;
//adresh= ct2a;
//ct2=ct2a+ct2b;

portb=00000000b;
portd=00000000b;
pie1=00000000b;
adcon0=00010001b;
adcon1=11000011b;
nop();
nop();
nop();
adcon0=00010101b;
if (adcon0==00010001b)
{pir1=00000000b;}
thirdA=adresl;
thirdB=adresh;
portb=thirdA;
portd=thirdB;
delay_s(3);
//adresl= ct3b;
//adresh= ct3a;
//ct3=ct3a+ct3b;

portb=00000000b;
portd=00000000b;
pie1=00000000b;
adcon0=00100001b;
adcon1=11000011b;
nop();
nop();
nop();
adcon0=00100101b;
if (adcon0==00100001b)
{pir1=00000000b;}
fourthA=adresl;
fourthB=adresh;
portb=fourthA;
portd=fourthB;
//adresl= ct4b;
//adresh= ct4a;
//ct4=ct4a+ct4b;
delay_s(3);
}
}
 

Dear friend

I can help u to solve this problem and also send u some sample codes, but u have to switch the compiler from Sourceboost to CCS info PICC. R u interested? If yes do me know. Best of luck

Regardz

Ayaz Ahmed
 

Dear friend

I can help u to solve this problem and also send u some sample codes, but u have to switch the compiler from Sourceboost to CCS info PICC. R u interested? If yes do me know. Best of luck

Regardz

Ayaz Ahmed



Thank you but i really don't want to purchase new software and the demo doesn't work with my MPLAB. Plus I may change my PIC later on and the free demo doesn't configure many PICs. Thank you though
 

Dear friend

I can help u to solve this problem and also send u some sample codes, but u have to switch the compiler from Sourceboost to CCS info PICC. R u interested? If yes do me know. Best of luck

Regardz

Ayaz Ahmed



Thank you but i really don't want to purchase new software and the demo doesn't work with my MPLAB. Plus I may change my PIC later on and the free demo doesn't configure many PICs. Thank you though

My friend if u r interested i can send u the full version of this software. Moreover you dont need MPLAB to work with software, its stand alone, but u can do so because MPLAB plugin of this software is also available in the full version.

Regardz

Ayaz Ahmed
 

My friend if u r interested i can send u the full version of this software. Moreover you dont need MPLAB to work with software, its stand alone, but u can do so because MPLAB plugin of this software is also available in the full version.

Regardz

Ayaz Ahmed



Ok that sounds good. Thank you!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top