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 / The following are the

The following are the

|

Microcontroller › 8051 › Automatic Bidirectional Visitor Counter › The following are the

November 12, 2012 at 3:28 am #8742
kangibnu
Participant

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

RSS Recent Posts

  • Telegram Based Alarm - Sensor cable protection May 21, 2025
  • Chinese Tarrifs – 104%!?! May 21, 2025
  • An Update On Tarrifs May 21, 2025
  • Tariff Updates from JLCPCB as of Today May 21, 2025
  • Solar lighting motion detector May 21, 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