This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pointer Variable on LCD

Hi all...
i need to print a value of pointer variable in 16x2 LCD...
for Eg.

void main()
{
int *a = 20;
int b;
*a=&b;
print_LCD(value of pointer variable a)
}


here is a simple example where i have declared a pointer variable 'a' whoes value is 20.
and then i stored the value of pointer variable at the address of variable b.
but i need to print the value of pointer variable on LCD screen.
how can i do this....
can anybody help me please....

Parents
  • Thanks for the help...
    actually i am new to programming and
    i was actually trying to understand what exactly pointer are....
    i need a small help from you...
    here i am trying to understand how can i interface RTC with 89s52...
    here is a part of code...

    unsigned char sec, min, hour, day, month, year,
    
    void DS1307_GetTime(unsigned char *h_ptr,unsigned char *m_ptr,unsigned char *s_ptr)
    {
    I2C_Start(); // Start I2C communication
    DS1307_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
    DS1307_Write(SEC_ADDRESS); // Request Sec RAM address at 00H
    I2C_Stop(); // Stop I2C communication after selecting Sec Register
    I2C_Start(); // Start I2C communication
    DS1307_Write(0xD1); // connect to DS1307( under Read mode) //by sending its ID on I2c Bus
    *s_ptr = DS1307_Read();
    I2C_Ack(); // read second and return Positive ACK
    *m_ptr = DS1307_Read();
    I2C_Ack(); // read minute and return Positive ACK
    *h_ptr = DS1307_Read();
    I2C_NoAck(); // read hour and return Negative/No ACK
    I2C_Stop(); // Stop I2C communication after reading the Time
    }
    
    void DS1307_GetDate(unsigned char *d_ptr,unsigned char *m_ptr,unsigned char *y_ptr)
    {
    I2C_Start(); // Start I2C communication
    DS1307_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
    DS1307_Write(DATE_ADDRESS); // Request DAY RAM address at 04H
    I2C_Stop(); // Stop I2C communication after selecting DAY Register
    I2C_Start(); // Start I2C communication
    DS1307_Write(0xD1); // connect to DS1307( under Read mode) // by sending its ID on I2c Bus
    *d_ptr = DS1307_Read();
    I2C_Ack(); // read Day and return Positive ACK
    *m_ptr = DS1307_Read();
    I2C_Ack(); // read Month and return Positive ACK
    *y_ptr = DS1307_Read();
    I2C_NoAck(); // read Year and return Negative/No ACK
    I2C_Stop(); // Stop I2C communication after reading the Time
    }
    
    void main()
    {
    DS1307_Init();
    DS1307_SetTime(0x10,0x40,0x20);
    DS1307_SetDate(0x12,0x07,0x14);
      while(1)
      {
       DS1307_GetTime(&hour,&min,&sec);
       DS1307_GetDate(&day,&month,&year);
      }
    }
    


    i am not able to understand this part of code...
    with the help of void DS1307_GetTime function i am storing the values like Hours, minutes and seconds in pointer variables (unsigned char *h_ptr,unsigned char *m_ptr,unsigned char *s_ptr) and the same goes for DS1307_GetDate.
    but now when i wrote
    DS1307_GetTime(&hour,&min,&sec);
    DS1307_GetDate(&day,&month,&year);
    in main function...
    i am not able to understand that if this function is storing the value of pointer *h_ptr, *m_ptr..... (which is the actual time)to the address of variable hours, min, sec. or it is storing the value to hours, min, sec.
    or something else..
    can you please explain what is exactly happening...

Reply
  • Thanks for the help...
    actually i am new to programming and
    i was actually trying to understand what exactly pointer are....
    i need a small help from you...
    here i am trying to understand how can i interface RTC with 89s52...
    here is a part of code...

    unsigned char sec, min, hour, day, month, year,
    
    void DS1307_GetTime(unsigned char *h_ptr,unsigned char *m_ptr,unsigned char *s_ptr)
    {
    I2C_Start(); // Start I2C communication
    DS1307_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
    DS1307_Write(SEC_ADDRESS); // Request Sec RAM address at 00H
    I2C_Stop(); // Stop I2C communication after selecting Sec Register
    I2C_Start(); // Start I2C communication
    DS1307_Write(0xD1); // connect to DS1307( under Read mode) //by sending its ID on I2c Bus
    *s_ptr = DS1307_Read();
    I2C_Ack(); // read second and return Positive ACK
    *m_ptr = DS1307_Read();
    I2C_Ack(); // read minute and return Positive ACK
    *h_ptr = DS1307_Read();
    I2C_NoAck(); // read hour and return Negative/No ACK
    I2C_Stop(); // Stop I2C communication after reading the Time
    }
    
    void DS1307_GetDate(unsigned char *d_ptr,unsigned char *m_ptr,unsigned char *y_ptr)
    {
    I2C_Start(); // Start I2C communication
    DS1307_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
    DS1307_Write(DATE_ADDRESS); // Request DAY RAM address at 04H
    I2C_Stop(); // Stop I2C communication after selecting DAY Register
    I2C_Start(); // Start I2C communication
    DS1307_Write(0xD1); // connect to DS1307( under Read mode) // by sending its ID on I2c Bus
    *d_ptr = DS1307_Read();
    I2C_Ack(); // read Day and return Positive ACK
    *m_ptr = DS1307_Read();
    I2C_Ack(); // read Month and return Positive ACK
    *y_ptr = DS1307_Read();
    I2C_NoAck(); // read Year and return Negative/No ACK
    I2C_Stop(); // Stop I2C communication after reading the Time
    }
    
    void main()
    {
    DS1307_Init();
    DS1307_SetTime(0x10,0x40,0x20);
    DS1307_SetDate(0x12,0x07,0x14);
      while(1)
      {
       DS1307_GetTime(&hour,&min,&sec);
       DS1307_GetDate(&day,&month,&year);
      }
    }
    


    i am not able to understand this part of code...
    with the help of void DS1307_GetTime function i am storing the values like Hours, minutes and seconds in pointer variables (unsigned char *h_ptr,unsigned char *m_ptr,unsigned char *s_ptr) and the same goes for DS1307_GetDate.
    but now when i wrote
    DS1307_GetTime(&hour,&min,&sec);
    DS1307_GetDate(&day,&month,&year);
    in main function...
    i am not able to understand that if this function is storing the value of pointer *h_ptr, *m_ptr..... (which is the actual time)to the address of variable hours, min, sec. or it is storing the value to hours, min, sec.
    or something else..
    can you please explain what is exactly happening...

Children