We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am using At89x52 microcontroller in the solar tracker. I use the ADC MCP3208 to connect the two ldr and convert it into digital signal by ADC MCP 3208.
But,it shows syntex error in code. Help me with this
#include<at89x52.h> #include<stdio.h> #define ADC_CS=P1^5; #define ADC_ClK P1^2; #define ADC_MOSI=P1^4; #define ADC_MISO=P1^3; #define p1 sbit ADC_CLK = p1^2; sbit ADC_MISO = P1^3; sbit ADC_MOSI = P1^4; sbit ADC_CS = P1^5; void initSerial(void); void write_adc_byte(char data_byte); unsigned int ReadADC(unsigned char channel); { { unsigned int adc_val=0; char i; ADC_CS=1; ADC_CLK=1; ADC_MOSI=1; ADC_MISO=1; ADC_CS=0; ADC_MOSI=1; ADC_CLK=0; msdelay(100); ADC_CLK=1; ADC_MOSI=1; ADC_CLK=1; ADC_MOSI=0; ADC_CLK=0; msdelay(100); ADC_CLK=1; ADC_MOSI=0; ADC_CLK=0; msdelay(100); ADC_CLK=1; ADC_MOSI=0; ADC_CLK=0; msdelay(100); ADC_CLK=1; for(i=11;i>=0;i-) { ADC_CLK=0; if(ADC_MISO) adc_val|=(1<<i); ADC_CLK=1; } ADC_CS=1; temp1=((adc_val*5.0/4095); return temp1; } { unsigned int adc_val=0; float temp; char i; ADC_CS=1; ADC_CLK=1; ADC_MOSI=1; ADC_MISO=1; ADC_CS=0; ADC_MOSI=1; ADC_CLK=0; msdelay(100); ADC_CLK=1; ADC_MOSI=1; ADC_CLK=1; ADC_MOSI=0; ADC_CLK=0; msdelay(100); ADC_CLK=1; ADC_MOSI=0; ADC_CLK=0; msdelay(100); ADC_CLK=1; ADC_MOSI=1; ADC_CLK=0; msdelay(100); ADC_CLK=1; for(i=11;i>=0;i-) { ADC_CLK=0; if(ADC_MISO) adc_val|=(1<<i); ADC_CLK=1; } ADC_CS=1; temp2=((adc_val*5.0/4095); return temp2; } } void init_uart() { SCON=0X50; TMOD=0X20; TH1=OXFD; TR1=1; TI=1; } { if(temp1>temp2) { cw=0; ccw=1; } else if(temp1<temp2) { cw=1; ccw=0; } else { cw=0; ccw=0; } } if(cw==1) { P1=OX66; msdelay(100); P1=OXCC; msdelay(100); P1=OX99; msdelay(100); P1=OX33; msdelay(100); } else if(ccw==1) { P1=0X66; msdelay(100); P1=0X33; msdelay(100); P1=OX99; msdelay(100); P1=0XCC; msdelay(100); } void msdelay(unsigned int value) { unsigned int x,y; for(x=0;x<1275;x++) for(y=o;y<value;y++); } Errors: compiling NEWCODE1.c... NEWCODE1.c(1): warning C500: MISSING LICENSE ID CODE (LIC) IN 'TOOLS.INI' NEWCODE1.c(10): error C141: syntax error near '^', expected 'sizeof' NEWCODE1.c(11): error C141: syntax error near '=', expected '<id>' NEWCODE1.c(11): error C141: syntax error near '=', expected 'hdata' NEWCODE1.c(11): error C129: missing ';' before '^' Target not created. Build Time Elapsed: 00:00:00
Help me with this.
That's usually an indication that you have completely confused the compiler!
So, as I said, look back over the preceding lines for mistakes.
There are some big ones!
What do you think this line does:
#define ADC_CS=P1^5;
And this:
#define p1
I think you need to re-read the section on preprocessor definitions in your 'C' textbook
In particular, these are preprocessor directives - not 'C' statements - so they should not end with semicolons (unless you want the semicolon to form part of the definition).
Those preprocessor definitions will completely mess up the code that follows - hence the bizarre error messages!
This is all standard 'C' stuff - not specific to Keil or 8051.
Here are some 'C' learning & reference resources - including a free online 'C' textbook: blog.antronics.co.uk/.../