• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC C Compiler

pwbtech

New Member
Hi
I am having difficulty with a project i was given. My task is to write C code for the PIC16F877 micro-controller to store 10 A/D readings in an array. Can anyone direct me in the right direction with this code?

//#define TEST
#define ADC

//#define ADCON0 register Address
#define ADCON0_ADD 0x1f
#define ADRESH_ADD 0x1e

//#define ADC Clock Frequency
#define ADC_frequency_mask 0b00111111
fosc_2 0b00000000
fosc_8 0b01000000
fosc_16 0b10000000
fosc_32 0b11000000

//define ADC_CHANNEL
#define ADC_CHANNEL_MASK 0b11000111
#define ADC_CHANNEL_0 0b11000111
#define ADC_CHANNEL_1 0b11000111
#define ADC_CHANNEL_2 0b11000111
#define ADC_CHANNEL_3 0b11000111
#define ADC_CHANNEL_4 0b11000111
#define ADC_CHANNEL_5 0b11000111

//#define ADCON bit
#define ADON 0b00000001
#define ADGO 0b00000100

//function like preprocessor macros
#define MASK_ADC_FREQ(x) x&=ADC_frequency_mask
#define SET_ADC_CLOCK_FREQUECY(x,b) x|=b

#define MASK_ADC_CHANNEL(x) x&=ADC_CHANNEL_MASK
#define SET_ADC_CHANNEL(x,b) x|=b

#define TURN_ON_ADC(x) x|=ADON
#define START_ADC(x) x|=ADGO

void main()
{
byte *pADCON0=ADCON_ADD;
byte *pADRESH=ADRESH_ADD;
byte results[10];
float average=0;
byte i;



////////////////////////////////////////////////////
#ifdef TEST1
////////////////////////////////////////////////////
while(1)
set_tris_c(0x00);
while(1)
for(i=1; i<8; i++)
{
*ptr_port_c = 0x01;
for(i=1; i<8; i++)
{
*ptr_port_c <<=1;
delay_ms(50);
}
*ptr_port_c = 0x80;
for(i=1; i<8; ++i)
{
*ptr_port_c >>=1;
delay_ms(50);
}
}
#endif

}


////////////////////////////////////////////////////
#ifdef ADC
////////////////////////////////////////////////////
while(1)
{
MASK_ADC_FREQ(*pADCON0);
SET_ADC_CLOCK_FREQUENCY(*pADCON0,fosc_8);

MASK_ADC_CHANNEL(*pADCON0);
SET_ADC_CHANNEL(*pADCON0,ADC_CHANNEL_0);

TURN_ON_ADC(*PADCON0);
average=0;

for(i=0;i<10;i++)
{
START_ADC(*pADCON0);
do
}
//wait for ADC to complete conversion
}

while(*pADCON0 & ADGO);
results=*pADRESH;
average += results;
}
average /=10;
}
#endif
////////////////////////////////////////////////////
}




Dont mind the bit masking for now, i still have to get the data sheets. The project requires the use of pointers. Do i have to set up a .HEX file or can i just compile it like so?
Any help much appreciated!!!!!!!!!!!!!!
:p :p :p :p
 

smcd

New Member
ADMIN EDIT:
This post has been removed.

If anyone abuses other members or posts any type of abuse you will be banned! We have word sensors and the words used have been added, any attempts to post them they will be replaced automatically by [bleep]'s.

Thank you to the people that reported this incident, the user smcd has now been banned. If any further incidents happen please send a private message to either a moderator or myself(ElectroMaster).
 

kinjalgp

Active Member
What is going on smcd? Please do not use such language in this forum.
This is a warning to you! One more time and you are no more allowed to post here. :evil:
 

Chippie

Member
I think we can do without this sort of language on here........He ought to be banned......no second chance!!! imho...... :(
 

kinjalgp

Active Member
Very true Chippie!
They seem to be project partners. And because pwbtech asked for some help, his partner is angry on him. This is what the whole story appears to me.

But whatever may the case, this is absolutely intolerable. Lets see what Electromaster says about smcd.
 

Chippie

Member
pwbtech, you can get the data sheet from microchips website and there is usually sample code there too.

Now, I aint a programmer, ( takes me all my time to set the alarm clock, only kidding......) but what you need to do now is if your happy with the code then compile using a C compiler to obtain your hex, then prog the pic.......


here's another good link you may find helpful:
http://www.piclist.com/techref/piclist/index.htm
 

bliamf

New Member
I think that what sbtech is saying is spot on. In this forumn, I believe in saying what u feel, and I feel that paddy is a waster and I applaude sbtech for his courage. I mean face it paddy, ur a waster.
 

johh

New Member
Quiet frankly bliamf and smcd are completely ignorant. This sort of behaviour is unexceptable. The poor chap is only trying to do a bit of C code but pwbtech its not c++. Like come on your better than that. And to the rest of the people who got on to the other two boys keep out of it its
none of your business.
 

Chippie

Member
To the 2 new guys that have joined up, bliamf and johh.

This forum is dedicated to all facets of electronics and is not the place to be sorting out your own petty squabbles..........Grow up and behave like adults!

If you wish to remain memebrs on here then, you should display a little more decorum in regard to the way you present yourselves


"And to the rest of the people who got on to the other two boys keep out of it its none of your business."

I make it my business when people come on here try to undermine the harmony of this forum and what it is about, especially when it involves other people who are trying to educate themselves........

Try using your time a little more constructively , instead of belittling others who wish to learn.
 

pebe

Member
chippie, I agree. The webmaster should throw these yobs off the site.

This is a technical forum, not some verbal battleground for people who conduct themselves like football hooligans.
 

picchead

New Member
Hello pwbtech. I have carefully reviewed your code and I would like ask u a few things.

Is it c or c++ because I can really help you out if it is c. I have recently set up a website with adequate details to suit your needs. If I am not mistaken I think that code is part of an MPLAB ICD project. If it is I have recently completed that project and I have vast information about it.
Enjoy the site.


http://www.busite.hpg.ig.com.br/Lesbicas/Szilvia_Lauren/tn/lindajamesgirlfun007.jpg.html
 

Latest threads

EE World Online Articles

Loading

 
Top