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 / Speedometer cum odometer using AT89S52

Speedometer cum odometer using AT89S52

|

Microcontroller › 8051 › Speedometer cum odometer using AT89S52

  • This topic has 17 replies, 5 voices, and was last updated 11 years, 10 months ago by isaac obiora.
Viewing 15 posts - 1 through 15 (of 18 total)
1 2 →
  • Author
    Posts
  • January 20, 2013 at 7:31 am #2081
    speedo
    Participant

    Good day , i have this project which requires us to make a digital speedometer and odometer and used AT89S52. I have tried it on Proteus (ISIS) simulator and is actually working. However, i am having a problem implementing it in breadbord and/or PCB. i am quite sure that all my connections were correct and all are according to the schematic diagram. i dont have any background in programming a microcontroller such as AT89S52 and i think i am having problems with the codes. the LCD display is only displaying boxes. please help me with this problem.thank you.

     

    this is the code

     

    Main

     

    #include”at89x52.h”

    #include”lcd.h”

    #include<24cxx.c>

    unsigned char val=0x00;

    unsigned int distance=0,speed=0,cal=0;

    unsigned char km=0,t=0;

    void timer0(void) interrupt 1

    {

    t++;

    distance=distance+100;

    if(distance==1000)

    {

    km=km+1;

    t=0;

    distance=0;

    }

    }

    void one_sec()

    {

    unsigned int i,j;

    for(i=0;i<120;i++)

    {

    for(j=0;j<1271;j++)

    {

    ;

    }

    }

    }

    void display(int num)

    {

    unsigned char t,u,f;

    t=num%10;

    num=num/10;

    u=num%10;

    num=num/10;

    f=num%10;

    lcd_data(‘0’+f);

    lcd_data(‘0’+u);

    lcd_data(‘0’+t);

    }

    void bintoascii(unsigned char value)

    {

    unsigned char x,d1,d2,d3,a,b,c;

    x=value/10;

    d1=value%10;

    d2=x%10;

    d3=x/10;

    a=0x30|d1;

    b=0x30|d2;

    c=0x30|d3;

    lcd_data(‘ ‘);

    lcd_data(c);

    lcd_data(b);

    lcd_data(a);

    lcd_com(0xc0);

    lcd_puts(“KM: “);

    display(km);

    lcd_puts(” MT: “);

    display(distance);

    }

    void main()

    {

    unsigned char c=0,d=0;

    T1=1;

    T0=1;

    TMOD=0x66;

    TH0=206;

    TL0=206;

    TH1=0;

    TL1=0;

    TR0=1;

    P1=0xFF;

    IE=0x82;

    RW24XX(&c, 1, 1, 0xA1, M2404);

    RW24XX(&d, 1, 4, 0xA1, M2404);

    t=d;

    km=c;

    distance=t*100;

    c=0;d=0;

    lcd_init();

    lcd_com(0x01);

    lcd_com(0x0C);

    lcd_com(0x80);

    while(1)

    {

    TR0=1;

    val=TL0;

    TL1=0;

    TR1=1;

    one_sec();

    speed=TL1;

    TR1=0;

    cal=(speed*7);

    lcd_com(0x80);

    lcd_puts(“Speed “);

    display(cal);

    lcd_com(0x89);

    lcd_data(‘ ‘);

    bintoascii(val);

    if(speed==0)

    {

    c=km;

    d=t;

    RW24XX(&c, 1, 1, 0xA0, M2404);

    RW24XX(&d, 1, 4, 0xA0, M2404);

    }

    if(P1_4==0)

    {

    while(P1_4!=1);

    c=0;

    RW24XX(&c, 2, 1, 0xA0, M2404);

    }

    }

    }

     

    January 20, 2013 at 8:24 am #8995
    mohamed abbas
    Participant

    are you sure you download firmware in your chip with correct crystal frequency ?

    January 21, 2013 at 5:54 am #9001
    AJISH ALFRED
    Participant

    Suggest you to try the following:

    Connect an extra LED in series with a 330 ohm resistance to any of the GPIO pin and the other end to ground.

    Burn any simple LED blinking code; If the LED blinks then we are sure that the code is running on the microcontroller and there is any issues regarding the crystal, firmware and all.

    Now burn any simple LCD display code and observe how the LCD respond. If there is no response then check your LCD connections again.

    January 21, 2013 at 6:58 am #9008
    speedo
    Participant

    Sir Ajish Alfred thank you for the reply. i would really like to check if the lcd/microcontroller is working but i dont how to program simple codes to test it. i only downloaded the codes l.can i just use this LED Blinker code i have downloaded in the internet?

     

    #include <REGX51.H> // it is the header file of AT89S52 µcontroller
    #define LEDPORT P2     // define PORT P2

    void Delay(void); //Function prototype declaration

    void main (void) {

    while(1) //End less while so that program never ends
    {
    LEDPORT = 0×55; //01010101 binary
    Delay();
    LEDPORT = 0xaa; //10101010 binary
    Delay();
    }
    }
    void Delay(void)
    {
    int j; int i;
    for(i=0;i<10;i++) // for() loop
    {
    for(j=0;j<10000;j++); // delay loop
    {
    }
    } }

     

    thank you again sir

     

    January 21, 2013 at 7:00 am #9009
    speedo
    Participant

    Sir Mohamed Abbas i am sure that i used the correct crystal frequency which is 11.0592MHz . thank you for the reply

    January 21, 2013 at 7:02 am #9011
    mohamed abbas
    Participant

    this is sample code. try to burn it at microcontroller and give us feedback.

    January 21, 2013 at 10:27 am #9014
    speedo
    Participant

    ok sir i will try it tomorrow. By the way this is the schematic diagram that im using for the project. i have used AT89C52 here because AT89S52 is not available in Proteus(ISIS) which i used to simulate the circuit.and luckily it is working just fine.also the circuit and codes(i posted earlier) is working even if i use AT89C51. can i ask how it is possible? wysiwyg_imageupload:7217:thank alot for helping me

    January 21, 2013 at 10:52 am #9015
    mohamed abbas
    Participant

    in your case yes because they have the same pin configuration

    January 21, 2013 at 11:36 am #9016
    speedo
    Participant

    oh i see, that settles it.also they belong to 8051 family. how about the “include <AT89X52> or the library ” do i need to change that if i will use AT89C51? if yes how can i do that? ive tried many times changing it but errors occurs whenever i convert it to hex file using KeilUvision. thanks again for your tym

    January 21, 2013 at 12:46 pm #9017
    mohamed abbas
    Participant

    you will use the same header file

     

    #include <REGX51.H>

     

    but may be the problem you not change the microcontroller you can do it from menu project then choose select device …. and choose your microcontroller

    January 21, 2013 at 1:16 pm #9018
    speedo
    Participant

    i understand but i have done it many times before but still error occurs. or am i missing something?

    January 21, 2013 at 1:38 pm #9019
    mohamed abbas
    Participant

    what is the message of error ?

    January 21, 2013 at 2:57 pm #9021
    speedo
    Participant

    wysiwyg_imageupload:7235:

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Build target ‘Target 1’
    compiling main.c…
    MAIN.C(1): error C103: ‘<string>’: unclosed string
    MAIN.C(1): error C141: syntax error near ‘<string>’
    main.c(1): warning C318: can’t open file ‘<REGX51.H’
    main.c(1): error C305: unterminated string/char const
    LCD.H(17): error C202: ‘P2_0’: undefined identifier
    LCD.H(18): error C202: ‘P2_1’: undefined identifier
    LCD.H(19): error C202: ‘P2’: undefined identifier
    LCD.H(20): error C202: ‘P2_2’: undefined identifier
    LCD.H(22): error C202: ‘P2_2’: undefined identifier
    LCD.H(30): error C202: ‘P2_0’: undefined identifier
    LCD.H(32): error C202: ‘P2_1’: undefined identifier
    LCD.H(35): error C202: ‘P2’: undefined identifier
    LCD.H(36): error C202: ‘P2’: undefined identifier
    LCD.H(37): error C202: ‘P2_2’: undefined identifier
    LCD.H(39): error C202: ‘P2_2’: undefined identifier
    LCD.H(42): error C202: ‘P2’: undefined identifier
    LCD.H(43): error C202: ‘P2’: undefined identifier
    LCD.H(44): error C202: ‘P2_2’: undefined identifier
    LCD.H(46): error C202: ‘P2_2’: undefined identifier
    LCD.H(50): error C202: ‘P2_0’: undefined identifier
    Target not created

     

    i just changed the include <AT89X52> to #include <REGX51.H>  and then change the device from At89S52 to At89C51 is that the correct way to do that. im so sorry i really dont have any idea about mcu programming

    January 21, 2013 at 8:02 pm #9024
    mohamed abbas
    Participant

    you write

     

    #include “<REGX51.H>”

     

    it’s sure wrong. the correct writing

     

    #include <REGX51.H>

     

    without “

    January 22, 2013 at 7:02 am #9028
    amit kulkarni
    Participant

    this is one of the part of my project. i am done with this part and its working well too.. but programming is in assembly language.

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

RSS Recent Posts

  • Droplet1 December 14, 2025
  • Bringing a Siemens W-48 and Ericsson Model 1951 back to life December 14, 2025
  • What is involved to convert a small town to fiber optic? December 14, 2025
  • mechanism to shutdown feeding when sensor temperature rises December 13, 2025
  • Oshonsoft MSSP simulation question December 13, 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