Hi, im a newbie at c programming, currently im trying to program a board using atmel 89c5131 microchip. Currently i managed to to do the clock but i cant seem to figure out how to make the alarm function. i have 5 buttons to use, button 1-5, them being P33, P10, P12, P13 and P14 respectively. Below is my current state of the program. Would appreciate some help and directions. I would also like the clock to be running at the back when i am setting the alarm. Thanks in advance!
this is my code currently, sorry i do not how to post the code in the right format:
Code:
#include "reg52.h"
#include <string.h>
//--- LCD Control Register Declaration -------
#define RS P16
#define RW P17
#define E P11
unsigned int calHr, calMin, calSec;
unsigned int hr, min, sec;
unsigned char msec = 0;
//----- Delay Subroutine -------
void delay( unsigned long duration)
{
while ( ( duration -- )!= 0);
}
//--------- Strobe Signal for LCD -----
void strobe()
{
E = 1;
delay( 50 );
E = 0;
delay( 50 );
}
//----- LCD initialisation -----
void LCD_init()
{
unsigned char x;
for ( x = 0 ; x < 3 ; x ++){
P0 = 0x30;
RS = 0;
RW = 0;
strobe();
delay( 750 );
}
P0 = 0x38;
strobe();
P0 = 0x0c;
strobe();
P0 = 0x01;
strobe();
P0 = 0x02;
strobe();
}
//----- LCD Character Print routine --------
void LCD_Print( unsigned char x)
{
P0 = x;
RS = 1;
strobe();
}
//----- LCD Command ----------
void LCD_Command( unsigned char x)
{
P0 = x;
RS = 0;
strobe();
}
//------ LCD Line Print ---------
void LCD_Print_Line( printData )
unsigned char *printData;
{
unsigned char x;
for( x = 0 ; x < strlen( printData ); x++)
LCD_Print( printData[ x ] );
}
//-------CLOCK--------
void displayClock(hr, min, sec)
{
unsigned int calHr;
unsigned int calMin;
unsigned int calSec;
RS=1;
calHr = hr;
calMin = min;
calSec = sec;
//display hour
P0=(calHr/10)+0x30;
strobe();
P0=(calHr%10)+0x30;
strobe();
P0=0x3A; //display
strobe();
//display minutes
P0=(calMin/10)+0x30;
strobe();
P0=(calMin%10)+0x30;
strobe();
P0=0x3A; //display
strobe();
//display seconds
P0=(calSec/10)+0x30;
strobe();
P0=(calSec%10)+0x30;
strobe();
}
void main()
{
P26=0; //off buzzer
E = 0;
LCD_init(); //initialize the LCD
LCD_Command( 0x01 ); // clear screen
for(;;){
//CLOCK
TR1=1; //start time
while(TF1==0);
if(TF1==1)
{
TF1=0; //reset the timer flag
msec++; //increment millisec by 1
TH1=0xD8; //this its to set the 10ms time
TL1=0xF0;
if(msec==22)
{
sec++; //increment sec by 1
msec=0; //reset millisec back to 0
if(sec==60)
{
min++; //increment min by 1
sec=0; //reset sec back to 0
if(min==60)
{
hr++; //increment hr by 1
min=0; //reset min back to 0
if(hr>12)
{
hr=1; //reset back hour to 1
}
}
}
}
}
LCD_Command(0x85);
LCD_Print_Line("CLOCK:");
LCD_Command(0xC4);
displayClock(hr, min, sec);
/*LCD_Command( 0x80 );
LCD_Print_Line("Hello Mr James.");
LCD_Command( 0xc0 );
LCD_Print_Line("Can I help you?");*/
}
}