tapu
Full Member level 4
Dear All,
I am transmitting decimal number 0 to 99 wireless by using ''RF seriel uart data link''.both side 89s52 used.code written in keil IDE.As module property data recieve for one second and then stops for one second then recieve for one second this process continues.Therefore my output display ON and OFF continously.My problem is Here how to stable output data on display?My code is given below. please reply.
Tramsmitting code:
Recieving code:
I am transmitting decimal number 0 to 99 wireless by using ''RF seriel uart data link''.both side 89s52 used.code written in keil IDE.As module property data recieve for one second and then stops for one second then recieve for one second this process continues.Therefore my output display ON and OFF continously.My problem is Here how to stable output data on display?My code is given below. please reply.
Tramsmitting code:
Code:
#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=P2^4;
sbit sw1=P2^5;
sbit sw2=P2^6;
sbit sw3=P1^3;
//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=0xFD; // 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;
SBUF=255;
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;
}
Recieving code:
Code:
#include <REGX52.H>
sbit e1=P2^1;
sbit e2=P2^2;
sbit e3=P2^3;
sbit buz=P1^7;
sbit on=P3^7;
sbit sw3=P1^0;
sbit sw2=P1^1;
sbit sw1=P1^2;
sbit sw=P1^3;
sbit zero=P0^0;
sbit one=P0^1;
sbit two=P0^2;
sbit three=P0^3;
sbit four=P0^4;
sbit five=P0^5;
sbit six=P0^6;
sbit seven=P0^7;
//sbit eight=P0^8;
//sbit nine=P0^9;
sbit SDA=P2^6;
sbit SCL=P2^7;
bit a;
#define off P2=0x00
#define EEPROM_ID 0xa0
unsigned int min;
unsigned char dat;
unsigned char message;
void EEPROM_WriteByte(unsigned char eeprom_Address, unsigned char eeprom_Data);
unsigned char EEPROM_ReadByte(unsigned char eeprom_Address);
void I2C_Start();
void I2C_Stop(void);
void I2C_Ack();
void I2C_Write(unsigned char dat);
unsigned char I2C_Read();
void I2C_NoAck();
void I2C_Clock();
void delay_ms(unsigned int ms_count);
void delay_us(unsigned int us_count);
unsigned char ansdigi1;
unsigned char ansdigi2;
unsigned char ansdigi3;
unsigned char push=00;
unsigned char lt=0;
void display();
void loop();
unsigned char catch;
void Seg8_decimal2(min);
Send2lcd(unsigned char value);
unsigned char pt,pt1,pt2,pt3,span;
//unsigned char num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main()
{
buz=0;
pt1=0;
P1=0xff;
P2=0x00;
/*
SCON=0x50;
TMOD=0x20;
TH1=253;
TR1=1;
*/
TMOD |= 0X20; // Timer 1 in mode 2
TH1=0xFD; // Baud rate of 1200
SCON = 0X50; //Asynchronous 8-bit data
TR1 = 1; // Turn ON the timer
min=00;
while(1)
{
while(RI==0);
min=SBUF;
Send2lcd(min);
Seg8_decimal2(min);
RI=0;
lt=0;
//loop();
}
}
// min=EEPROM_ReadByte(0x01);
// EEPROM_WriteByte(0x01, min);
void loop()
{
//P0=ansdigi1;
//delay_ms(100);
Send2lcd(min);
Seg8_decimal2(min);
pt=1;
while(!sw)
{
pt1++;
if(pt==1)
{
if(push==0)
if(lt==0)
{
min=1;
push++;
lt=1;
}
if(push==1)
if(lt==0)
{
min=min*10+1;
push++;
lt=1;
}
if(push==2)
if(lt==0)
{
min=min*10+1;
push=0;
lt=1;
}
pt=0;
buz=0;
}
Send2lcd(min);
Seg8_decimal2(min);
delay_ms(10);
a=1;
if(pt1==100)
{
buz=1;
pt1=0;
}
}
sw1=1;
while(!sw2)
{
if(pt==1)
{
min=min+111;
pt=0;
//buz=1;
}
Send2lcd(min);
Seg8_decimal2(min);
delay_ms(10);
if(min==0xffff)
min=999;
Send2lcd(min);
Seg8_decimal2(min);
}
while(!sw3)
{
if(pt==1)
{
min=00;
pt=0;
}
Send2lcd(min);
Seg8_decimal2(min);
//delay_ms(10);
a=1;
}
while(!sw1)
{
if(pt==1)
{
if(push==0)
if(lt==0)
{
min=2;
push++;
lt=1;
}
if(push==1)
if(lt==0)
{
min=min*10+2;
push++;
lt=1;
}
if(push==2)
if(lt==0)
{
min=min*10+2;
push++;
lt=1;
}
pt=0;
}
Send2lcd(min);
Seg8_decimal2(min);
//delay_ms(10);
a=1;
}
buz=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();
//P0=P3;
ansdigi2=P0;
//P1=0x04;
//P2=0x08;
e3=1;
e2=0;
e1=0;
delay_ms(5);
e1=e2=e3=0;
dat=Lcd_o+0x30;
display();
ansdigi3=P0;
//P0=P3;
//P1=0x08;
//P2=0x04;
e2=1;
e3=0;
e1=0;
delay_ms(5);
e1=e2=e3=0;
if(min>99)
if(min<=199)
{
P0=0x06;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>199)
if(min<=299)
{
P0=0x5b;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>299)
if(min<=399)
{
P0=0x4f;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>399)
if(min<=499)
{
P0=0x66;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>499)
if(min<=599)
{
P0=0x6d;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>599)
if(min<=699)
{
P0=0x7d;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>699)
if(min<=799)
{
P0=0x07;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>799)
if(min<=899)
{
P0=0x7f;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
e1=e2=e3=0;
}
if(min>899)
if(min<=999)
{
P0=0x6f;
ansdigi1=P0;
//P2=0x02;
e1=1;
e2=0;
e3=0;
delay_ms(5);
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)
//P3=0xc0;
P0=0x3f;
if(dat==0x31)
//P3=0xf9;
P0=0x06;
if(dat==0x32)
//P3=0xa4;
P0=0x5b;
if(dat==0x33)
//P3=0xb0;
P0=0x4f;
if(dat==0x34)
//P3=0x99;
P0=0x66;
if(dat==0x35)
//P3=0x92;
P0=0x6d;
if(dat==0x36)
//P3=0x82;
P0=0x7d;
if(dat==0x37)
//P3=0xf8;
P0=0x07;
if(dat==0x38)
//P3=0x80;
P0=0x7f;
if(dat==0x39)
//P3=0x90;
P0=0x6f;
}
void EEPROM_WriteByte(unsigned char eeprom_Address, unsigned char eeprom_Data)
{
I2C_Start(); // Start i2c communication
I2C_Write(EEPROM_ID); // connect to AT2404 by sending its ID on I2c Bus
I2C_Ack();
I2C_Write(eeprom_Address); // Select the Specified EEPROM address of AT2404
I2C_Ack();
I2C_Write(eeprom_Data); // Write the data at specified address
I2C_Ack();
I2C_Stop(); // Stop i2c communication after Writing the data
delay_ms(5); // Write operation takes max 5ms, refer At2404 datasheet
}
unsigned char EEPROM_ReadByte(unsigned char eeprom_Address)
{
unsigned char eeprom_Data;
I2C_Start(); // Start i2c communication
I2C_Write(EEPROM_ID); // connect to AT2404(write) by sending its ID on I2c Bus
I2C_Ack();
I2C_Write(eeprom_Address); // Select the Specified EEPROM address of AT2404
I2C_Ack();
I2C_Start(); // Start i2c communication
I2C_Write(0xA1); // connect to AT2404(read) by sending its ID on I2c Bus
I2C_Ack();
eeprom_Data = I2C_Read(); // Read the data from specified address
I2C_NoAck();
I2C_Stop(); // Stop i2c communication after Reading the data
delay_us(10);
return eeprom_Data; // Return the Read data
}
void I2C_Start()
{
SCL = 0; // Pull SCL low
SDA = 1; // Pull SDA High
delay_us(1);
SCL = 1; //Pull SCL high
delay_us(1);
SDA = 0; //Now Pull SDA LOW, to generate the Start Condition
delay_us(1);
SCL = 0; //Finally Clear the SCL to complete the cycle
}
void I2C_Stop(void)
{
SCL = 0; // Pull SCL low
delay_us(1);
SDA = 0; // Pull SDA low
delay_us(1);
SCL = 1; // Pull SCL High
delay_us(1);
SDA = 1; // Now Pull SDA High, to generate the Stop Condition
}
void I2C_Ack()
{
SDA = 0; //Pull SDA low to indicate Positive ACK
I2C_Clock(); //Generate the Clock
SDA = 1; // Pull SDA back to High(IDLE state)
}
void I2C_NoAck()
{
SDA = 1; //Pull SDA high to indicate Negative/NO ACK
I2C_Clock(); // Generate the Clock
SCL = 1; // Set SCL */
}
void I2C_Write(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++) // loop 8 times to send 1-byte of data
{
SDA = dat & 0x80; // Send Bit by Bit on SDA line
I2C_Clock(); // Generate Clock at SCL
dat = dat<<1;
}
SDA = 1; // Set SDA at last
}
unsigned char I2C_Read(void)
{
unsigned char i, dat=0x00;
SDA=1; //Make SDA as I/P
for(i=0;i<8;i++) // loop 8times to read 1-byte of data
{
delay_us(1);
SCL = 1; // Pull SCL High
delay_us(1);
dat = dat<<1; //dat is Shifted each time and
dat = dat | SDA; //ORed with the received bit to pack into byte
SCL = 0; // Clear SCL to complete the Clock
}
return dat; // Finally return the received Byte*
}
void I2C_Clock(void)
{
delay_us(1);
SCL = 1; // Wait for Some time and Pull the SCL line High
delay_us(1); // Wait for Some time
SCL = 0; // Pull back the SCL line low to Generate a clock pulse
}