Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] embeded systems & programming

Status
Not open for further replies.

tapu

Full Member level 4
Joined
Sep 15, 2014
Messages
234
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
india
Activity points
3,041
Hi,I am using 89c51 in my board.The programme is loaded in controller.problom is that if i write above 2080bytes of programm then it does not execute in board.and if i write below 2074 bytes then programme partially runs but keypad does not work.please reply.I use keil uvision3 & usb programmer.
 

It seems like a problem with your Programmer's setting because 89c51 has 4096 Bytes of Re-programmable Flash Memory .. You should check you're USB programmer .. it can be a firmware issue ..
 
Last edited by a moderator:
  • Like
Reactions: tapu

    tapu

    Points: 2
    Helpful Answer Positive Rating
Thank you for replying my thread I will check my programmer's setting.
 

Hi,I am using 89c51 in my board.The programme is loaded in controller.problom is that if i write above 2080bytes of programm then it does not execute in board.and if i write below 2074 bytes then programme partially runs but keypad does not work.please reply.I use keil uvision3 & usb programmer.

Greetings,
Unlicensed version of keil only allows you to program upto 2kB of code.. So buy licensed version of keil or use free IDE.

you're <Last edited by bigdogguru; Today at 12:54. Reason: Replaced Improper SMS Style Abbreviations with Proper Complete Words, "ur" with "you're" >
I think it should be your not you're (you are) :p


Good Luck
 

In addition to that If I write 2070 to 2074 bytes then controller takes too time to starts running.and keypad does not works.if it is a problom of unlicensed keil then it should not run on proteus simulation.while it runs on proteus successfully.
 

will unlicensed keil allow to compile more than 2kb, Is it the limitation is only for simulation?
when programming 2080 bytes what is the starting address on the target ? ensure the hex code not crossing your 4096 bytes..
 
In addition to that If I write 2070 to 2074 bytes then controller takes too time to starts running.and keypad does not works.if it is a problom of unlicensed keil then it should not run on proteus simulation.while it runs on proteus successfully.

You are not using any interrupts right?
 

I am using 6 switches in circuit for setting time and alarms and code according to switch. My PC has virus and shows errors. Does virus reacts my programmer or programmer software or compiler? Can it be a pc problem?
 
Last edited by a moderator:

I am using 6 switches in circuit for setting time and alarms and code according to switch. My PC has virus and shows errors. Does virus reacts my programmer or programmer software or compiler? Can it be a pc problem?

First answer these:
1) is your keil licensed?
2) Are you using interrupts in your program?
3) Did you tried programming your code below 2KB?
 

I am using unlicensed keil & there is no inturrupts in my programme.as I write below 2kb(1723 bytes) & place chip on board then Lcd(16x2) shows initial message according to mentioned on programme. but keypad does not work and time and date not displayed.
 

post your program here !
 
  • Like
Reactions: tapu

    tapu

    Points: 2
    Helpful Answer Positive Rating
here is a program.

Code:
#include<reg51.h>


sbit set=P1^0;
sbit mov=P1^1;
sbit inc=P1^2;
sbit dec=P1^3;
sbit ent=P1^4;
sbit alarmset=P3^7;
sbit e5=P1^5;//3rd e5
sbit e6=P2^3;//4th    e6
sbit e4=P1^7;//1st e4
sbit e3=P1^6;//2nd e3
sbit Lcd_rs = P2^0;
sbit Lcd_rw = P2^1;
sbit Lcd_en = P2^2;
sbit sda_rtc =P2^5;
sbit scl_rtc =P2^4;
sbit SDA=P2^6;
sbit SCL=P2^7;

#define DS1307_ID 0xD0
#define SEC 0x00
#define MIN 0x01
#define HOUR 0x02
#define DATE 0x04
#define MONTH 0x05
#define YEAR 0x06

#define First_Line 0x80
#define Second_Line 0xc0
#define Curser_On 0x0f
#define Curser_Off 0x0c
#define Clear_Display 0x01
#define Data_Port P0
#define EEPROM_ID 0xa0


