|
|
View previous topic :: View next topic |
Author |
Message |
sheikh.alsheikh
Joined: 27 Apr 2018 Posts: 2 Location: Islamabad, Pakistan
|
Error in time setting and debouncing in rts ds3232 using ssd |
Posted: Thu Sep 20, 2018 1:50 pm |
|
|
I am display hours and minutes of real time on four different ssd
using following drivers https://www.ccsinfo.com/forum/viewtopic.php?t=50256 with rtc 3232.
My code is following:
My time is automatically reset to different values and causing errors.
Debouncing is also occur.
I am unable to find the problem with it.
Code: |
#include <16c72.h>
#fuses HS
#use delay (clock = 8MHz)
#use I2C(Master, SDA = pin_C4, SCL = pin_C3)
#use rs232 (baud=9600,xmit=pin_c6,rcv=pin_c7,errors)
#define zero 0b11000000
#define one 0b11111001
#define two 0b10100100
#define three 0b10110000
#define four 0b10011001
#define five 0b10010010
#define six 0b10000010
#define seven 0b11111000
#define eight 0b10000000
#define nine 0b10010000
#define blank 0b11111111
#include "DS3231.c"
//#include "driver0.h"
unsigned int8 s = 55;
unsigned int8 min = 59;
unsigned int8 hr = 12;
unsigned int8 dy = 1;
unsigned int8 dt = 31;
unsigned int8 mt = 12;
unsigned int8 yr = 99;
short hr_format = _12_hour_format;
short am_pm = 1;
unsigned int8 data;
//int8 num;
//int8 inprocess1,inprocess2,inprocess3,inprocess4;
//int8 x[2],y[2];
unsigned int8 tenhr,unithr,tenmin,unitmin;
unsigned int8 tenhrr,unithrr,tenminn,unitminn;
//int8 aa,bb,cc,dd;
void bcdhrs(int8 a)
{
tenhr=a/10;
unithr=a%10;
}
void bcdmin(int8 a)
{
tenmin=a/10;
unitmin=a%10;
}
int ssd_code(int8 f)
{
switch (f)
{
case 0:
data=zero;
break;
case 1:
data=one;
break;
case 2:
data=two;
break;
case 3:
data=three;
break;
case 4:
data=four;
break;
case 5:
data=five;
break;
case 6:
data=six;
break;
case 7:
data=seven;
break;
case 8:
data=eight;
break;
case 9:
data=nine;
break;
default:
printf("\n\rno number");
break;
}
return data;
}
void bcs27()
{
tenhrr=ssd_code(tenhr);
unithrr=ssd_code(unithr);
tenminn=ssd_code(tenmin);
unitminn=ssd_code(unitmin);
}
void displaythousand()
{
output_b(tenhrr);
output_high(pin_a0);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a3);
delay_ms(40);
output_b(blank);
output_low(pin_a0);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a3);
delay_ms(40);
}
void displayhundred()
{
output_b(unithrr);
output_high(pin_a1);
output_low(pin_a0);
output_low(pin_a2);
output_low(pin_a3);
delay_ms(40);
output_b(blank);
output_low(pin_a0);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a3);
delay_ms(40);
}
void displaytenn()
{
output_b(tenminn);
output_high(pin_a2);
output_low(pin_a1);
output_low(pin_a0);
output_low(pin_a3);
delay_ms(40);
output_b(blank);
output_low(pin_a0);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a3);
delay_ms(40);
}
void displayunitt()
{
output_b(unitminn);
output_high(pin_a3);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a0);
delay_ms(40);
output_b(blank);
output_low(pin_a0);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a3);
delay_ms(40);
}
void main()
{
//int816 x=1234;
DS3231_init();
setTime(hr, min, s, am_pm, hr_format);
while(1)
{
getTime(hr, min, s, am_pm, hr_format);
printf ("\n\r hrs =%d\n\r mins= %d\n\r secs= %d",hr,min,s);
bcdhrs(hr);
bcdmin(min);
//print8f("\n\r thousand %d hundred%d tens%d unit%d",thou,hund,ten,unit);
bcs27();
//printf("\n\r %D %D %D %d"tenhrr,unithrr,tenminn,unitminn);
displaythousand();
displayhundred();
displaytenn();
displayunitt();
}
}
| ! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Thu Sep 20, 2018 2:28 pm |
|
|
You don't show us the setTime() or getTime() functions so very hard to say why or where the problem is....
However if you 'hard program' a time, does the Seven Segment Display(ssd) work OK ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 20, 2018 8:49 pm |
|
|
Do something similar to what temtronic suggested. Test if your display
routines work. Change your main() to this:
Code: |
void main()
{
DS3231_init();
hr = 0;
min = 0;
while(TRUE)
{
bcdhrs(hr);
bcdmin(min);
bcs27();
displaythousand();
displayhundred();
displaytenn();
displayunitt();
min++;
if(min == 60)
{
min = 0;
hr++;
}
delay_ms(500);
}
} |
Does it work correctly ? It should count up, in minutes and hours.
If not, you have something wrong with your display routines.
If it works, then look closely at your ds3231 routines.
Last edited by PCM programmer on Fri Sep 21, 2018 1:25 am; edited 2 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Sep 21, 2018 1:24 am |
|
|
Put a baud rate into the I2C setup.
It may well be clocking faster than your chip likes. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|