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 / Replies / I’ve tried make visitor

I’ve tried make visitor

|

Microcontroller › 8051 › Automatic Bidirectional Visitor Counter › I’ve tried make visitor

October 29, 2012 at 12:04 pm #8699
kangibnu
Participant

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]!=’’;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

 

wysiwyg_imageupload:6554:

 

RSS Recent Posts

  • Hitachi SuperScan Elite 802 CRT Monitor Issues (Model CM802U) December 7, 2025
  • Sanity Check – Peltier "Cooler" for Heating and Cooling December 7, 2025
  • My Advanced Realistic Humanoid Robots Project December 7, 2025
  • Funny Images Thread! December 7, 2025
  • I am ready to move from electrical and electronics field but confused where ? December 7, 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