1. 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.
    Dismiss Notice

PIC C Compiler

Discussion in 'Microcontrollers' started by pwbtech, Apr 8, 2003.

  1. pwbtech

    pwbtech New Member

    Joined:
    Apr 8, 2003
    Messages:
    2
    Likes:
    0
    Location:
    Ireland
    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
     
  2. smcd

    smcd New Member

    Joined:
    Apr 8, 2003
    Messages:
    1
    Likes:
    0
    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).
     
  3. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA
    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:
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Chippie

    Chippie New Member

    Joined:
    Mar 8, 2003
    Messages:
    991
    Likes:
    9
    Location:
    Good 'ole England

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

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA
    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.
     
  7. Chippie

    Chippie New Member

    Joined:
    Mar 8, 2003
    Messages:
    991
    Likes:
    9
    Location:
    Good 'ole England
    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
     
  8. bliamf

    bliamf New Member

    Joined:
    Apr 9, 2003
    Messages:
    2
    Likes:
    0
    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.
     
  9. johh

    johh New Member

    Joined:
    Apr 9, 2003
    Messages:
    1
    Likes:
    0
    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.
     
  10. Chippie

    Chippie New Member

    Joined:
    Mar 8, 2003
    Messages:
    991
    Likes:
    9
    Location:
    Good 'ole England
    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.
     
  11. pebe

    pebe Member

    Joined:
    Sep 24, 2002
    Messages:
    354
    Likes:
    1
    Location:
    Ellon - Scotland
    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.
     
  12. ElectroMaster

    ElectroMaster Administrator

    Joined:
    Jul 5, 2002
    Messages:
    2,051
    Likes:
    127
    Location:
    Broadbeach, AU
    Hi peeps,

    I hope we can continue this post now that i have removed the trouble maker. pwbtech asked a good question and i hope this incedent has not put him off posting again.

    Once again thanks to the people that reported this and I hope that everyone can continue this thread :p
     
  13. bliamf

    bliamf New Member

    Joined:
    Apr 9, 2003
    Messages:
    2
    Likes:
    0
    ADMIN EDIT:
    Your banned too :)

    :lol: ElectroMaster is on a banning spree
     
  14. picchead

    picchead New Member

    Joined:
    Apr 10, 2003
    Messages:
    1
    Likes:
    0
    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
     

Share This Page