CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

setting up RTCC - PIC 18F24J11- timer -- please!!
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 30, 2011 2:18 pm     Reply with quote

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

View user's profile Send private message

print as string
PostPosted: Thu Mar 31, 2011 6:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 31, 2011 7:52 am     Reply with quote

Take a look the examples on this page:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/

Another one:
http://www.elook.org/programming/c/printf.html

Another one:
http://www.nerdkits.com/videos/printf_and_scanf/
_________________
Google and Forum Search are some of your best tools
heUAcyp



Joined: 16 Mar 2011
Posts: 33

View user's profile Send private message

PostPosted: Thu Mar 31, 2011 8:19 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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