Microcontroller › 8051 › Re: Project MC012 – Problems with code
- This topic has 36 replies, 5 voices, and was last updated 13 years, 6 months ago by dagakshay.
-
AuthorPosts
-
February 15, 2011 at 10:23 am #679G ThomasParticipant
Hey guys I was trying to make the stopwatch but I have problems with the code provided. Shows 59 errors! I’d like to program the microcontroller asap as everything else is ready to go! Please help!
Thank you!
//Program to make a stopwatch
#include<reg51.h>
#define msec 1
unsigned int sec1,sec2;
int sec1_1,sec1_2,sec2_1,sec2_2;
unsigned int digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
sbit dig_ctrl_1=P1^0; // Declare the control pins of seven segments
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_4=P1^3;
sbit start_pin = P1^4; // Start pin to start the watch.
sbit stop_pin = P1^5; // Stop pin to stop the watch.
sbit reset_pin = P1^6; // Reset pin to reset the watch.
int s,t;
void mplex_delay(unsigned int time) // Function to provide a time delay of approximatelty one second using Timer 1
{
int i,j;
for (i=0;i<=time;i++)
for(j=0;j<=50;j++);
}
void digi_out(unsigned int current_num)
{
P2=digi_val[current_num];
mplex_delay(msec);
}
void display(unsigned int dig1,unsigned int dig2) // Function to display the digits on seven segmnet. For more details refer seven segment multiplexing.
{
sec1_2=dig1%10;
sec1_1=dig1/10;
sec2_2=dig2%10;
sec2_1=dig2/10;
TMOD=0x01; //Enable Timer 0
TL0=0xFF;
TH0=0xDB;
TR0=1; // Triger Timer 0
while(TF0==0)
{
dig_ctrl_1 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_1);
dig_ctrl_2 = 1;
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;
digi_out(sec1_2);
dig_ctrl_3 = 1;
dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;
digi_out(sec2_1);
dig_ctrl_4 = 1;
dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;
digi_out(sec2_2);
}
TR0=0;
TF0=0;
}
void main()
{
while(1)
{
start: // Segment to start the stop watch
start_pin = 1;
stop_pin = 1;
reset_pin = 1;
dig_ctrl_1 = 0;
dig_ctrl_2 = 0;
dig_ctrl_3 = 0;
dig_ctrl_4 = 0;
P2 = 0xFF;
s = t = 0;
while(start_pin == 1)// Check if start pin is pressed
{
display(0,0);
}
stopwatch: // Segment to stop the watch
for (sec1=s;sec1<=99;sec1++)
{
if (stop_pin == 0 ) //Check if stop pin is pressed
break;
for (sec2=t;sec2<=99; sec2++)
{
if (stop_pin == 0 ) //Check if stop pin is pressed
break;
t=0;
display(sec1,sec2);
}
}
stop_pin = 1;
s = sec1;
t = sec2;
while ( start_pin != 0 && reset_pin != 0 ) //Check if start pin or reset pins are not pressed
{
display(sec1,sec2);
}
if (start_pin == 0) //Check if start pin is pressed
{
goto stopwatch;
}
else
{
if (reset_pin == 0 ) //Check if reset pin is pressed
{
s = t = 0;
goto start;
}
}
}
}
February 15, 2011 at 10:49 am #5535dagakshayParticipantcan you send the eerors please
February 16, 2011 at 5:30 am #5539AnonymousGuestplease post your errors and also mention which compiler are u using?
please see if the header file is getting included properly or not.. so many errors can occur mainly due to that.
February 16, 2011 at 10:03 am #5540G ThomasParticipantThanks alot for your time. Much appreciated.Compiling 8052.cError Count = 59“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 3 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 10 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 11 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 12 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 13 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 14 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 15 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 16 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 20 error: undefined symbol “of”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 21 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 23 error: illegal symbol name“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 24 error: illegal symbol name“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 25 error: invalid argument specifier“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 27 error: attempt to define a variable of type void“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 29 error: undefined symbol “P2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 34 error: undefined symbol “the”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 35 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 36 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 37 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 38 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 39 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 40 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 41 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 42 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 43 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 44 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 45 error: illegal symbol name“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 47 error: undefined symbol “dig_ctrl_1”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 48 error: undefined symbol “dig_ctrl_2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 49 error: undefined symbol “digi_out”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 50 error: undefined symbol “dig_ctrl_2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 51 error: undefined symbol “dig_ctrl_1”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 52 error: undefined symbol “digi_out”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 53 error: undefined symbol “dig_ctrl_3”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 54 error: undefined symbol “dig_ctrl_2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 55 error: undefined symbol “digi_out”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 56 error: undefined symbol “dig_ctrl_4”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 57 error: undefined symbol “dig_ctrl_2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 58 error: undefined symbol “digi_out”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 61 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 62 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 63 error: Syntax error“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 70 error: undefined symbol “start_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 71 error: undefined symbol “stop_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 72 error: undefined symbol “reset_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 73 error: undefined symbol “dig_ctrl_1”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 74 error: undefined symbol “dig_ctrl_2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 75 error: undefined symbol “dig_ctrl_3”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 76 error: undefined symbol “dig_ctrl_4”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 77 error: undefined symbol “P2”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 79 error: undefined symbol “start_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 87 error: undefined symbol “stop_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 91 error: undefined symbol “stop_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 97 error: undefined symbol “stop_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 101 error: undefined symbol “start_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 102 error: undefined symbol “reset”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 103 error: no semicolon“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 107 error: undefined symbol “start_pin”“C:Program Files (x86)RigelReads51Work8052 digital stopwatch8052.c” 113 error: undefined symbol “reset_pin”February 16, 2011 at 10:28 am #5541G ThomasParticipantUsed read 51 complier
tried programming AT89s52 using universal programmmer (http://www.mqp.com/pm48.htm). but apparebntky need to conver it into hex?
February 17, 2011 at 5:37 am #5545dagakshayParticipanti was very sure about that but still i wnted to confirm that is why i asked you for the queries…
i assumed that you are using KEIL compiler… and if not my suggestion to use that..
there might be two thing one is yoiu havn’t included the #include<reg51.h>
in your code…
or if you have included then either the keil have not installed properly or go to the drive in your computer where you have installed keil software, the go to keil folder open it open C51 named folder then to ASM there you find the all hedder files your software is supporting,,, check REG51 is present of not…that file must be there…
if its not there either downlad that file or downlaod other keil version and try…
still if you get any problem let me know….
download keil from here:
http://worldforfree.net/software/1146159878-keil-c51-v901-compiler-uvision-4-ide.html
February 17, 2011 at 1:33 pm #5549G ThomasParticipantTHANKYOU for the reply and suggestions. Much appreciated. In the process of trying it.
I was told I need to cinvert the code to hex to program the microcontroller… any ideas? or any ideas on how to program the microcontroller?
thanks again
February 21, 2011 at 5:02 am #5559dagakshayParticipantuse keil compiler its very much simple to use.. this compiler has an option to convert the C code into hex code…
you need a programmer (also known as burner) to dump you hex code into controller…
go for the link it is the simplest burner ckt using parallel port…
February 21, 2011 at 12:17 pm #5563G ThomasParticipantHey thanks again for your post and help.
The link you gave me for the Keil compiler doesnt seem to have any creadible download links on that page. Have you got any other links to download the Keil compiler?
Best regards,
February 21, 2011 at 1:25 pm #5564G ThomasParticipantcode size limit 2k? *** error 56: can’t open file? keep getting this any ideas?
sorry but im really new at this. Just trying to play and learn.
February 21, 2011 at 2:47 pm #5566DharmitParticipanthey im having trouble converting c to hex….
February 21, 2011 at 8:28 pm #5568G ThomasParticipantwhen the stop button is pressed it jumps a second or so….
February 22, 2011 at 7:20 am #5576dagakshayParticipantFebruary 22, 2011 at 7:22 am #5577dagakshayParticipanthello s_g_tom
please elobrate yourself
March 7, 2011 at 8:39 am #5665G ThomasParticipantcode works now without errors. but as u can see in video :
http://www.engineersgarage.com/microcontroller/8051projects/stopwatch-AT89C51-circuit
when stop button is pressed it jumps a second. how do i alter code to make it more accurate and record up to max 9 seconds and accurate to miliseconds?
-
AuthorPosts
- You must be logged in to reply to this topic.