my c code is as shown below but when i compile in keil compailer it will show as c(4): warning C318: can't open file 'DELAY.H' c(21): warning C206: 'delay_ms': missing function-prototype (21): error C267: 'delay_ms': requires ANSI-style prototype Target not created please someone help me to correct this
#include<stdio.h> #include<math.h> #include<reg51.h> #include"DELAY.H" # define DATA P1 void msdelay(unsigned int); sbit e=P3^7; sbit rw=P3^6; sbit rs=P3^5; sbit s1=P2^0; sbit s2=P2^1; sbit s3=P2^2; sbit relay=P0^6; sbit s4=P2^3; void mov_stepper(unsigned char dir,unsigned char rot) { while(rot>0) { if(dir=='c') { P0=0X08; delay_ms(5); P0=0X04; ms_delay(5); P0=0X02; ms_delay(5); P0=0X01; ms_delay(5); } if(dir=='a') { P0=0X01; ms_delay(5); P0=0X02; ms_delay(5); P0=0X04; ms_delay(5); P0=0X08; ms_delay(5); } rot--; } } void lcd_cmd(unsigned char temp) { DATA=temp; rs=0; rw=0; e=1; ms_delay(5); e=0; ms_delay(5); } void lcd_data(unsigned char temp) { DATA=temp; rs=1; rw=0; e=1; ms_delay(5); e=0; ms_delay(5); } void lcd_init() { lcd_cmd(0x38); lcd_cmd(0x06); lcd_cmd(0x0e); lcd_cmd(0x01); lcd_cmd(0x80); } void lcd_puts(unsigned char *s) { lcd_init(); while(*s!='\0') { lcd_data(*s); s++; } } void main() { P0=0X00; P2=0X00; while(1) { if(s1==1) { mov_stepper('c',3); lcd_puts("FIELD A"); while(s1!=0) { relay=1; } relay=0; mov_stepper('a',3); lcd_puts("MONITORING"); } if(s2==1) { mov_stepper('c',6); lcd_puts("FIELD B"); while(s2!=0) { relay=1; } relay=0; mov_stepper('a',6); lcd_puts("MONITORING"); } if(s3==1) { mov_stepper('a',9); lcd_puts("FIELD C"); while(s3!=0) { relay=1; } relay=0; mov_stepper('c',9); lcd_puts("MONITORING"); } if(s4==1) { lcd_puts("FIELD D"); while(s4!=0) { relay=1; } relay=0; lcd_puts("MONITORING"); } lcd_puts("MONITORING"); } }
follow the posting instructions and, maybe someone can figure out your problem
anyhow based on the errors I doubt it is "my c code", the errors are typical for a download from the web
Rule #1 when you get compilation errors: Try to understand the first error you get.
"c(4): warning C318: can't open file 'DELAY.H'"
So - why should _we_ try to help you with this? If this is _your_ code, then _you_ already have written a "delay.h" file.
If this is _not_ your code, then maybe you should look for a "delay.h" file in the same location you found all the other code.
You need to improve your C skills a bit more before you try to sit down and take the next test at school - your teacher really expect you to understand the meaning of include files. And the result of trying to include a file that the compiler can't locate...
I got the same code. You can fix it to make a file "DELAY.H" and put in the line
void msdelay ( unsigned int tadger ) { if ( tadger != 0 ) msdelay ( tadger-- ); }
And that would be a high score in bad content of the file.
Why place the implementation in the header file, when the original code was written with the intention of having the delay in a separate source file?
Secondly - the OP has significant issues with what name to use for the delay function. And you selected to suggest a third alternative name.
Thirdly - why implement a recursive delay?
sir actually i dont know to make c code. I am mechanical student i just copied the code for my project
so just me gave you any code. and some mr person complained about that.
a small change and you can compile it. it is not best but it can help u. plz try.
make a file "DELAY.H" and typing in the lines
#define delay_ms(gogo) mydelay(gogo) #define msdelay(gogo) mydelay(gogo) #define ms_delay(gogo) mydelay(gogo)
void mydelay ( unsigned int tadger ) { while ( tadger > 0 ) { unsigned long i; for ( i = 0 ; i < 65327 ; i = i + 1 ) ; } }
fix a very little error
void mydelay ( unsigned int tadger ) { while ( tadger > 0 ) { unsigned long i; tadger -= tadger; for ( i = 0 ; i < 65327 ; i = i + 1 ) ; } }
code is very complicated. easy to get bugs :-(
void mydelay ( unsigned int tadger ) { while ( tadger > 0 ) { unsigned long i; tadger -= 1; for ( i = 0 ; i < 65327 ; i = i + 1 ) ; } }
Thank you very much sir.It is working
are you saying that they give you a project that you have no idea how to handle, even if you had paid attention in class?
just to get the name back
I'd probably want to pay for such an education with photocopied bank notes.