Automatic Bidirectional Visitor Counter
Hi Sindujaa
Displays are common anode.
you can use AT89s52 insted of AT89c51 differences only memory size and one timer added extra in 52.
Regards,
Hari krishna k
From the circuit, it can be found that the seven segment is switched to +5V using a transistor. So I think it is common anode
There are a problem occuring with up key and down key. If we press up key for few second then counter increse no of visitor.suppose that a men stop at position of up sensor for few second then counter count the many people in room.
I've tried make visitor counter circuit and successful, and I want to combine it with articel read write eeprom (I tried it and succeeded), but when I try to combine both methods the program does not work, please help, I want to store data in the eeprom at24c16 count, and show on seven segment display,
here the code...
#include<reg51.h>
#include<intrins.h>
#define msec 50
#define lcd_data_str_pin P0
bit ack;
sbit rs = P3^6; //Register select (RS) pin
sbit rw = P3^5; //Read write(RW) pin
sbit en = P3^7; //Enable(EN) pin
sbit sda=P3^1; //sda
sbit scl=P3^0; //sck
sbit led=P1^0;
sbit led1=P1^1;
sbit sensor_1=P3^1; //sensor1
int max = 0;
int carry = 0;
int arr[4];
//inisialissi varibel eeprom
unsigned char reead,write,write2,b,k;
unsigned int temp;
//
int count_amt[7],j;
unsigned int count_1,count_2;
/*
void delay(int delay_time) // Time delay function
{
int j,k;
for(j=0;j<=delay_time;j++)
for(k=0;k<=1275;k++);
}
*/
void delay(unsigned int count) // Function to provide time delay in msec.
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<500;j++);
}
void lcd_cmd(unsigned char cmd_addr) //Function to send command to LCD
{
lcd_data_str_pin = cmd_addr;
en = 1;
rs = 0;
rw = 0;
delay(1);
en = 0;
return;
}
void lcd_data_str(char str[50]) //Function to send string
{
int p;
for (p=0;str[p]!='\0';p++)
{
lcd_data_str_pin = str[p];
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}
void lcd_data_int(unsigned int count)
{
char dig_ctrl_var;
int p;
for (j=6;j>=0;j--)
{
count_amt[j]=count%10;
count=count/10;
}
for (p=0;p<=6;p++)
{
dig_ctrl_var = count_amt[p]+48;
lcd_data_str_pin = dig_ctrl_var;
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}
void aknowledge() //acknowledge condition
{
scl=1;
_nop_();
_nop_();
scl=0;
}
void start() //start condition
{
sda=1;
scl=1;
_nop_(); //No operation
_nop_();
sda=0;
scl=0;
}
void stop() //stop condition
{
sda=0;
scl=1;
_nop_();
_nop_();
sda=1;
scl=0;
}
void send_byte(unsigned char value) //send byte serially
{
unsigned int i;
unsigned char send;
send=value;
for(i=0;i<8;i++)
{
sda=send/128; //extracting MSB
send=send<<1; //shiftng left
scl=1;
_nop_();
_nop_();
scl=0;
}
ack=sda; //reading acknowledge
sda=0;
}
unsigned char read_byte() //reading from EEPROM serially
{
unsigned int i;
sda=1;
reead=0;
for(i=0;i<8;i++)
{
reead=reead<<1;
scl=1;
_nop_();
_nop_();
if(sda==1)
reead++;
scl=0;
}
sda=0;
return reead; //Returns 8 bit data here
}
void save() //save in EEPROM
{
start();
send_byte(0xA0); //device address
aknowledge();
send_byte(0x00); //word address
aknowledge();
// send_byte(5); //send data
// aknowledge();
// send_byte(65);
// aknowledge();
stop();
/*if(ack==0)
{
led1=1;
delay(100);
led1=0;
delay(100);
lcd_command(0x86);
lcd_data('5');
lcd_command(0x87);
lcd_data('A');
}
else
led1=1;
aknowledge();
*/
}
void Read()
{
/*start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
*/
start();
send_byte(0xA1);//device address
aknowledge();
b=read_byte();
aknowledge();
k=read_byte();
aknowledge();
stop();
if(b==0)
{
led=0;
delay(100);
led=1;
delay(100);
write=b+count_2;
lcd_cmd(0x86);
lcd_data_int(write);
}
else
led=1;
if(k!= 0)
{
lcd_cmd(0x87);
lcd_data_int(count_2);
}
aknowledge();
}
void count_count() //count
{
while (sensor_1==0);
if (sensor_1==1)
{
while (sensor_1 == 1);
{
count_1 = count_1 + 1;
// save();
if(count_2==0)
count_2=count_1;
if(count_2 !=0){
count_2=count_2+1;
start();
send_byte(0xA0); //device address
aknowledge();
send_byte(0x00); //word address
aknowledge();
send_byte(count_2); //send data
aknowledge();
//send_byte(count_1);
//aknowledge();
stop();
if(ack==0)
{
led1=1;
delay(100);
led1=0;
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x01);
delay(5);
lcd_cmd(0x80);
lcd_data_str("Saved: ");
lcd_cmd(0x87);
lcd_data_int(count_2);
}
else
led1=1;
aknowledge();
}
}
}
}
void main()
{
//ini_pin = stop_pin = 1;
count_1= 0;
sensor_1= 0;
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0x80);
delay(5);
lcd_data_str("COUNT UP");
Read();
delay(5);
while(1)
{
//results();
//lcd_ini();
count_count();/*
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0x02);
delay(5);
lcd_cmd(0x80);
delay(5);
lcd_data_str("push switch ");
*/
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0x02);
delay(5);
lcd_cmd(0xC0);
delay(5);
lcd_data_str( "value :" );
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0xC8);
delay(5);
lcd_data_int(count_1);
delay(5);
Read();
delay(5);
}
}
please help and advice
Hi Kangibnu,
I can't see any function call to the eeprom from your main() function. The code will work without calling the eeprom related functions from your main() function.
tank's for your advise..
I will try this....angain....
You are welcome. Please don't forget to update the result.
The following are the programs I use on a counter circuit (see the picture I attached to the previous post), this program is working normally and can save the result of a calculation to memory IC eeprom, after turn off the power supply circuit and restarted, the count value can are saved and can be updated with a few new ones. But there are several obstacles(problems) that count results can be stored into the eeprom IC at24c16 maximum value 256. after the value could not keep back .... and must be reset IC eeprom memory contents.
please give advice to me, which part should I change to be able to display and store the result of a calculation to the value of 999 999
I wait for suggestions from fellow forum
here the code,
/*
Bissmillahirrohmanirrokhiim...
rev.2 tes 26 oktober '2012
Program : Counting up with LCD + eeprom 24c16 + AT89S51
Tanggal : 25 September 2012 - 10 Oktober 2012
Author : Ibnu Budi R. ( kangibnu ) Laros-Edu
Country Org : Indonesia-Jatim
Compiler : Raisonance C Compiler 6.1.6
note : many variable with Bahasa Indonesia
: you can translate in english
*/
#include<reg51.h>
#include<intrins.h>
#define msec 50
#define lcd_data_str_pin P2
bit ack;
sbit rs = P3^6; //Register select (RS) pin
sbit rw = P3^5; //Read write(RW) pin
sbit en = P3^7; //Enable(EN) pin
sbit sda=P3^1; //sda
sbit scl=P3^0; //sck
sbit led=P0^3;
sbit led1=P0^1;
sbit sensor_1=P3^2; //sensor1
sbit sensor_2=P3^3; //sensor2
sbit motor=P1^7; //motor mekanik
int max = 0;
int carry = 0;
int arr[4];
//inisialissi varibel eeprom
unsigned char reead,write,write2,b,k;
unsigned int temp;
//
int hitung_amt[7],j;
unsigned int hitung_1,hitung_2;
void tunda(int waktu) // Time delay function
{
int s,k;
for(s=0;s<=waktu;s++)
for(k=0;k<=20;k++);
}
void delay(unsigned int count) // Function to provide time delay in msec.
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<500;j++);
}
void lcd_cmd(unsigned char cmd_addr) //Function to send command to LCD
{
lcd_data_str_pin = cmd_addr;
en = 1;
rs = 0;
rw = 0;
delay(1);
en = 0;
return;
}
void lcd_data_str(char str[50]) //Function to send string
{
int p;
for (p=0;str[p]!='\0';p++)
{
lcd_data_str_pin = str[p];
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}
void lcd_data_int(unsigned int hitung)
{
char dig_ctrl_var;
int p;
for (j=6;j>=0;j--)
{
hitung_amt[j]=hitung%10;
hitung=hitung/10;
}
for (p=0;p<=6;p++)
{
dig_ctrl_var = hitung_amt[p]+48;
lcd_data_str_pin = dig_ctrl_var;
rw = 0;
rs = 1;
en = 1;
delay(1);
en = 0;
}
return;
}
void aknowledge() //acknowledge condition
{
scl=1;
_nop_();
_nop_();
scl=0;
}
void start() //start condition
{
sda=1;
scl=1;
_nop_(); //No operation
_nop_();
sda=0;
scl=0;
}
void stop() //stop condition
{
sda=0;
scl=1;
_nop_();
_nop_();
sda=1;
scl=0;
}
void send_byte(unsigned char value) //send byte serially
{
unsigned int i;
unsigned char send;
send=value;
for(i=0;i<8;i++)
{
sda=send/128; //extracting MSB
send=send<<1; //shiftng left
scl=1;
_nop_();
_nop_();
scl=0;
}
ack=sda; //reading acknowledge
sda=0;
}
unsigned char read_byte() //reading from EEPROM serially
{
unsigned int i;
sda=1;
reead=0;
for(i=0;i<8;i++)
{
reead=reead<<1;
scl=1;
_nop_();
_nop_();
if(sda==1)
reead++;
scl=0;
}
sda=0;
return reead; //Returns 8 bit data here
}
void Read()
{
start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
start();
send_byte(0xA1);//device address
aknowledge();
b=read_byte();
aknowledge();
k=read_byte();
aknowledge();
stop();
led=0;
delay(100);
led=1;
delay(100);
lcd_cmd(0xc6);
lcd_data_int(b);
led=1;
lcd_cmd(0xc7);
lcd_data_int(k);
aknowledge();
}
void hitung_count() //hitung ( bahasa indonesia ) = Counting
{
while (sensor_1==0);
if (sensor_1==1)
{
//read,counting, save to eeprom
start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
start();
send_byte(0xA1);//device address
aknowledge();
b=read_byte();
aknowledge();
k=read_byte();
aknowledge();
stop();
aknowledge();
//end reading
while (sensor_1 == 1);
{
hitung_1 = hitung_1 + 1;
//begin save to eeprom
// save();
//saving
if(hitung_2==0)
hitung_2=b;
if(b !=0){
hitung_2=hitung_2+1;
start();
send_byte(0xA0); //device address
aknowledge();
send_byte(0x00); //word address
aknowledge();
send_byte(hitung_2); //send data
aknowledge();
send_byte(hitung_2);
aknowledge();
stop();
if(ack==0)
{
led1=1;
delay(100);
led1=0;
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x01);
delay(5);
lcd_cmd(0x80);
lcd_data_str("Saved: ");
lcd_cmd(0x87);
lcd_data_int(hitung_2);
}
else
led1=1;
aknowledge();
// end save to eeprom
}
}
}
}
void sedot()//for motor (optional)
{
motor=1;
tunda(20); //tunda ( bahasa indonesia = delay for motor )
motor=0;
tunda(20);
}
void main()
{
motor=0;
hitung_1= 0;
sensor_1= 1;
sensor_2=1;
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0x80);
delay(5);
lcd_data_str("Insert Document");
delay(5);
//Optional for motor control
while (sensor_2==1);
if (sensor_2==0)
{
motor=1;
//
Read();
delay(5);
while(1)
{
hitung_count();
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0x02);
delay(5);
lcd_cmd(0xC0);
delay(5);
lcd_data_str( "Value :" );
lcd_cmd(0x38);
delay(5);
lcd_cmd(0x0F);
delay(5);
lcd_cmd(0xC8);
delay(5);
lcd_data_int(hitung_1);
delay(5);
}
}
}
I think your code is writing data to the same single page with adress 0x00. Once the page is full you should write to the next page. Go through the datasheet thoroughly to learn more about memory page aceess for that eeprom.
thanks for advise, I'll try it again, is there anything that needs to be changed from the listing program that I attach ...?
give me some example....