Microcontroller › 8051 › Speedometer cum odometer using AT89S52
- This topic has 17 replies, 5 voices, and was last updated 9 years, 9 months ago by
isaac obiora.
-
AuthorPosts
-
January 20, 2013 at 7:31 am #2081
speedo
ParticipantGood 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 #8995mohamed abbas
Participantare you sure you download firmware in your chip with correct crystal frequency ?
January 21, 2013 at 5:54 am #9001AJISH ALFRED
ParticipantSuggest 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 #9008speedo
ParticipantSir 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 P2void 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 #9009speedo
ParticipantSir 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 #9011mohamed abbas
Participantthis is sample code. try to burn it at microcontroller and give us feedback.
January 21, 2013 at 10:27 am #9014speedo
Participantok 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 #9015mohamed abbas
Participantin your case yes because they have the same pin configuration
January 21, 2013 at 11:36 am #9016speedo
Participantoh 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 #9017mohamed abbas
Participantyou 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 #9018speedo
Participanti 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 #9019mohamed abbas
Participantwhat is the message of error ?
January 21, 2013 at 2:57 pm #9021speedo
ParticipantBuild 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 createdi 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 #9024mohamed abbas
Participantyou write
#include “<REGX51.H>”
it’s sure wrong. the correct writing
#include <REGX51.H>
without “
January 22, 2013 at 7:02 am #9028amit kulkarni
Participantthis 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.
-
AuthorPosts
- You must be logged in to reply to this topic.