void all_disp();
void alarm_set1();
void alarm_set2();
void time_set();
void Lcd8_Init();
void Lcd8_Command(unsigned char);
void Lcd8_Write(unsigned char,unsigned char);
void Lcd8_Display(unsigned char,const unsigned char*,unsigned int);
void Lcd8_Decimal2(unsigned char,unsigned char);
void Delay(unsigned int);
void del();

void Seg8_decimal2(min);

void Led8decimal2(hour);
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 delay_ms(unsigned int ms_count);
void I2C_NoAck();
void I2C_Clock();
void delay_us(unsigned int us_count);
void msdelay(unsigned int value);

DS1307_get(unsigned char);
void DS1307_settime(unsigned char, unsigned char, unsigned char);
void DS1307_setdate(unsigned char, unsigned char, unsigned char);
Send2lcd(unsigned char);
void Rtc_Write(unsigned char,unsigned char);
Rtc_Read(unsigned char);
void Rtc_rd_wr_sub();
void Rtc_Init();
void Rtc_Start();
void Rtc_Tx();
void Rtc_Rx();
void Rtc_Stop();
void Rtc_Ack();

unsigned int Rtc_add_wr,Rtc_add_rd;
unsigned char d_rtc,datain_rtc,in_rtc,temp_rtc,dat_rtc,flag_rtc;

unsigned char i,j,a[10],cur=0;
unsigned char sec,hour,min,date,month,year,sec1,hour1,min1,sec2, hour2,min2,hh,mm,ss,dd,mn,yy,ahour,amin,asec,amin1,ahour1;
 unsigned char count[4]={0x86,0x89};

unsigned char dec_hex(unsigned char tt)
{
if(tt>59)
tt+=36;
else if(tt>49)
tt+=30;
else if(tt>39)
tt+=24;
else if(tt>29)
tt+=18;
else if(tt>19)
tt+=12;
else if(tt>9)
tt+=6;
return(tt);
} 

void all_disp()
{
sec = DS1307_get(SEC);
min = DS1307_get(MIN);
hour = DS1307_get(HOUR);
date = DS1307_get(DATE);
month = DS1307_get(MONTH);
year = DS1307_get(YEAR);

min=Send2lcd(min);

hour=Send2lcd(hour);
 Seg8_decimal2(min);
 Led8decimal2(hour);


}
void main()
{
Lcd8_Init();
Lcd8_Display(0x80,"RTC TESTING: ",12);
Delay(65000);
Delay(65000);
Lcd8_Command(0x01);
Lcd8_Display(First_Line,"alarm can set:",14);
Rtc_Init();

//DS1307_setdate(0x04,0x11,0x11);
//DS1307_settime(0x16,0x00,0x00);

while(1)
{
 ahour=EEPROM_ReadByte(0x01);
 amin= EEPROM_ReadByte(0x02);
 asec=0;
  ahour1=EEPROM_ReadByte(0x04);
 amin1= EEPROM_ReadByte(0x05);


all_disp();
if(!set)
time_set();
 if(alarmset==1)
{
alarm_set1();
alarm_set2();
}
}
}
void time_set()
{
all_disp();
cur=0;
while(ent)
{
if(mov==0)
{
while(!mov);
cur++;
if(cur==2)
cur=0;
}


else if(count[cur]==0x86)
{
if(inc==0)
{
while(inc==0);
hour++;
Led8decimal2(hour);

if(hour>=24)
hour=0;
}
}

else if(count[cur]==0x89)
{
if(inc==0)
{
while(inc==0);
min++;
Seg8_decimal2(min);

if(min>=60)
min=0;
}
}

}



hh=dec_hex(hour);
mm=dec_hex(min);

DS1307_settime(hh,mm,ss);
DS1307_setdate(dd,mn,yy); 
}










void alarm_set1()
{

 Lcd8_Command(0x01);
 Lcd8_Display(0x84,"alarm1 can:",10);
 Lcd8_Display(0xc6,"set now:",7);

 Delay(65000);
 
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"alrm1:",7);


 Lcd8_Decimal2(0x86,ahour);
 Lcd8_Decimal2(0x89,amin);


cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==2)
cur=0;
}
else if(count[cur]==0x86)
{
if(inc==0)
{
while(inc==0);
ahour++;
if(ahour>=24)
ahour=0;
Lcd8_Decimal2(count[cur],ahour);
}
}

