#include <REGX52.H>
sbit e1=P1^7;
sbit e3=P2^1;
sbit e0=P2^0;
sbit e2=P2^2;
sbit e4=P2^3;
sbit buz=P1^7;
sbit sw=P1^3;
sbit sw1=P2^5;
sbit sw2=P2^6;
sbit sw3=P2^4;
//sbit rinc=P3^3;
//sbit rdec=P3^2;
//sbit rset=P3^1;
bit ring=0;
bit a;
//#define off P2=0x00
unsigned int min;
unsigned char dat;
unsigned char message;
void display();
void loop();
void Seg8_decimal2(min);
Send2lcd(unsigned char value);
void delay_ms(unsigned int ms_count);
void delay_us(unsigned int us_count);
unsigned char pt,pt1,pt2,pt3,span;
//unsigned char num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main()
{
min=00;
/*
SCON=0x50;
TMOD=0x20;
TH1=253;
TR1=1;
*/
TMOD |= 0X20; // Timer 1 in mode 2
TH1=-24; // Baud rate of 1200
SCON = 0X50; //Asynchronous 8-bit data
TR1 = 1; // Turn ON the timer
while(1)
{
/*
if(ring==1)
{
SBUF=message;
ring=0;
}
*/
SBUF =min;
while(TI==0);
TI=0;
loop();
if(a==1)
{
span++;
buz=0;
delay_ms(10);
buz=1;
if(span==70)
{
a=0;
buz=1;
span=0;
}
}
}
}
void loop()
{
//delay_ms(100);
Send2lcd(min);
Seg8_decimal2(min);
//if(sw==0)
//rinc=0;
//else
//rinc=1;
//if(sw1==0)
//rset=0;
//else
//rset=1;
//if(sw2==0)
//rdec=0;
//else
//rdec=1;
pt=1;
while(!sw)
{
if(pt==1)
{
min++;
ring=1;
pt=0;
}
Send2lcd(min);
Seg8_decimal2(min);
//delay_ms(10);
a=1;
}
while(!sw1)
{
//while(sw==0);
if(pt==1)
{
min--;
pt=0;
}
Send2lcd(min);
Seg8_decimal2(min);
//delay_ms(10);
if(min==0xffff)
min=999;
}
while(!sw2)
{
if(pt==1)
{
min=0;
pt=0;
}
Send2lcd(min);
Seg8_decimal2(min);
//delay_ms(10);
a=1;
}
/*
while(!sw3)
{
if(pt==1)
{
min=0;
pt=0;
}
Send2lcd(min);
Seg8_decimal2(min);
//delay_ms(10);
a=1;
}
*/
//rinc=1;
}
void Seg8_decimal2(min)
{
unsigned int Lcd_hr,Lcd_t,Lcd_o;
Lcd_hr=min%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
dat=Lcd_t+0x30;
display();
//P1=0x04;
e3=1;
delay_ms(5);
e0=e2=e3=0;
dat=Lcd_o+0x30;
display();
//P1=0x08;
e2=1;
delay_ms(5);
e0=e2=e3=0;
if(min>99)
if(min<=199)
{
P0=0xf9;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>199)
if(min<=299)
{
P0=0xa4;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>299)
if(min<=399)
{
P0=0xb0;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>399)
if(min<=499)
{
P0=0x99;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>499)
if(min<=599)
{
P0=0x92;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>599)
if(min<=699)
{
P0=0x82;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>699)
if(min<=799)
{
P0=0xf8;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>799)
if(min<=899)
{
P0=0x80;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>899)
if(min<=999)
{
P0=0x90;
//P0=0xf9;
e0=1;
delay_ms(5);
e0=e1=e2=e3=0;
}
if(min>999)
{
min=00;
}
}
Send2lcd(unsigned char value)
{
unsigned char buf1,buf2,buf = 0;
buf1 = value & 0xF0; /* Filter for high byte */
buf1 = (buf1>>4); /* Convert to ascii code */
buf2 = value & 0x0F; /* Filter for low byte */
buf=(buf1*10)+buf2;
return buf;
}
void delay_ms(unsigned int ms_count)
{
while(ms_count!=0)
{
delay_us(112); //delay_us is called to generate 1ms delay
ms_count--;
}
}
void delay_us(unsigned int us_count)
{
while(us_count!=0)
{
us_count--;
}
}
void display()
{
if(dat==0x30)
P0=0xc0;
//P0=0x3f;
if(dat==0x31)
P0=0xf9;
//P0=0x06;
if(dat==0x32)
P0=0xa4;
//P0=0x5b;
if(dat==0x33)
P0=0xb0;
//P0=0x4f;
if(dat==0x34)
P0=0x99;
// P0=0x66;
if(dat==0x35)
P0=0x92;
//P0=0x6d;
if(dat==0x36)
P0=0x82;
//P0=0x7d;
if(dat==0x37)
P0=0xf8;
//P0=0x07;
if(dat==0x38)
P0=0x80;
//P0=0x7f;
if(dat==0x39)
P0=0x90;
//P0=0x6f;
}
Arduino code:
[CODE]
int incommingByte=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.read();
incommingByte=Serial.read();
if(incommingByte==2)
digitalWrite(13, HIGH);
}
circuit diagram:
[ATTACH]157692._xfImport[/ATTACH]