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
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++;
}
}
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);
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);
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);
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:
But the ByteToStr is also enough in this case (3-char string, printed from its second position (string +1).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);
Code C - [expand] 1 2 LCD_Out(1,1,"EDA BOARD"); LCD_Out(1,6,"FLICKERING");
As I wrote above:how can I print an array from it's fourth position to the end !?
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");
As I wrote above:
Lcd_out(1,1,counter_Hours_string + 3);
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; }
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; }
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; }
The posted code is broken, review the listing and hex file. The processor resets before time and date strings are printed to LCD.no I used a full version and it compiled correctly and entirely
but the blinking problem remains
Code C - [expand] 1 2 TRISB = 0x00; PORTB = 0x00;
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);
}
Because you used a lot of Delay_ms(...) function.I get ROM problem ! There is not enough ROM space __Lib_Delays.c
Delay_ms(100) >>> Delay_100ms()
Delay_ms(1000) >>> Delay_1sec()
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?