Microcontroller › 8051 › microcontroller coin counter with IR sensor
- This topic has 1 reply, 2 voices, and was last updated 12 years, 7 months ago by AJISH ALFRED.
-
AuthorPosts
-
March 30, 2012 at 5:10 am #4765akmalParticipant
hi there
I m working on coin counter project which can count the no. of coin entering in a boc. I am using at89c51,infrared led and a transistor and lcd for displaying no of counts.
after i make a connection, my LCD show this results. There's no display on it. Im use this code "C Language"
#include<reg51.h>
void lcdcmd (unsigned char value);
void lcddata (unsigned char value);
void lcdready();
void display(unsigned char z);
void MSDelay (unsigned int itime);
sfrldata = 0x90;
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
sbit busy = P1^7;
sbit sen5 = P2^4;
sbit sen10 = P2^5;
sbit sen20 = P2^6;
sbit sen50 = P2^7;
void main()
{
unsigned int a;
unsigned int b;
unsigned int c;
unsigned int e;
unsigned int ao;
unsigned int bo;
unsigned int co;
unsigned int eo;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
lcddata('5');
lcddata('c');
lcdcmd(0x84);
lcddata('1');
lcddata('0');
lcddata('c');
lcdcmd(0x89);
lcddata('2');
lcddata('0');
lcddata('c');
lcdcmd(0x8D);
lcddata('5');
lcddata('0');
lcddata('c');
a = 1;
b = 1;
c = 1;
e = 1;
while(1)
{
sen5 = 1;
sen10 = 1;
sen20 = 1;
sen50 = 1;
while(sen5 == 0)
{
ao = a++;
lcdcmd(0xC0);
display (ao);
MSDelay(100);
}
while(sen10 == 0)
{
bo = b++;
lcdcmd(0xC4);
display (bo);
MSDelay(100);
}
while(sen20 == 0)
{
co = c++;
lcdcmd(0xC9);
display (co);
MSDelay(100);
}
while(sen50 == 0)
{
eo = e++;
lcdcmd(0xCD);
display(eo);
MSDelay(100);
}
}
}
void lcdcmd (unsigned char value){
lcdready();
ldata = value;
rs = 0;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
return;
}
void lcddata (unsigned char value){
lcdready();
ldata = value;
rs = 1;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
return;
}
void lcdready()
{
busy = 1;
rs = 0;
rw = 1;
while (busy == 1)
{
en = 0;
MSDelay (1);
en = 1;
}
return;
}
void display(unsigned char z)
{
unsigned char x,d1,d2;
x = z / 10;
d1 = z % 10;
d2 = x % 10;
lcddata(d2 + 0x30);
lcddata(d1 + 0x30);
}
void MSDelay (unsigned int itime){
unsigned int i,j;
for (i = 0; i<itime; i++)
for (j = 0; j<1275; j++);
}
can anyone find the problem to fix this error??
April 25, 2012 at 1:31 pm #7544AJISH ALFREDParticipanttry the code after changing your lcdready() function like the following
void lcdready()
{
// busy = 1;
rs = 0;
rw = 1;
// while (busy == 1)
// {
en = 0;
MSDelay ( 100 );
en = 1;
// }
return;
}
-
AuthorPosts
- You must be logged in to reply to this topic.