else if(count[cur]==0x89)
{
if(inc==0)
{
while(inc==0);
amin++;
if(amin>=60)
amin=0;
Lcd8_Decimal2(count[cur],amin);
}
}


}
Lcd8_Command(0x0c);
Delay(65000);Delay(65000);

 EEPROM_WriteByte(0x01, ahour);
 EEPROM_WriteByte(0x02, amin);


Lcd8_Command(0x01);

}
void alarm_set2()
{

{

 Lcd8_Command(0x01);
 Lcd8_Display(0x84,"alarm2 can:",10);
 Lcd8_Display(0xc6,"set now:",7);

 Delay(65000);
 
  Lcd8_Command(0x01);
  Lcd8_Display(0x80,"alrm2:",7);


 Lcd8_Decimal2(0x86,ahour1);
 Lcd8_Decimal2(0x89,amin1);


cur=0;

while(ent)
{
Lcd8_Command(0x0f);
Lcd8_Command(count[cur]);
if(mov==0)
{
while(!mov);
cur++;
if(cur==2)
cur=0;
}
else if(count[cur]==0x86)
{
if(inc==0)
{
while(inc==0);
ahour++;
if(ahour>=24)
ahour=0;
Lcd8_Decimal2(count[cur],ahour1);
}
}

else if(count[cur]==0x89)
{
if(inc==0)
{
while(inc==0);
amin++;
if(amin>=60)
amin=0;
Lcd8_Decimal2(count[cur],amin1);
}
}


}
Lcd8_Command(0x0c);
Delay(65000);Delay(65000);

 EEPROM_WriteByte(0x01, ahour);
 EEPROM_WriteByte(0x02, amin);


Lcd8_Command(0x01);
Lcd8_Display(0x84,"NOW",3);
Lcd8_Display(0xc4,"READY",5);
Delay(65000);
}



}





void Lcd8_Init()
{
Lcd8_Command(0x38); //to select function set
Lcd8_Command(0x06); //entry mode set
Lcd8_Command(0x0c); //display on
Lcd8_Command(0x01); //clear display
}

void Lcd8_Command(unsigned char com)
{
Data_Port=com;
Lcd_en=1;
Lcd_rs=Lcd_rw=0;
Delay(125);
Lcd_en=0;
Delay(125);
}

void Lcd8_Write(unsigned char com,unsigned char lr)
{
Lcd8_Command(com);
Data_Port=lr; // Data 
Lcd_en=Lcd_rs=1;
Lcd_rw=0;
Delay(125);
Lcd_en=0;
Delay(125);
}

void Lcd8_Display(unsigned char com,const unsigned char *word,unsigned int n)
{
unsigned char Lcd_i;
for(Lcd_i=0;Lcd_i<n;Lcd_i++)
{ 
Lcd8_Write(com+Lcd_i,word[Lcd_i]);
}
}

void Lcd8_Decimal2(unsigned char com,unsigned char val)
{
unsigned int Lcd_hr,Lcd_t,Lcd_o;

Lcd_hr=val%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;

Lcd8_Write(com,Lcd_t+0x30);
Lcd8_Write(com+1,Lcd_o+0x30);
}



void Delay(unsigned int del)
{
while(del--);
}

void del()
{
Delay(65000);
Delay(65000);

}


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;
e5=0;
P3=Lcd_t+0x30;
e5=1;
e6=0;
P3=Lcd_o+0x30;
e6=1;

}







void Led8decimal2(hour)
{
unsigned int Lcd_hr,Lcd_t,Lcd_o;

Lcd_hr=hour%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
e4=0;
P3=Lcd_t+0x30;
e4=1;
e3=0;
P3=Lcd_o+0x30;
e3=1;
}


/*********************************LCD HEADER FILE END*************************************/



/*********************************RTC HEADER FILE START*********************************/


DS1307_get(unsigned char addr)
{
unsigned char ret;

Rtc_Start(); 
ret = Rtc_Read(addr);
Rtc_Stop();

return ret;
}

