This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Code in C

hi, here is a code, can any one tell me why its not working properly, its digital clock

same code like this i use in ASM that working prfct, but its not working


//#include <AT89Cstm.h> /* special function register declarations */
//#include <stdio.h>
#ifndef __REG52_H__
#define __REG52_H__

sfr DataPort = 0xA0; // Port 2

sfr p0 = 0x80;
sfr p1 = 0x90;
sfr p2 = 0xA0;
sfr p3 = 0xB0;

sbit Seg1 = 0x90; // Port 1 pin 0, Sec1
sbit Seg2 = 0x91; // Port 1 pin 1,
sbit Seg3 = 0x92; // Port 1 pin 2,
sbit Seg4 = 0x93; // Port 1 pin 3,
sbit Seg5 = 0x94; // Port 1 pin 4,
sbit Seg6 = 0x95; // Port 1 pin 5, Hor 2

sbit ShowTime = 0xb6; // port 0.6
sbit SetTime = 0xb7; // port 0.7

sbit PulseIn = 0xB2; // port 3.2

sbit IncrementPressed = 0x97; // port 3.3                Min or hor Increment
sbit DecrementPressed = 0x96; // port 3.4                Min or hor Decrement

sbit MINorHOr = 0xB5; // port 3.5                Min or hor selection

sbit SegHL = 0xB3; // Segment common High or Low port 3.2
sbit DataHL = 0xB4; // Segment Data High or Low

#endif



unsigned char sec=0,min=10,hour=15,day=1,mnth=1,year=2011;
unsigned char SegData[12] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0xB9};
                        //   0    1    2    3    4    5    6    7    8    9   blnk  C
                        //   gfedcba        gfedcba                                 hgfedcba
                        //   0111111        1001111        ..         ..      ..    10111001

bit SecStored = 0;
bit IncrementStored = 0;
bit DecrementStored = 0;
bit TimeStop = 0;
bit TimeSaved = 0;
bit SendData = 0;
unsigned char  SendCount = 0;
void ShowSec();
void ShowMin();
void ShowHour();
void IncSec();
void IncMin();
void IncHour();
//void DecSec();
void DecMin();
void DecHour();
void Delay();
void ScanSecond();
void ScanIncrement();
void ScanInputs();
void ScanDecrement();
void ScanDecrement();

void main()
   {
unsigned int temp=0;

p0 = 255;
p1 = 0;
p2 = 0;
p3 = 255;

while (temp !=1)
        {

                if (SetTime == 0 || ShowTime == 0)
                {
                        ShowSec();
                        ShowMin();
                        ShowHour();
                        if (SetTime == 0)
                        {
                                ScanIncrement();
                                ScanDecrement();
                        }
                }
                else
                {
                        if(TimeStop == 1)
                        {
                                TimeStop = 0;
                        }
                                p1 = 255;
                                p2 = 255;

                }
                ScanSecond();
        }
 }

void ScanSecond()
{
        if (PulseIn == 1 && SecStored == 0 && TimeStop == 0)  // Scan Second Pulse
        {
                IncSec();
                SecStored = 1;
        }
        else
        {
                if (PulseIn == 0 && SecStored == 1)
                {
                SecStored = 0;
                }
        }
}

void ScanIncrement()
{
        if (IncrementPressed == 0 && IncrementStored == 0 )  // Scan Increment Pulse
        {
                if (MINorHOr == 1 )
                {
                        IncMin();
                        SendData = 1;
                }
                else
                {
                        IncHour();
                        SendData = 1;
                }
                IncrementStored = 1;
                TimeStop = 1;
                sec = 0;
        }
        else
        {
                if (IncrementPressed == 1 && IncrementStored == 1)
                {
                IncrementStored = 0;
                }
        }
}

void ScanDecrement()
{
        if (DecrementPressed == 0 && DecrementStored == 0 )  // Scan Decrement Pulse
        {
                if (MINorHOr == 1 )
                {
                        DecMin();
                        SendData = 1;
                }
                else
                {
                        DecHour();
                        SendData = 1;
                }
                DecrementStored = 1;
                TimeStop = 1;
                sec = 0;
        }
        else
        {
                if (DecrementPressed == 1 && DecrementStored == 1)
                {
                DecrementStored = 0;
                }
        }
}



void ShowSec()
{
        Seg6 = (~SegHL);
        if(DataHL == 0)
                DataPort = SegData[sec % 10];
        else
                DataPort = (~(SegData[sec % 10]));
        Seg1 =  SegHL;
Delay();
        Seg1 = (~SegHL);
        if(DataHL == 0)
                DataPort = SegData[sec / 10];
        else
                DataPort = (~(SegData[sec / 10]));
        Seg2 =  SegHL;
Delay();
}

void ShowMin()
{
        Seg2 = (~SegHL);
        if(DataHL == 0)
                DataPort = SegData[min % 10];
        else
                DataPort = (~(SegData[min % 10]));
        Seg3 =  SegHL;
Delay();
        Seg3 = (~SegHL);
        if(DataHL == 0)
                DataPort = SegData[min / 10];
        else
                DataPort = (~(SegData[min / 10]));
        Seg4 =  SegHL;
Delay();
}

void ShowHour()
{
        Seg4 = (~SegHL);
        if(DataHL == 0)
                DataPort = SegData[hour % 10];
        else
                DataPort = (~(SegData[hour % 10]));
        Seg5 =  SegHL;
Delay();
        Seg5 = (~SegHL);
        if(DataHL == 0)
                DataPort = SegData[hour / 10];
        else
                DataPort = (~(SegData[hour / 10]));
        Seg6 =  SegHL;
Delay();
}

void IncSec()
{
sec = sec + 1;
if(sec==60)
        {
        sec = 0;
        if (SetTime == 1 )
        IncMin();
        }
}

void IncMin()
{
min = min + 1;
if(min==60)
        {
        min=0;
        if (SetTime == 1 )
        IncHour();
        }
}

void IncHour()
{
hour = hour + 1;
if(hour==24)
        {
        hour = 0;
        //IncHour();
        }
}
/*
void DecSec()
{
sec = sec - 1;
if(sec==255)
        {
        sec = 59;
        if (SetTime == 1 )
        DecMin();
        }
}
  */
void DecMin()
{
min = min - 1;
if(min==255)
        {
        min=59;
        if (SetTime == 1 )
        DecHour();
        }
}

void DecHour()
{
hour = hour - 1;
if(hour==255)
        {
        hour = 23;
        //IncHour();
        }
}

void Delay()
   {
  unsigned int i;
        for(i=0; i<100; i++)
  {
  }

   }

Parents
  • "but its not working"

    Brilliant error description. How many hours did you spend before you managed to compress the error description into these words?

    How many do you think will care about your source code, with that amount of error description from you?

    By the way - how proud are you over your software delay? And your amount of source code comments?

Reply
  • "but its not working"

    Brilliant error description. How many hours did you spend before you managed to compress the error description into these words?

    How many do you think will care about your source code, with that amount of error description from you?

    By the way - how proud are you over your software delay? And your amount of source code comments?

Children