ADC C programming using PIC18 and SK40C

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

ADC C programming using PIC18 and SK40C

Postby ghostajip » Sat Nov 24, 2012 7:31 am

can anyone help me to solve this problem. it's always failed to build and i dont know what wrong with my program. maybe i miss something..

for your reference.
- MPLAB IDE v8.85
- im using infrared sensor 5v from cytron
- using vcc = VDD SK40c, GND and Singal from ir sensor i connect to RA0
- im try to make LED at port C on when sensor detect something.


this my first program.
CODE: SELECT_ALL_CODE
#include<p18f4580.h>
void DelayADC(unsigned int);
void main (void);
   {
   TRISB=0;
   TRISD=0;
   TRISAbits.TRISA0=0;
   ADCON0=0x81;
   ADCCON1=0xCE;      //right justify,AN0=analog

   while(1);
      {
      DelayADC(1);
      ADCONbits.GO=1;   //start converting
      while (ADCONbits.DONE == 1)
      PORTC=ADRESL;
      PORTD=ADRESH;
      DelayADC(250);
      }   
            
      
         
   }



void DelayADC(unsigned int itime)
{
   unsigned int i,j;
   for(i=0;i<itime;i++)
      for(j=0;j<300;j++);
}
ghostajip
Freshie
 
Posts: 6
Joined: Sat Nov 24, 2012 12:53 am

Re: ADC C programming using PIC18 and SK40C

Postby zhenning » Sat Nov 24, 2012 7:50 am

ghostajip WROTE:can anyone help me to solve this problem. it's always failed to build and i dont know what wrong with my program. maybe i miss something..

for your reference.
- MPLAB IDE v8.85
- im using infrared sensor 5v from cytron
- using vcc = VDD SK40c, GND and Singal from ir sensor i connect to RA0
- im try to make LED at port C on when sensor detect something.


this my first program.
CODE: SELECT_ALL_CODE
#include<p18f4580.h>
void DelayADC(unsigned int);
void main (void);
   {
   TRISB=0;
   TRISD=0;
   TRISAbits.TRISA0=0;
   ADCON0=0x81;
   ADCCON1=0xCE;      //right justify,AN0=analog

   while(1);
      {
      DelayADC(1);
      ADCONbits.GO=1;   //start converting
      while (ADCONbits.DONE == 1)
      PORTC=ADRESL;
      PORTD=ADRESH;
      DelayADC(250);
      }   
            
      
         
   }



void DelayADC(unsigned int itime)
{
   unsigned int i,j;
   for(i=0;i<itime;i++)
      for(j=0;j<300;j++);
}


Whats the errors? Did you download C compiler for MPLAB: HiTech C,or MCC18?
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: ADC C programming using PIC18 and SK40C

Postby ghostajip » Sat Nov 24, 2012 1:59 pm

of course im using MCC18. the program failed to build because syntax error. i dont know what wrong or missing.

CODE: SELECT_ALL_CODE
Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.43\bin\mcc18.exe" -p=18F4580 /i"C:\MCC18\H" "xx.c" -fo="xx.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\Users\User\Desktop\C prgram mini\xx.c:4:Error: syntax error
Halting build on first failure as requested.BUILD FAILED



when i click at blue link to identify the problem, it show me to this line

CODE: SELECT_ALL_CODE
#include<p18f4580.h>
void DelayADC(unsigned int);
void main (void);
  {                      //  <<<<<<<< this line >>
   TRISB=0;
   TRISD=0;
   TRISAbits.TRISA0=0;
   ADCON0=0x81;
   ADCCON1=0xCE;   
ghostajip
Freshie
 
Posts: 6
Joined: Sat Nov 24, 2012 12:53 am

Re: ADC C programming using PIC18 and SK40C

Postby zhenning » Sat Nov 24, 2012 2:05 pm

ghostajip WROTE:void main (void);



void main(void){ } ? No?

Why there is a semi-colon after the (void)?
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: ADC C programming using PIC18 and SK40C

Postby ghostajip » Sat Nov 24, 2012 2:29 pm

zhenning WROTE:
ghostajip WROTE:void main (void);



void main(void){ } ? No?

Why there is a semi-colon after the (void)?


ok i delete semi colon, sory i forget about that.
yes but syntax error again


CODE: SELECT_ALL_CODE
void main (void)
{
   TRISB=0;
   TRISD=0;
   TRISAbits.TRISA0=0;
   ADCON0=0x81;
   ADCCON1=0xCE;
   {
      //same program
   }
}
ghostajip
Freshie
 
Posts: 6
Joined: Sat Nov 24, 2012 12:53 am

Re: ADC C programming using PIC18 and SK40C

Postby ghostajip » Sat Nov 24, 2012 2:34 pm

can anyone show me how to program ADC in c programming..
i can learn my mistake
ghostajip
Freshie
 
Posts: 6
Joined: Sat Nov 24, 2012 12:53 am

Re: ADC C programming using PIC18 and SK40C

Postby zhenning » Sat Nov 24, 2012 2:53 pm

ghostajip WROTE:
zhenning WROTE:
ghostajip WROTE:void main (void);



void main(void){ } ? No?

Why there is a semi-colon after the (void)?


ok i delete semi colon, sory i forget about that.
yes but syntax error again


CODE: SELECT_ALL_CODE
void main (void)
{
   TRISB=0;
   TRISD=0;
   TRISAbits.TRISA0=0;
   ADCON0=0x81;
   ADCCON1=0xCE;
   {
      //same program
   }
}


Please post the error also :)
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: ADC C programming using PIC18 and SK40C

Postby ghostajip » Sat Nov 24, 2012 4:48 pm

for your info.
Attachments
cc.jpg
this the program and error
ghostajip
Freshie
 
Posts: 6
Joined: Sat Nov 24, 2012 12:53 am

Re: ADC C programming using PIC18 and SK40C

Postby zhenning » Sat Nov 24, 2012 5:24 pm

ghostajip WROTE:for your info.


Right. Where is your semi-colon after your function declaration: void DelayADC(unsigned int);? after your #include
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: ADC C programming using PIC18 and SK40C

Postby robosang » Sat Nov 24, 2012 5:32 pm

I spotted a few too... please take care of the semi-colon..... :D You miss a few in your code.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron