 |
 |
| View previous topic :: View next topic |
| Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 30, 2011 2:18 pm |
|
|
Edit the 18F24J11.h file and change the name as shown below in bold.
CCS does this in all recent versions of the compiler.
| Quote: |
typedef struct {
int8 tm_year;
int8 tm_yday; // Not used by built in functions
int8 tm_mday;
int8 tm_mon;
int8 tm_hour;
int8 tm_wday;
int8 tm_sec;
int8 tm_min;
int8 tm_isdst; // Not used by built in functions
} rtc_time_t;
|
Also use that name in your main program, when referring to structure elements. |
|
 |
heUAcyp
Joined: 16 Mar 2011 Posts: 33
|
| print as string |
Posted: Thu Mar 31, 2011 6:20 am |
|
|
It is working boss, here is the code:
| Code: | #include <18F24J11.h>
#device ADC=10
#include <STDIO.H>
#include <stdlib.h>
#include <math.h>
#include <STRING.H>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void patch_off() {
output_low(PIN_A2);
//printf("patch is off") ;
}
void patch_on() {
output_high(PIN_A2);
//printf("patch is on") ;
}
void InitTime()
{
rtc_time_t tmp;
tmp.tm_year = 11;
tmp.tm_mday = 29;
tmp.tm_mon = 3;
tmp.tm_hour = 10;
tmp.tm_wday = 4;
tmp.tm_sec = 0;
tmp.tm_min = 30;
rtc_write(&tmp);
}
rtc_time_t tmp;
void main()
{
setup_adc_ports(sAN0) ;
setup_adc(ADC_CLOCK_INTERNAL) ;
set_adc_channel( 0 );
// ti={0,0,0,0,0,0,0,0,0} ;
setup_rtc(RTC_ENABLE,RTCC_INTERNAL);
InitTime() ;
while(true)
{
enable_interrupts(global);
rtc_read(&tmp);
printf("%2u\n\r",tmp.tm_year);
printf("%2u\n\r",tmp.tm_mon);
printf("%2u\n\r",tmp.tm_mday);
printf("%2u\n\r",tmp.tm_hour);
printf("%2u\n\r",tmp.tm_min);
printf("%2u\n\r",tmp.tm_sec);
delay_ms(1000);
//printf("testing") ;
if (read_adc() > 0x300)
patch_off() ;
else
patch_on() ;
}
} |
However, instead of printing them in separate lines, as currently above code:
| Code: | printf("%2u\n\r",tmp.tm_year);
printf("%2u\n\r",tmp.tm_mon);
printf("%2u\n\r",tmp.tm_mday);
printf("%2u\n\r",tmp.tm_hour);
printf("%2u\n\r",tmp.tm_min);
printf("%2u\n\r",tmp.tm_sec); |
doing, I want to print them as single string like:
29.03.11 Tuesday 10:30:03
I have checked the manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
but I couldn't find out how to arrange that using printf().
How can I do this, can you guide me ?
Thank you very much again PCM. |
|
 |
dyeatman
Joined: 06 Sep 2003 Posts: 1985 Location: Norman, OK
|
|
 |
heUAcyp
Joined: 16 Mar 2011 Posts: 33
|
|
Posted: Thu Mar 31, 2011 8:19 am |
|
|
dyeatman , thanks for your reply,
this is my new code:
| Code: | #include <18F24J11.h>
#device ADC=10
#include <STDIO.H>
#include <stdlib.h>
#include <math.h>
#include <STRING.H>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void patch_off() {
output_low(PIN_A2);
//printf("patch is off") ;
}
void patch_on() {
output_high(PIN_A2);
//printf("patch is on") ;
}
void InitTime()
{
rtc_time_t tmp;
tmp.tm_year = 11;
tmp.tm_mday = 29;
tmp.tm_mon = 3;
tmp.tm_hour = 23;
tmp.tm_wday = 4;
tmp.tm_sec = 50;
tmp.tm_min = 59;
rtc_write(&tmp);
}
rtc_time_t tmp;
void main()
{
setup_adc_ports(sAN0) ;
setup_adc(ADC_CLOCK_INTERNAL) ;
set_adc_channel( 0 );
// ti={0,0,0,0,0,0,0,0,0} ;
setup_rtc(RTC_ENABLE,RTCC_INTERNAL);
InitTime() ;
while(true)
{
enable_interrupts(global);
rtc_read(&tmp);
printf("DATE: %u %u %u \n\r",tmp.tm_mday ,tmp.tm_mon, tmp.tm_year);
printf("Time: %u %u %u \n\r", tmp.tm_hour, tmp.tm_min, tmp.tm_sec);
delay_ms(1000);
if (read_adc() > 0x300)
patch_off() ;
else
patch_on() ;
}
} |
However when I test the RTCC, I realized that after 23:59:59 , instead of incrementing day it does not change the date, and starts from 20:00:00, what can be the reason for this!?
here is the output of hyperterminal:
DATE: 29 3 11
Time: 23 59 58
DATE: 29 3 11
Time: 23 59 59
DATE: 29 3 11
Time: 20 0 0
DATE: 29 3 11
Time: 20 0 1
DATE: 29 3 11
Time: 20 0 2 |
|
 |
|
|
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
|