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

Digital clock program using AT892051

Hi, I'm writing a code for digital clock in Keil C, but I'm not getting the expected results. Can anybody please help me with the program? The code is as follows..

#include <AT892051.H>
#include <stdio.h>
#include <intrins.h>

sbit PIN_P10=P1^0;/* Character to be transfered through this bit in parallel*/
sbit PIN_P11=P1^1;/* Clock*/
sbit PIN_P12=P1^2;/* Latch*/
sbit CS4=P1^3; /* 1st 7-segment Display*/
sbit CS3=P1^4; /* 2nd 7-segment Display*/
sbit CS2=P1^5; /* 3rd 7-segment Display*/
sbit CS1=P1^6; /* 4th 7-segment Display*/

unsigned char DataWrite;
unsigned char _crol_(unsigned char Temp,unsigned char DataWrite);
char Display_Buffer[6];
unsigned char Dispcount;
unsigned char mscount;

int Hours=1;
int Minutes=0;
int Seconds=0;
int i=0;
char Temp;

code unsigned char Lookup[11]=
{ 0xEE,0x28,0xCD,0x6C,0x2B,0x67,0xE7,0x2C,0xEF,0x2F
};

void main()
{

TMOD=0x01; TH0=0xF8; /* Initializing timer0*/ TL0=0x30; /*for 1ms*/ IE=0x82; TR0=1;

do
{

sprintf(Display_Buffer,"%02d%02d",Hours,Minutes); /* converting int into char*/

}while(1);

}

void Timer0(void) interrupt 1
{ TF0=0; TR0=0; TH0=0xF8; TL0=0x30; TR0=1;

{ mscount++; Dispcount++; if(mscount>=1000) { mscount=0; Seconds++; } if(Seconds>=59) { Seconds=0; Minutes++; } if(Minutes>=59) { Minutes=0; Hours++; } if(Hours>=12) { Hours=1; }
}

{ if(Dispcount==29) /* This code is for refresh rate*/ { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==30) {

DataWrite=Lookup[Display_Buffer[0]-0x30];

}

if(8>i) { i++; if (Dispcount==34) { Temp=DataWrite; } if (Dispcount==32) { PIN_P11=1; }

if (Dispcount==36) { PIN_P10=Temp^7; } if (Dispcount==38) { PIN_P11=0; } if (Dispcount==40) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0;

if(Dispcount==48) { CS1=1; }
}

{ if(Dispcount==49) { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==50) {

DataWrite=Lookup[Display_Buffer[1]-0x30];

}

{

if(8>i)

{ i++; if (Dispcount==54) { Temp=DataWrite; } if (Dispcount==52) { PIN_P11=1; }

if (Dispcount==56) { PIN_P10=Temp^7; } if (Dispcount==58) { PIN_P11=0; } if (Dispcount==60) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0; }

if(Dispcount==68) { CS2=1; }
}

{ if(Dispcount==69) { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==70) {

DataWrite=Lookup[Display_Buffer[2]-0x30];

}

{

if(8>i) { i++; if (Dispcount==74) { Temp=DataWrite; } if (Dispcount==72) { PIN_P11=1; }

if (Dispcount==76) { PIN_P10=Temp^7; } if (Dispcount==78) { PIN_P11=0; } if (Dispcount==80) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0; }

if(Dispcount==88) { CS3=1; }
}

{ if(Dispcount==89) { CS1=0; CS2=0; CS3=0; CS4=0; } if(Dispcount==90) {

DataWrite=Lookup[Display_Buffer[3]-0x30];

}

{

if(8>i) { i++; if (Dispcount==94) { Temp=DataWrite; } if (Dispcount==92) { PIN_P11=1; }

if (Dispcount==96) { PIN_P10=Temp^7; } if (Dispcount==98) { PIN_P11=0; } if (Dispcount==100) { DataWrite=_crol_(Temp,1); }

} PIN_P12=0; }

if(Dispcount==108) { CS4=1; }
}

if(Dispcount==821) { CS1,CS2,CS3,CS4=0;

}
} RETI;

Parents
  • Have you considered how fast a shift register is compared to the instruction sequencing of your processor? Have you introduced huge capacitances on the signals, or why do you assume that you need a huge state machine for slowing down the output of the bits to the shift register?

    What is the fastest frequency the shift register can shift? What is the fastest speed your processor can tggle a processor pin? What is your conclusion from these times?

Reply
  • Have you considered how fast a shift register is compared to the instruction sequencing of your processor? Have you introduced huge capacitances on the signals, or why do you assume that you need a huge state machine for slowing down the output of the bits to the shift register?

    What is the fastest frequency the shift register can shift? What is the fastest speed your processor can tggle a processor pin? What is your conclusion from these times?

Children
  • I've posted the new code of only one LED now. But I stil don't know whtat to declare for Dispcount, since it keeps on incrementin for 1ms. Dispcount is used for refresh rate

  • That is an absolutely basic, first step in 'C' programming - nothing specifially to do with Keil.
    (in fact, it's not even specific to 'C' - the same would apply in any other programming language with "typed" variables)

    You really need to go back and review the notes from your first few 'C' classes.
    (and/or the early chapters of your 'C' textbook)

    If you're still stuck, you really need to discuss this with your tutors - since the assignment clearly assumes that you had nailed this issue a long time ago!