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.

[PIC] Display DS1307 RTC data PIC18F24K40

Status
Not open for further replies.

ajit_nayak87

Member level 5
Joined
Oct 30, 2017
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
981
I have PIC18F24k40 with DS1307 RTC device. here is sample code i have shared here. I am facing actual while displaying parameter.

i am setting value of MIN_SET & SEC_SET =0X40 in decimal . if i use below instruction it properly increment . but in Run mode while displaying ,it display hexadecimal value 0X28
Temp1= sec & 0x0f;Temp2= sec>> 4;
LEDBuffer_1[0] = DISPTABLE[Temp1];
LEDBuffer_1[1] = DISPTABLE[Temp2];
Temp3 = min & 0x0f;Temp4= min >> 4;
LEDBuffer_1[2] = DISPTABLE[Temp3];
LEDBuffer_1[3] = DISPTABLE[Temp4];

If i change below value it will display hexadecimal value after 40. if i set MIN_SET & SEC_SET =0X00 then properly increment. But for MIN_SET & SEC_SET=0X40
min paramter shows 0X40 and sec parameter display for 56 it shows 38
Temp1= sec & 0x0f;Temp2= sec>> 4;
LEDBuffer_1[0] = DISPTABLE[Temp1];
LEDBuffer_1[1] = DISPTABLE[Temp2];
Temp3 = min & 0x0f;Temp4= min >> 4;
LEDBuffer_1[2] = DISPTABLE[Temp3];
LEDBuffer_1[3] = DISPTABLE[Temp4];
what are changes need to made to display actual value. Somewhere i need to convert bcd to decimal and decimal to Bcd conversion

my code is code.txt file
 

Attachments

  • code.txt
    15.5 KB · Views: 71

Hi,

i am setting value of MIN_SET & SEC_SET =0X40 in decimal

I assume you are confusing the value representations.
So either you set
* 0X40 --> which is hex. "0x" means it is a value represented as HEX.
* or you set 40 in decimal (without "0x")
...but you can´t set "0x40" in decimal.

So I assume you set 40 in decimal... this is 0x28 in HEX. There is no difference in the code nor in the stored data.
40 (decimal) = 0x28 (HEX) = 0b00101000 (binary) = "(" (ASCII) . There is no difference in the value, it´s just another representation.
The difference is how "you" see it. or how you tell the print function to display it.

Klaus
 

Here is my code where i could able to change RTC value. I have share part of code. DATE_TIME_SET_ADD function where i am changing the RTC
date and time in programming mode.

when i come out of programming mode means if (pgm_run == 0) if i short (RTC_Write ==1) i.e port pin then only it write.
for value 0 to 30it wont any difference showing but after 30 it display in hex. where i am making wrong here.

how i need to correct. weather i need to convert bcd to decimal or decimal to bcd here.


Code:
signed char Hour_ON1;
signed char Min_ON1;
signed char Hour_OFF1;
signed char MIN_OFF1;
signed char YEAR_SET = 20;
unsigned char MONTH_SET = 1;
unsigned char Day_SET = 1;
unsigned char HOUR_SET = 0;
unsigned char MIN_SET = 0;
unsigned char SEC_SET = 0;
unsigned char WK_DAY_SET = 0;
unsigned char RLY_PATTERN = 0;
unsigned char BLINKFLAG = 0;



void DATE_TIME_SET_ADD() {
    //Setting Date and time
    if ((Rly_No == 10) && (Comb_No == 1)) {
        Day_SET++;
        if (Day_SET > 31) {
            Day_SET = 1;
        }
        LEDBuffer_1[1] = DISPTABLE[Day_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[Day_SET % 10];
    } else if ((Rly_No == 10) && (Comb_No == 2)) {
        MONTH_SET++;
        if (MONTH_SET > 12) {
            MONTH_SET = 1;
        }
        LEDBuffer_1[1] = DISPTABLE[MONTH_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[MONTH_SET % 10];
    } else if ((Rly_No == 10) && (Comb_No == 3)) {
        YEAR_SET++;
        if (YEAR_SET > 99) {
            YEAR_SET = 0;
        }
        LEDBuffer_1[1] = DISPTABLE[YEAR_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[YEAR_SET % 10];
    } else if ((Rly_No == 10) && (Comb_No == 4)) {
        WK_DAY_SET++;
        if (WK_DAY_SET > 60) {
            WK_DAY_SET = 1;
        }
        LEDBuffer_1[1] = DISPTABLE[WK_DAY_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[WK_DAY_SET % 10];
    } else if ((Rly_No == 10) && (Comb_No == 5)) {
        HOUR_SET++;
        if (HOUR_SET > 24) {
            WK_DAY_SET = 0;
        }
        LEDBuffer_1[1] = DISPTABLE[HOUR_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[HOUR_SET % 10];
    } else if ((Rly_No == 10) && (Comb_No == 6)) {
        MIN_SET++;
        if (MIN_SET > 59) {
            MIN_SET = 0;
        }
        LEDBuffer_1[1] = DISPTABLE[MIN_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[MIN_SET % 10];
    } else if ((Rly_No == 10) && (Comb_No == 7)) {
        SEC_SET++;
        if (SEC_SET > 59) {
            SEC_SET = 0;
        }
        LEDBuffer_1[1] = DISPTABLE[SEC_SET / 10];
        LEDBuffer_1[0] = DISPTABLE[SEC_SET % 10];
    }

}
//===========================================================================================
// Display_RTC_Clock
//
//===========================================================================================

void Display_RTC_Clock() {
    unsigned char Index = 0, Temp_Runner = 0, Temp1;
    unsigned char Temp2;
    unsigned char Temp3;
    unsigned char Temp4;

    Temp1 = sec & 0x0f;
    Temp2 = sec >> 4;
    LEDBuffer_1[0] = DISPTABLE[Temp1];
    LEDBuffer_1[1] = DISPTABLE[Temp2];

    Temp3 = min & 0x0f;
    Temp4 = min >> 4;
    LEDBuffer_1[2] = DISPTABLE[Temp3];
    LEDBuffer_1[3] = DISPTABLE[Temp4];

    LEDBuffer_1[0] = DISPTABLE[22]; // display R

}

void main(void) {
    // Initialize the device
    SYSTEM_Initialize();

    I2C1_Initialize();
    I2C1_Write1ByteRegister(0x68, 0x00, 0x30);
    I2C1_Write1ByteRegister(0x68, 0x01, 0x30);
    I2C1_Write1ByteRegister(0x68, 0x02, 0x05);
    I2C1_Write1ByteRegister(0x68, 0x03, 0x01);
    I2C1_Write1ByteRegister(0x68, 0x04, 0x02);
    I2C1_Write1ByteRegister(0x68, 0x05, 0x03);
    I2C1_Write1ByteRegister(0x68, 0x06, 0x10);

    DgtSel = 1;
    GIE = 1;
    while (1) {
        if (pgm_run == 1) {
            __delay_ms(10);
            start = 0;
            if (Pgm_Mode_Entry == 0) {
                Pgm_Mode_Cnng_Over = 0;
                Update_Rly_Power_on(0x00);
                Rly_No = 1;
                Comb_No = 1;
                BLINKSEGMENT = 0;
                SELECTPRESS = 0;
                BLINKFLAG = 0;
                run_Mode_Entry = 0;
                RLY_PATTERN = 0;
                Eprom_reads();
                Pgm_Mode_Entry = 1;
            }
            KeyCheck();

        } else if (pgm_run == 0) {
            
            
            
            if (RTC_Write == 1) {

          I2C1_Write1ByteRegister(0x68, 0x00, SEC_SET);
          I2C1_Write1ByteRegister(0x68, 0x01, MIN_SET);
          I2C1_Write1ByteRegister(0x68, 0x02, HOUR_SET);
          I2C1_Write1ByteRegister(0x68, 0x03, WK_DAY_SET);
          I2C1_Write1ByteRegister(0x68, 0x04, Day_SET);
          I2C1_Write1ByteRegister(0x68, 0x05, MONTH_SET);
          I2C1_Write1ByteRegister(0x68, 0x06, YEAR_SET);

        }
        
        sec = I2C1_Read1ByteRegister(0x68, 0x00);
        min = I2C1_Read1ByteRegister(0x68, 0x01);
        Hour = I2C1_Read1ByteRegister(0x68, 0x02);

        Display_RTC_Clock();

        }

    }
}
 

Hi,

The clock works in BCD mode.
Read about BCD.
Example, minutes:
Hex / decimal value of HEX / time representation
0x00 = 0 = 0 minutes
Up to
0x09 = 9 = 9 minutes
(Not allowed: 0x0A = 10 to 0x0F = 15, because no valid BCD)
0x10 = 17 = 10 minutes
Up to
0x19 = 25 = 19 minutes
(Not allowed: 0x1A = 26 to 0x1F = 31, because no valid BCD)
0x20 = 32 = 20 minutes
Up to
0x29 = 41 = 29 minutes
(Not allowed: 0x2A = 42 to 0x2F = 47, because no valid BCD)
....
You see the decimal values are confusing.
Better human readable is the HEX view. But in each HEX nibble (4bits) only values of 0...9 are allowed. A to F is not allowed.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top