Code:
#include <REG51.H>
//Port pin definition
#define LCD_DATA_PORT P2
//LCD commands
#define FunctionSet 0x3B
#define DisplayOn 0x0E
#define EntryModeSet 0x06
#define ClearScreen 0x01
#define SecondLine 0xC0
//function prototypes
void lcd_data_write(unsigned char display_data) ;
void lcd_command_write(unsigned char display_data);
void delay(unsigned char no_loops);
void delayX1msec(unsigned int no_loops);
void init_lcd();
//pin definitions
sbit EN = P3^5;
sbit RS = P3^4;
sbit RW = P3^6;
sbit buzzer = P1^2;
//function prototype
void delayX1msec(unsigned int no_loops);
//time variables
char seconds=24;
bit run=0;
void main()
{
init_lcd();
//enable switch interrupts
IT0=1;
IT1=1;
IE=0x85;
while(1)
{
delayX1msec(1000); //1 second delay
if(seconds>0&&run==1)
{
seconds--;
}
lcd_command_write(ClearScreen);
lcd_data_write(seconds/10 + 0x30);
lcd_data_write(seconds%10 + 0x30);
if(seconds=0;seconds<10;seconds++)
{
buzzer=1;
delayX1msec(1000);
buzzer=0;
}
}
}
void start_stop_isr() interrupt 2
{
run=~run;
}
void reset_isr()interrupt 0
{
seconds=24;
run=0;
}
//**************************************************************************
//function to generate a delay of x * 1msec
//e.g. delay(50); generates a 50msec delay
//Assumes a 12MHz crystal oscillator
void delayX1msec(unsigned int no_loops)
{
unsigned int x;
TR0 = 0;
TF0 = 0;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x18;
TR0 = 1;
for(x=0;x<no_loops;x++)
{
while(!TF0);
TF0 = 0;
TH0 = 0xFC;
TL0 = 0x18;
}
TR0 = 0;
}
//function to initialise the LCD display
void init_lcd()
{
lcd_command_write(FunctionSet);
lcd_command_write(DisplayOn);
lcd_command_write(EntryModeSet);
lcd_command_write(ClearScreen);
}
//**************************************************************************
// Function to write a display character to the LCD
void lcd_data_write(unsigned char display_data)
{
RW = 0;
RS = 1;
EN = 1;
LCD_DATA_PORT = display_data;
EN = 0;
delayX1msec(5); //delay to allow write operation to complete
}
//**************************************************************************
// Function to write a command to the LCD
void lcd_command_write(unsigned char command)
{
RW = 0;
RS = 0;
EN = 1;
LCD_DATA_PORT = command;
EN = 0;
delayX1msec(5); //delay to allow write operation to complete
}
i want to put a buzzer in so when my time goes to 0 the buzzer goes of for 2 seconds and then stops..i also want to enter a string to say swish when the time reaches 10 and a led will light up for 2 seconds.wil someone please help me...re-enter my code with the things i wwant done in it please..urgent..been stuck for ages