void DS1307_settime(unsigned char hh, unsigned char mm, unsigned char ss)
{
Rtc_Start(); 

Rtc_Write(0x00,ss); /* Write sec on RAM address 00H */
Rtc_Write(0x01,mm); /* Write min on RAM address 01H */
Rtc_Write(0x02,hh); /* Write hour on RAM address 02H */

Rtc_Stop(); /* Stop i2c bus */
}


void DS1307_setdate(unsigned char dd, unsigned char mm, unsigned char yy)
{
Rtc_Start();

Rtc_Write(0x04,dd); /* Write date on RAM address 04H */
Rtc_Write(0x05,mm); /* Write month on RAM address 05H */
Rtc_Write(0x06,yy); /* Write year on RAM address 06H */

Rtc_Stop(); /* Stop i2c bus */
}


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 Rtc_Init()//lower order 256 bytes of the chip
{
Rtc_add_wr=0xd0;
Rtc_add_rd=0xd1;
}


void Rtc_Write(unsigned char zig,unsigned char zag)// program to write to EEPROM
{
dat_rtc=zig;
temp_rtc=zag;
Rtc_rd_wr_sub();
above:
d_rtc=temp_rtc;
Rtc_Tx();
if (CY==1)goto above;
CY=0;
Rtc_Stop();
}


Rtc_Read(unsigned char zig)// program to read from EEPROM
{
dat_rtc=zig;
Rtc_rd_wr_sub();
Rtc_Start();
be:
d_rtc=Rtc_add_rd; // 0xd1 =Rtc_add_rd
Rtc_Tx();
if(CY==1)goto be;
Rtc_Rx();
Rtc_Ack();
CY=0;
Rtc_Stop();
return(datain_rtc);
}


void Rtc_Start()// must for any operation on EEPROM
{
sda_rtc=1;
scl_rtc=1;
sda_rtc=0;
scl_rtc=0;
}


void Rtc_Stop()// this is similar to the START operation whereas this should be performed after the completion of any operation
{
sda_rtc=0;
scl_rtc=1;
sda_rtc=1;
}


void Rtc_Tx()// program to send the device address, read/write address,data to be written
{
signed char i_rtc;
for(i_rtc=7;i_rtc>=0;i_rtc--)// should necessarily be initialised as signed char.
{
CY=(d_rtc>>i_rtc)&0x01;
sda_rtc=CY;
scl_rtc=1;// clock is essential inorder to write or read
scl_rtc=0;// clk should be alternated
}
sda_rtc=1;
scl_rtc=1;
CY=sda_rtc;
scl_rtc=0;
}


void Rtc_Rx()// program read the data from the EEPROM
{
unsigned char l_rtc;
sda_rtc=1;
for (l_rtc=0;l_rtc<=7;l_rtc++)
{
scl_rtc=1;
in_rtc=in_rtc<<1;
in_rtc|=sda_rtc;
scl_rtc=0;
}
datain_rtc=in_rtc;
in_rtc=0;
}


void Rtc_Ack()// this is to intimate the EEPROM that the read operation is over
{
sda_rtc=1;
scl_rtc=1;
scl_rtc=0;
}


void Rtc_rd_wr_sub()// this routine will be used by both the read & write operations to send the device address & the address at which the corresponding action is to be taken
{
Rtc_Start();
here1:
d_rtc=Rtc_add_wr;// 0xd0 device address is passed
Rtc_Tx();
if(CY==1)goto here1;
again1:
d_rtc=dat_rtc;// the address from which data is to be read/written is to be passed
Rtc_Tx();
if(CY==1)goto again1;
}

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(1);            // 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 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 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
}
 
Last edited by a moderator:

Hello sir Thank you for reply your file Tapu.hex is working fine.what was a Error?is their a keil setting or code?
 

Hello sir Thank you for reply your file Tapu.hex is working fine.what was a Error?is their a keil setting or code?

See, I already told you in my first post to use Licensed version of keil. The problem was with your unlicensed keil, it supports program code limit of 2KB only.

Good Luck :)
 
  • Like
Reactions: tapu

    tapu

    Points: 2
    Helpful Answer Positive Rating
Hi,
Thank you for replies.Now I will use licensed version.Can I use eclipse IDE ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top