EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Re: Project MC012 – Problems with code

Re: Project MC012 – Problems with code

|

Microcontroller › 8051 › Re: Project MC012 – Problems with code

  • This topic has 36 replies, 5 voices, and was last updated 14 years, 1 month ago by dagakshay.
Viewing 15 posts - 1 through 15 (of 37 total)
1 2 3 →
  • Author
    Posts
  • February 15, 2011 at 10:23 am #679
    G Thomas
    Participant

    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 #5535
    dagakshay
    Participant

    can you send the eerors please

     

    February 16, 2011 at 5:30 am #5539
    Anonymous
    Guest

    please 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 #5540
    G Thomas
    Participant

    Thanks alot for your time. Much appreciated.
     
    Compiling   8052.c
    Error 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 #5541
    G Thomas
    Participant

    Used 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 #5545
    dagakshay
    Participant

    i 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 #5549
    G Thomas
    Participant

    THANKYOU 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 #5559
    dagakshay
    Participant

    use 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…

    http://www.kmitl.ac.th/~kswichit/IspPgm30a/ISP-Pgm30a.html 

    February 21, 2011 at 12:17 pm #5563
    G Thomas
    Participant

    Hey 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 #5564
    G Thomas
    Participant

    code 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 #5566
    Dharmit
    Participant

    hey im having trouble converting c to hex…. 

    February 21, 2011 at 8:28 pm #5568
    G Thomas
    Participant

    when the stop button is pressed it jumps a second or so….

     

     

    February 22, 2011 at 7:20 am #5576
    dagakshay
    Participant

    go to the link:

    http://www.engineersgarage.com/forums/8051/how-convert-c-code-hex-code-using-keil-compiler 

    February 22, 2011 at 7:22 am #5577
    dagakshay
    Participant

    hello s_g_tom

    please elobrate yourself

    March 7, 2011 at 8:39 am #5665
    G Thomas
    Participant

    code 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?

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 37 total)
1 2 3 →
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault [unrepairable] July 20, 2025
  • using a RTC in SF basic July 20, 2025
  • Dismantling a WestinghouseRoku TV ? July 20, 2025
  • Does US electric code allow branching ? July 20, 2025
  • My Advanced Realistic Humanoid Robots Project July 20, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise