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] urgent help needed with mikroc Code arrays

Status
Not open for further replies.

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
Hi,

I have a project in which I want to display numbers on LCD
I convert the numbers from int to string and then display them on LCD
but I want to compare this number with another two digits number which is stored in array
the problem is that each time I display the two digits number on LCD it leaves 4 to 5 blanks before the number is displayed
it's like the number is moved or not stored on [0] location
I don't know what to do

this code
Code:
if(PORTA.F1==0)
         {


             WordToStr(counter_Hours, counter_Hours_string);

             if(counter_Hours>=12)
             {
                counter_Hours = 0 ;

             }
           if(h[0]==houry[0] && h[1] == houry[1] )
          {
            portd=0xFF;
            delay_ms(1000);
            portd=0x00;
            delay_ms(1000);
          } 
                     h[0] = counter_Hours_string[0];
                  h[1] = counter_Hours_string[1];

                 Lcd_out(1,1,h);

                o=0;
                for(n=0;n<7;n++){
                
                if(h[n]!=' ')
                {
                    h[o]= h[n];
                    o++;
                }
                }

the purpose of this code is that each time I press a button it will increase the hour which is a two digit number
and display it on LCD
at the bottom of the code I tried to clear it from spaces and display it a gain
I faced a lot of problems dealing with arrays and integers when LCD is involved so the question is how long an array should be to transfer a two digit integer to it and should I define it as integer or as long

I feel like lost the point but any explanation on how to convert int to string without getting spaces and without using atoi function would be appreciated

- - - Updated - - -

The main request is a method that I can use to convert integer to string even if the array of strings has spaces before or after the number
not a predefined method as atoi since non of them works for me

- - - Updated - - -

The main request is a method that I can use to convert integer to string even if the array of strings has spaces before or after the number
not a predefined method as atoi since non of them works for me

- - - Updated - - -

The main request is a method that I can use to convert integer to string even if the array of strings has spaces before or after the number
not a predefined method as atoi since non of them works for me
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Debug and see if IntToStr() inserts blank spaces in the beginning of array.

After you use IntToStr(intVal, strVal)

See if this code solves your problem


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
j = 0;
 
while(strVal[i]) {
 
    while(strVal[i] == ' ')i++; 
    
    strVal[j++] = strval[i++];
    
}
 
strVal[j] = '\0';
 
LCD_Out(1,1,strVal);

 

zuisti

Advanced Member level 1
Joined
Jul 2, 2004
Messages
480
Helped
188
Reputation
376
Reaction score
184
Trophy points
1,323
Location
Hungary
Activity points
3,311
Hi kobre98;

From the help, about the WordToStr:
Converts input word to a string. The output string has fixed width of 6 characters including null character at the end (string termination). The output string is right justified and the remaining positions on the left (if any) are filled with blanks.

If you have a 2-digit decimal number then simply print out the string from its fourth position. The possible leading space is also can be changed to '0' if you want:
Code:
WordToStr(counter_Hours, counter_Hours_string);
if (counter_Hours_string[3] == 32)
    counter_Hours_string[3] = '0';
....
Lcd_out(1,1,counter_Hours_string + 3);
But the ByteToStr is also enough in this case (3-char string, printed from its second position (string +1).
 
Last edited:

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
when I insert intToStr the whole code isn't working, the LCD flashes with data and nothing appears on it, when I remove it, everything go backs to normal

- - - Updated - - -

Debug and see if IntToStr() inserts blank spaces in the beginning of array.

After you use IntToStr(intVal, strVal)

See if this code solves your problem


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
j = 0;
 
while(strVal[i]) {
 
    while(strVal[i] == ' ')i++; 
    
    strVal[j++] = strval[i++];
    
}
 
strVal[j] = '\0';
 
LCD_Out(1,1,strVal);


when I insert intToStr the whole code isn't working, the LCD flashes with data and nothing appears on it, when I remove it, everything go backs to normal

- - - Updated - - -

Hi kobre98;

From the help, about the WordToStr:
Converts input word to a string. The output string has fixed width of 6 characters including null character at the end (string termination). The output string is right justified and the remaining positions on the left (if any) are filled with blanks.

If you have a 2-digit decimal number then simply print out the string from its fourth position. The possible leading space is also can be changed to '0' if you want:
Code:
WordToStr(counter_Hours, counter_Hours_string);
if (counter_Hours_string[3] == 32)
    counter_Hours_string[3] = '0';
....
Lcd_out(1,1,counter_Hours_string + 3);
But the ByteToStr is also enough in this case (3-char string, printed from its second position (string +1).

how can I print an array from it's fourth position to the end !? one char at a time ?! or is there another way ?!

thanks for replying

- - - Updated - - -

by the way when I use intToStr everything works correctly except that the screen keeps flashing like if there is something wrong in the code,
BTW it's a clock using ds1307 code

- - - Updated - - -

I also need to convert an array of strings to integer to compare it with another integer
any help with that ?!
 
Last edited:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Zip and post your complete mikroC project files. If you do like this you will get flickering display...


Code C - [expand]
1
2
LCD_Out(1,1,"EDA BOARD");
LCD_Out(1,6,"FLICKERING");

 

zuisti

Advanced Member level 1
Joined
Jul 2, 2004
Messages
480
Helped
188
Reputation
376
Reaction score
184
Trophy points
1,323
Location
Hungary
Activity points
3,311
how can I print an array from it's fourth position to the end !?
As I wrote above:

Lcd_out(1,1,counter_Hours_string + 3);
 

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
Zip and post your complete mikroC project files. If you do like this you will get flickering display...


Code C - [expand]
1
2
LCD_Out(1,1,"EDA BOARD");
LCD_Out(1,6,"FLICKERING");


the code and the circuit are attached
the four buttons on the left are used to add alarm time or edit clock
the first one is used to enter alarm mode
and the third and fourth are used to edit hours or minutes
I want to compare the alarm time with the clock time and light the led when they are equal

- - - Updated - - -

As I wrote above:

Lcd_out(1,1,counter_Hours_string + 3);

thanks
but do you know how I can convert back a string to integer without using MikroC predefined methods !?
 

Attachments

  • code.rar
    79.3 KB · Views: 14

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
but do you know how I can convert back a string to integer without using MikroC predefined methods !?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
unsigned char i = 0;
char myString[] = "1234567890";
unsigned int intval = 0;
 
 
while(myString[i]) {
 
    intval = (intVal * 10) + myString[i] - 0x30;
    ++i;
}




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
unsigned char i = 0;
char myString[] = "1234567890";
unsigned int intval = 0;
 
 
while(myString[i]) {
 
    intval = (intVal * 10) + myString[i] - 0x30;
    ++i;
}
 
 
unsigned char i = 0, j = 1, dpFlag = 0;
char myString[] = "1234.567890";
double fltVal = 0;
 
 
while(myString[i]) {
 
    if(((myString[i] >= '0') && (myString[i] <= '9')) && (!dpFlag)) {
 
        fltVal = (fltVal * 10.0) + myString[i] - 0x30;
    }
    else if(((myString[i] >= '0') && (myString[i] <= '9')) && (dpFlag)) {
 
        fltVal = fltVal + (myString[i] - 0x30) / (j * 10);
        j *= 10;
    }
    else if(myString[i] == '.') dpFlag = 1;
 
    ++i;
}

 
Last edited:

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
did you see the code and proteous simulation ?!
it's a clock and alarm using ds1307

- - - Updated - - -

the last thing that I can up with is showing the hour from real time and the hour from the alarm set
but I faced another problem
the hour from ds1307 shows the time in this format 01
while the hour from alarm set show it as 1
how can I compare these two values or get ride of the zero
 

zuisti

Advanced Member level 1
Joined
Jul 2, 2004
Messages
480
Helped
188
Reputation
376
Reaction score
184
Trophy points
1,323
Location
Hungary
Activity points
3,311
Or:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char Str2dec (char* ptr) {
   //restricted to max 255 decimal ("255")
   char dig, res;
   for ( res = 0 ; dig = *ptr ; ++ptr) {
       if (dig == 32 && res == 0)
          continue;
       if (dig >= '0' && dig <= '9') {//isdigit
          res *= 10;
          res += dig - '0';
       }
       else
          break;
   }
   return res;
}



Edit:
As you see above (line 5 and 6), leading spaces are also allowed.
For example:
Str2dec(" 2"); // return 2
 
Last edited:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Or:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
unsigned char i = 0, j = 1, dpFlag = 0;
char myString[] = "1234.567890";
double fltVal = 0;
 
 
while(myString[i]) {
 
    if((myString[i] >= '0') && (myString[i] <= '9')) {
 
    switch(dpFlag) {
 
        case 0:
            fltVal = (fltVal * 10.0) + myString[i] - 0x30;
            break;
        case 1:
            fltVal = fltVal + (myString[i] - 0x30) / (j * 10);
            j *= 10;
            break;
    }   
 
        
    }
    else if(myString[i] == '.') dpFlag = 1;
 
    ++i;
}

 

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
I did all the conversion that is needed but each time I try to run the simulation the LCD blinks
when I remove the switch case part from the code it's working a gain and displaying everything correctly
but when I return it back the blinking is back
and I couldn't see whats wrong
the code and simulation are attached
 

Attachments

  • s254 - Copy.rar
    83.5 KB · Views: 22

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
48,365
Helped
14,245
Reputation
28,751
Reaction score
12,931
Trophy points
1,393
Location
Bochum, Germany
Activity points
279,954
Code compilation has been cut after line 550 as you can see from the list file. Is it compiled by a limited demo version?
 

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
no I used a full version and it compiled correctly and entirely
but the blinking problem remains
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
48,365
Helped
14,245
Reputation
28,751
Reaction score
12,931
Trophy points
1,393
Location
Bochum, Germany
Activity points
279,954
no I used a full version and it compiled correctly and entirely
but the blinking problem remains
The posted code is broken, review the listing and hex file. The processor resets before time and date strings are printed to LCD.
 

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
what could cause such thing ?! after compiling it says that Compile finished without errors !

- - - Updated - - -

0 1 mikroCPIC1618.exe -MSF -DBG -pP16F877A -DL -O11111114 -fo8 -N"F:\s254 - Copy\dc.mcppi" -"__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM.mcl" "__Lib_FLASH_RW.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_RS485.mcl" "__Lib_S1D13700.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl" "__Lib_EthEnc24j600.mcl" "__Lib_TouchPanel.mcl"
0 1139 Available RAM: 352 [bytes], Available ROM: 8192 [bytes]
30 1354 warning: "/*" within comment F:\s254 - Copy\dc.c
0 126 All files Preprocessed in 187 ms
30 1354 warning: "/*" within comment F:\s254 - Copy\dc.c
0 122 Compilation Started dc.c
577 123 Compiled Successfully dc.c
58 1164 Variable 't2' has been eliminated by optimizer dc.c
73 1164 Variable 't' has been eliminated by optimizer dc.c
0 127 All files Compiled in 281 ms
0 1144 Used RAM (bytes): 143 (41%) Free RAM (bytes): 209 (59%) Used RAM (bytes): 143 (41%) Free RAM (bytes): 209 (59%)
0 1144 Used ROM (program words): 2220 (27%) Free ROM (program words): 5972 (73%) Used ROM (program words): 2220 (27%) Free ROM (program words): 5972 (73%)
0 125 Project Linked Successfully dc.mcppi
0 128 Linked in 967 ms
0 129 Project 'dc.mcppi' completed: 1669 ms
0 103 Finished successfully: 27 ÃÈÑíá 2014, 08:35:21 dc.mcppi
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
48,365
Helped
14,245
Reputation
28,751
Reaction score
12,931
Trophy points
1,393
Location
Bochum, Germany
Activity points
279,954
I already noticed that dc.log doesn't show any errors. I don't know why the compiler output is broken after line 550.

I can only guess that's a problem of your compiler installation. But I'm not using mikroC and can't further look into the problem.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
FvM is right. The problem is with generated .hex file. I have compiled your project at post #12. There is a difference in the .hex files generated. Try my .hex file and reply. Re-install your compiler and try.

Add


Code C - [expand]
1
2
TRISB = 0x00;
PORTB = 0x00;



You have made RB0 as input. I don't know why. There is no switch connected to it. There is a lot of commented code and also the code is not properly indented. Remove all unwanted code and indent the code properly and post the new project files. Also make any changes needed in Proteus file. There are 2 or 3 switch() statements and I don't know which one you are talking about.
 

Attachments

  • s254.rar
    96.8 KB · Views: 11
Last edited:

kobre98

Full Member level 2
Joined
Sep 18, 2011
Messages
145
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Gaza, Palestine
Activity points
2,523
I tried the two hex files the one named dc.hex is working but the dc_old isn't
what is the difference ?!?!
how could this problem happens even it says that it compiles correctly
what version of mikroc do you use ?! and is it full version ?

- - - Updated - - -

this is the full code without any unneeded comments, I also edit the trisb thing, but when I try to compile it I get ROM problem !
7 342 There is not enough ROM space __Lib_Delays.c
Code:
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;




unsigned short read_ds1307(unsigned short address)
{
  unsigned short r_data;
  I2C1_Start();
  I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
  I2C1_Wr(address);
  I2C1_Repeated_Start();
  I2C1_Wr(0xD1); //0x68 followed by 1 --> 0xD1
  r_data=I2C1_Rd(0);
  I2C1_Stop();
  return(r_data);
}


void write_ds1307(unsigned short address,unsigned short w_data)
{
  I2C1_Start(); // issue I2C start signal
  //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
  I2C1_Wr(0xD0); // send byte via I2C (device address + W)
  I2C1_Wr(address); // send byte (address of DS1307 location)
  I2C1_Wr(w_data); // send data (data to be written)
  I2C1_Stop(); // issue I2C stop signal
}


unsigned char BCD2UpperCh(unsigned char bcd)
{
  return ((bcd >> 4) + '0');
}


unsigned char BCD2LowerCh(unsigned char bcd)
{
  return ((bcd & 0x0F) + '0');
}


int Binary2BCD(int a)
{
   int t1, t2;
   t1 = a%10;
   t1 = t1 & 0x0F;
   a = a/10;
   t2 = a%10;
   t2 = 0x0F & t2;
   t2 = t2 << 4;
   t2 = 0xF0 & t2;
   t1 = t1 | t2;
   return t1;
}


int BCD2Binary(int a)
{
   int r,t;
   t = a & 0x0F;
   r = t;
   a = 0xF0 & a;
   t = a >> 4;
   t = 0x0F & t;
   r = t*10 + r;
   return r;
}



int second;
int minute;
int hour;
int hr;
int day;
int dday;
int month;
int year;
int ap;

////////////////new edit
int flag1=0;
int x,y;
char txt[4];
char houry[2];
char Minutey[2];
unsigned char myString[10];
int t;
int o1=0;
int n1=0;
int o2=0;
int n2=0;
char h7[7];
int counter_Hours;
int counter_Minutes;
char counter_string[7];
char counter_Hours_string[6];
char counter_Minutes_string [6];
char hour_temp [7];
char h[2] ;
 char m[2] ;
 int minute1;
 int hour1;
 char minute2[7];
 char hour2[7];
 char minute3[7];
 char hour3[7];
 int counterhourtemp=0;
 int n,o;
////////////////new edit
 
unsigned short set_count = 0;
short set;

char time[] = "00:00:00 PM";
char date[] = "00-00-00";

void main()
{
   I2C1_Init(100000); //DS1307 I2C is running at 100KHz

   CMCON = 0x07;   // To turn off comparators
   ADCON1 = 0x06;  // To turn off analog to digital converters

   TRISA = 0x07;
   PORTA = 0x00;

   ///////////new edit

   TRISA = 0xFF;
   TRISD = 0x00;
   PORTA = 0x00;
   PORTD = 0x00;

  flag1=0;

   TRISB = 0x00;
    PORTB = 0x00;
   PORTB.RB0 = 0;          // All PORTB pins are cleared
   INTCON.GIE = 1;       //enables unmasked interrupts.
   INTCON.INTE = 1;      //Enables the INT external interrupt

   PortA.RA0 = 1; //initialize portA, pin 0
   TRISA.RA0 = 0; //make portA Pin0 as output
   TRISA.RA3 = 1;

   ///////////new edit
   Lcd_Init();                        // Initialize LCD
   Lcd_Cmd(_LCD_CLEAR);               // Clear display
   Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
   Lcd_out(1,1,"Time:");
   Lcd_out(2,1,"Date:");
   
   do
   {  flag1=0;
     set = 0;
      if(PORTd.F0 == 0)
     {
     if(PORTA.F0 == 0)
     {
         Delay_ms(100);
         if(PORTA.F0 == 0)
         {
             set_count++;
             if(set_count >= 7)
             {
                set_count = 0;
             }
         }
     }
     
     
     if(set_count)
     {
        if(PORTA.F1 == 0)
        {
          Delay_ms(100);
          if(PORTA.F1 == 0)
              set = 1;
        }
        
        if(PORTA.F2 == 0)
        {
          Delay_ms(100);
          if(PORTA.F2 == 0)
              set = -1;
        }
        if(set_count && set)
        {

          switch(set_count)
          {  


            case 1:
                    hour = BCD2Binary(hour);
                    hour = hour + set;
                    hour = Binary2BCD(hour);
                    if((hour & 0x1F) >= 0x12)
                    {
                      hour = hour & 0b11100001;
                      hour = hour ^ 0x20;
                    }
                    else if((hour & 0x1F) <= 0x00)
                    {
                      hour = hour | 0b00010010;
                      hour = hour ^ 0x20;
                    }
                    write_ds1307(2, hour); //write hour
                    break;
            case 2:
                     minute = BCD2Binary(minute);
                     minute = minute + set;
                     if(minute >= 60)
                        minute = 0;
                     if(minute < 0)
                        minute = 59;
                     minute = Binary2BCD(minute);
                     write_ds1307(1, minute); //write min
                     break;
            case 3:
                   if(abs(set))
                      write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator
                   break;
            case 4:
                     day = BCD2Binary(day);
                     day = day + set;
                    day = Binary2BCD(day);
                     if(day >= 0x32)
                        day = 1;
                     if(day <= 0)
                        day = 0x31;
                     write_ds1307(4, day); // write date 17
                     break;
            case 5:
                   month = BCD2Binary(month);
                      month = month + set;
                    month = Binary2BCD(month);

                    if(month > 0x12)
                      month = 1;
                    if(month <= 0)
                      month = 0x12;
                    write_ds1307(5,month); // write month 6 June
                    break;
            case 6:
                    year = BCD2Binary(year);
                    year = year + set;
                    year = Binary2BCD(year);
                    if(year <= -1)
                       year = 0x99;
                    if(year >= 0x50)
                       year = 0;
                    write_ds1307(6, year); // write year
                    break;
          }
        }
     }
      }

      if(PORTd.F0 == 0)
     {
     if(PORTA.F0 == 0)
     {
         Delay_ms(100);
         if(PORTA.F0 == 0)
         {
             set_count++;
             if(set_count >= 7)
             {
                set_count = 0;
             }
         }
     }
     if(set_count)
     {
        if(PORTA.F1 == 0)
        {
          Delay_ms(100);
          if(PORTA.F1 == 0)
              set = 1;
        }

        if(PORTA.F2 == 0)
        {
          Delay_ms(100);
          if(PORTA.F2 == 0)
              set = -1;
        }
        if(set_count && set)
        {
          switch(set_count)
          {
            case 1:
                    hour = BCD2Binary(hour);
                    hour = hour + set;
                    hour = Binary2BCD(hour);
                    if((hour & 0x1F) >= 0x12)
                    {
                      hour = hour & 0b11100001;
                      hour = hour ^ 0x20;
                    }
                    else if((hour & 0x1F) <= 0x00)
                    {
                      hour = hour | 0b00010010;
                      hour = hour ^ 0x20;
                    }
                    write_ds1307(2, hour); //write hour
                    break;
            case 2:
                     minute = BCD2Binary(minute);
                     minute = minute + set;
                     if(minute >= 60)
                        minute = 0;
                     if(minute < 0)
                        minute = 59;
                     minute = Binary2BCD(minute);
                     write_ds1307(1, minute); //write min
                     break;
            case 3:
                    if(abs(set))
                      write_ds1307(0,0x00); //Reset second to 0 sec. and start Oscillator
                    break;
            case 4:
                     day = BCD2Binary(day);
                     day = day + set;
                     day = Binary2BCD(day);
                     if(day >= 0x32)
                        day = 1;
                     if(day <= 0)
                        day = 0x31;
                     write_ds1307(4, day); // write date 17
                     break;
            case 5:
                    month = BCD2Binary(month);
                    month = month + set;
                    month = Binary2BCD(month);
                    if(month > 0x12)
                      month = 1;
                    if(month <= 0)
                      month = 0x12;
                    write_ds1307(5,month); // write month 6 June
                    break;
            case 6:
                    year = BCD2Binary(year);
                    year = year + set;
                    year = Binary2BCD(year);
                    if(year <= -1)
                       year = 0x99;
                    if(year >= 0x50)
                       year = 0;
                    write_ds1307(6, year); // write year
                    break;
          }
        }
     }
      }

      /////////// new edit
               if(PORTA.F3 == 0)
         {
          Lcd_Cmd(_LCD_CLEAR);               // Clear display
         Lcd_out(1,1,"Hours :");

         delay_ms(200);
         //Lcd_Cmd(_LCD_CLEAR);
         while(flag1!=1){
         if(PORTA.F1==0)
         {



             intToStr(counterhourtemp, counter_Hours_string);

                o=0;
                for(n=0;n<7;n++){

                if(counter_Hours_string[n]!=' ')
                {
                    h[o]= counter_Hours_string[n];
                    o++;

                }
                }
                 if(counterhourtemp>=24)
             {
                Lcd_Cmd(_LCD_CLEAR);
                counterhourtemp = 0 ;
             }

             Lcd_out(1,8,h);
           delay_ms(200);
            EEPROM_Write(0x00, counterhourtemp);
             counterhourtemp++;
         }

         if(PORTA.F2==0)
         {
           Lcd_out(2,1,"Minutes :");
             intToStr(counter_Minutes, counter_Minutes_string);

                n=0;
                o=0;
                for(n=0;n<7;n++){

                if(counter_Minutes_string[n]!=' ')
                {
                    m[o]= counter_Minutes_string[n];
                    o++;
                }
                }
             Lcd_out(2,10,m);



             if(counter_Minutes>=60)
             {
              Lcd_Cmd(_LCD_CLEAR);
                counter_Minutes = 0 ;

             }
             delay_ms(200);
             EEPROM_Write(0x01, counter_Minutes);
              counter_Minutes++;
         }

         if(PORTA.F3 == 0){
            Lcd_Cmd(_LCD_CLEAR);               // Clear display
            Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
            Lcd_out(1,1,"Time:");
            Lcd_out(2,1,"Date:");
         flag1=1;
         delay_ms(200);
         }
          }

         }
         flag1=0;
         
      
      ///////////////// test alarm vs hour

            if(houry[0]=='0'){
           if(hour3[0]==houry[1] )
          {
              //////////////// minutes
             if(time[3]=='0'){
           if(minute3[0]==time[4])
          {

            portd=0xFF;
            delay_ms(1000);
            portd=0x00;
            delay_ms(1000);
          }          }

          else if (minute3[0]==time[3] && minute3[1] == time[4])
          {
            portd=0xFF;
            delay_ms(1000);
            portd=0x00;
            delay_ms(1000);
          }

          //////////////// minutes


           } }
                    else if (hour3[0]==houry[0] && hour3[1] == houry[1])
          {
              //////////////// minutes
             if(time[3]=='0'){
           if(minute3[0]==time[4])
          {

            portd=0xFF;
            delay_ms(1000);
            portd=0x00;
            delay_ms(1000);
          }          }

          else if (minute3[0]==time[3] && minute3[1] == time[4])
          {
            portd=0xFF;
            delay_ms(1000);
            portd=0x00;
            delay_ms(1000);
          }

          //////////////// minutes
          }

          ///////////////// test alarm vs hour
          
          
      
      second = read_ds1307(0);
      minute = read_ds1307(1);
      hour = read_ds1307(2);
       hr = hour & 0b00011111;
       ap = hour & 0b00100000;
      dday = read_ds1307(3);
      day = read_ds1307(4);
      month = read_ds1307(5);
      year = read_ds1307(6);


      time[0] = BCD2UpperCh(hr);
      time[1] = BCD2LowerCh(hr);
      time[3] = BCD2UpperCh(minute);
      time[4] = BCD2LowerCh(minute);
      time[6] = BCD2UpperCh(second);
      time[7] = BCD2LowerCh(second);

      date[0] = BCD2UpperCh(day);
      date[1] = BCD2LowerCh(day);
      date[3] = BCD2UpperCh(month);
      date[4] = BCD2LowerCh(month);
      date[6] = BCD2UpperCh(year);
      date[7] = BCD2LowerCh(year);
      
      if(ap)
      {
         time[9] = 'P';
         time[10] = 'M';
      }
      else
      {
         time[9] = 'A';
         time[10] = 'M';
      }

      
      Lcd_out(1, 6, time);
      Lcd_out(2, 6, date);
      Delay_ms(100);

   
   }while(1);
}
 
Last edited:

zuisti

Advanced Member level 1
Joined
Jul 2, 2004
Messages
480
Helped
188
Reputation
376
Reaction score
184
Trophy points
1,323
Location
Hungary
Activity points
3,311
I get ROM problem ! There is not enough ROM space __Lib_Delays.c
Because you used a lot of Delay_ms(...) function.
From the help:
"This is an “inline” routine; code is generated in the place of the call" (every call !!).

Use instead the functions from the __Lib_Delays.c:
Code:
 Delay_ms(100)  >>> Delay_100ms() 
 Delay_ms(1000)  >>> Delay_1sec()

Attached the modified and well (?) working project.
The mikroC v6.01 compiler is used, in 'case sensitive' mode (recommended) so the source is also modified.
 

Attachments

  • dc_1.rar
    52.8 KB · Views: 7

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top