|
|
View previous topic :: View next topic |
Author |
Message |
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
Use of RTC in PIC24 using PCD compiler |
Posted: Wed Mar 12, 2008 11:57 am |
|
|
Does anyone have an example how to read and write the built-in RTC of the PIC 24 processor, using the PCD compiler. I could find no documentation whatsoever except that the compiler is supposed to support it.
Thanks for any help you can give,
Ron |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Wed Mar 12, 2008 1:36 pm |
|
|
I don't know with PCD, however if you look at download the MCHP Explorer16 examples from Microchip using the PIC24F and look at how the sample application uses the RTC, it appears to be a straight forward port to CCS. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Thu Mar 13, 2008 3:43 am |
|
|
Andrew,
Thanks for the hekp. I found the files and I think I can solve it that way. However I wanted to use the built-in fuctions rtc_read() , rtc_write() and setup_rtc(). I just found that the compiler recognises them, but I do not know what parameters to pass and how to get the right information back.
Ron |
|
|
Globellit
Joined: 11 Mar 2008 Posts: 6 Location: Sweden
|
RTCC |
Posted: Tue Apr 01, 2008 7:45 am |
|
|
Did You solve the problem? I got the similar problem and I cant start the SOSC oscillator for the RTCC module so it dont running. I can write to the RTCC struct defined in device header file. Here com some code that seems to work.
time_t my_RTCC; //pointer to struct in device header file
void init_RTC(void){
setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0x00);// last int8 is calibration
setup_rtc_alarm(RTC_ALARM_ENABLE,RTC_ALARM_SECOND, 0xff); // 0xff repeat
my_RTCC.tm_year = 0x08; //init date and time
my_RTCC.tm_mon = 0x01;
my_RTCC.tm_mday = 0x01;
my_RTCC.tm_wday = 0x02;
my_RTCC.tm_hour = 0x0C;
my_RTCC.tm_min = 0x00;
my_RTCC.tm_sec = 0x00;
rtc_write(&my_RTCC); //write date and time
}
Hoping for a tip to start the SOSC oscillator.
regards,
robert
ronbreukers wrote: | Andrew,
Thanks for the hekp. I found the files and I think I can solve it that way. However I wanted to use the built-in fuctions rtc_read() , rtc_write() and setup_rtc(). I just found that the compiler recognises them, but I do not know what parameters to pass and how to get the right information back.
Ron |
|
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Thu Apr 03, 2008 2:39 am |
|
|
Thanks Robert,
It looks as if your code may work. I had not found it in the header file. I will have to wait for my PCB to check my solution to start the oscilator, but if it works I will post it here. |
|
|
mkent
Joined: 09 Sep 2003 Posts: 37 Location: TN, USA
|
|
Posted: Thu Apr 03, 2008 11:57 am |
|
|
The RTC functions are now listed in the "HELP" files. V4.071 |
|
|
Globellit
Joined: 11 Mar 2008 Posts: 6 Location: Sweden
|
pic24 RTCC |
Posted: Thu Apr 17, 2008 12:00 pm |
|
|
How did it go for You?
I have not implement the RTCC yet in my application but are moving forward to that day.
regards robert |
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Thu Apr 17, 2008 12:25 pm |
|
|
Hi Robert,
My PCB arrived this morning and I just finished assembling it. I did already see the the SOSC doe not work. I used
#define OSCCON 0x742
bit_set(*OSCCON,1) to set SOSCEN bit. But no luck yet. Will follow up here when I get someplace.
Ron |
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Sat Apr 19, 2008 6:25 am |
|
|
I managed to start the SOSC. The problem was that the OSCCON needs an unlock sequence, and that MUST be in assembly due to timing. I added:
#ASM
MOV #0x742,W1 //OSCCON L address
MOV.B #0x02,W0 //the SOSCEN bit is set
MOV #0x46,W2 //UNLOCK SEQUENCE 1
MOV #0x57,W3 //UNLOCK SEQUENCE 2
MOV.B W2,[W1] //Write the
MOV.B W3,[W1] //unlock sequence
MOV.B W0,[W1] //set the SOSCEN bit
#ENDASM |
|
|
Globellit
Joined: 11 Mar 2008 Posts: 6 Location: Sweden
|
RTCC |
Posted: Mon Apr 21, 2008 12:25 am |
|
|
Thank you very much I will test it. I have one question that you might know something about.
Is #int_RTCC interrupt connected to the RTCC alarm or is it timer 0 as usual. I have not find anything how the alarm interrupt works. Maybe I have to have to check the interrupt flag in the interrupt register.
regards robert |
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Mon Apr 21, 2008 2:56 am |
|
|
Robert, I am not sure. I assumed it was for the alarm function, but the RTCC does not work yet. It reads back FF each time.
If I look in the disassembly listing I see that setup_rtc(rtc_enable,0); translates into unlocking (as in the reference), but using 0x46,0x57 unlock sequence instead of 0x55 0xaa as it is supposed to be. I do not know if this is a bug in the compiler or if it works with this unlock sequence as well. I use version 4.068 compiler. |
|
|
Globellit
Joined: 11 Mar 2008 Posts: 6 Location: Sweden
|
pic24 rtcc |
Posted: Mon Apr 21, 2008 1:06 pm |
|
|
Ok, I am away for one week but will test it when I am back. I wonder if the wrong returning values has to do with BCD numbers I just has a fast look the mplab RTCC examples here is an example I just find.
It might be that the returned values is in BCD format but anyway the result schould not have been FF all the time probably still SOSC clock failure.
regards,
robert
Code: |
//-----------------------------------------------------------------------------
// Piece of code for PIC 24FJ64GA00 28pins using RTCC
// L. Baghli 27/02/2008
// info sent on UART1 (3V)
//
//-----------------------------------------------------------------------------
//#include "p24FJ64GA002.h"
#include "p24FJ128GA010.h"
_CONFIG1(JTAGEN_OFF & ICS_PGx1 & GCP_OFF & GWRP_OFF & BKBUG_OFF & COE_OFF & FWDTEN_OFF)
// si PLL : FCY = (FOSC*4)/2
// si pas PLL : FCY = FOSC/2
// Avec Pri osc de 4 MHz et pas sur l'Osc secondaire
_CONFIG2(IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRIPLL)
#define FCY 8000000 //Instruction cycle rate (Osc x (4)PLL / 2) = 8 MHz
#define T1Period 1600 // pour 200us à 4 MHz = T1Period = 400=FCY*200us
//-----------------------------------------------------------------------------
//Program Specific Constants
#define tcntPRD 5000 // combien de fois pour ariver en 1s avec des pas de 200us : 5000
#define MILLISEC FCY/20000 // 1 mSec delay constant
// debug
//#define DCF_RX _RB10 // DCF77 RX sur RB10
#define DCF_RX _LATB10 // DCF77 RX debug sur RB10
#define INT_Sleep _RB6 // IntSleep
#define InfoLED _LATB5 // Output
#define KeyMenu _RA0 // Input // BP2 pour Menu
#define KeyEnter _RA1 // Input // BP2 pour Enter
#define KeyUp _RB2 // Input // BP2 pour Up
#define KeyDown _RB3 // Input // BP2 pour Down
// U1RX sur RP11, U1TX sur RP9
// SPI SDO1 sur RP7, SCK1 sur RP8
void setup_ports(void);
void InitVar();
void InitUART();
void initTimer();
void DelayNmSec(unsigned int N);
unsigned int tcnt;
struct {
unsigned Recalcule : 1;
unsigned CheckRX : 1;
unsigned SendTX : 1;
unsigned SendData : 1;
unsigned RefreshLCD : 1;
unsigned unused : 11;
} Flags;
// RS232 -------------------------------------------
unsigned char *TXPtr;
unsigned char *RXPtr;
int SeqComm; // ttes les 1 s
#define SeqCommMax 5000
#define CR 0x0D
#define LF 0x0A
#define BAUD 19200
unsigned char InData[] = {"000000000000000000000000000000000"};
#define current_inputindexLimit 31
unsigned char OutData1[] = {"Xxxxx 00:00:00 le 00/00/2000\r"};
#define Offsetheure 10 // offset in OutData : position de la val de Heure, +3 pour min, +6 pour sec
#define OffsetDate 22 // offset in OutData : position de la val de Date
typedef union
{
struct
{
int BinYear; //Bin year 07-99
int BinFill; //Not used
int BinDay; //Bin day 01-31
int BinMonth; //Bin month 01-12
int BinHour; //Bin hour 00-24
int BinDOW; //Bin day of week 00-06
int BinSec; //Bin second 00-59
int BinMin; //Bin minutes 00-59
} BinField; //Field access
unsigned int BinData[8]; //Array to loop thru date/time values
} BinDateTime;
typedef union
{
struct
{
unsigned char BCDYear; //BCD Year
unsigned char BCDFill; //Not used - End of Year register
unsigned char BCDDay; //BCD day
unsigned char BCDMonth; //BCD Month - End of MTHDY register
unsigned char BCDHour; //BCD hours
unsigned char BCDDOW; //BCD day of week - End of WKDYHR register
unsigned char BCDSec; //BCD seconds
unsigned char BCDMin; //BCD minutes - End of MINSEC register
} BCDField;
unsigned char BCDReg8[8]; //Array to loop thru each field
unsigned int BCDReg16[4]; //Array to load/read entire register
} BCDDateTime;
BinDateTime datetime;
BCDDateTime BCDdatetime;
//-----------------------------------------------------------------------------
// Initialise variables
//-----------------------------------------------------------------------------
void InitVar(void)
{
tcnt=0;
}
//-----------------------------------------------------------------------------
// Setup ports
//-----------------------------------------------------------------------------
void setup_ports(void)
{
// enable Secondary Oscillator, attention : unlock OSCCON
__builtin_write_OSCCONL(OSCCON | 0x02); // OSCCON.SOSCEN=1;
// Clear All Ports Prior to defining I/O
AD1PCFG = 0xFFFF; // all PORTB = Digital(1) NoADC= analog(0)
// debug-a
PORTA=0; //Initialize LED pin data to off state
PORTB=0; //Initialize LED pin data to off state
// Now set pin direction registers
TRISA = 0xFFFF; // KeyMenu RA0 in, KeyEnter RA1 in, RA4 NC 0x1111
TRISB = 0x09DF; // RB0-1 in NC, KeyUp in RB2, KeyDown in RB3, RB4 in NC, InfoLED Out RB5, INT_Sleep RB4 in, DCF_RX RB10 out 1101|1111
// RB11 RX in, RB9 TX out LCD3310_Speaker, LCD3310_DC, LCD3310_CS, LCD3310_RST RB12-14 Out 0000|1001
__builtin_write_OSCCONL(OSCCON & ~0x40); //clear the bit 6 of OSCCONL to unlock pin re-map
//rem : unlock inutile si on programme juste une fois
RPINR18bits.U1RXR = 11; //RPINR18 is UART1 Receive and CTS register, 11 = RP we are using
RPOR4bits.RP9R = 3; //RPOR4 is output register for RP8 and RP9, 3 is function = UART1 Transmit
RPOR4bits.RP8R = 8; //RPOR4 is output register for RP8 and RP9, RP8 SCK1OUT 8 SPI1 Clock Output
RPOR3bits.RP7R = 7; //RPOR3 is output register for RP6 and RP7, RP7 SDO1 7 SPI1 Data Output
__builtin_write_OSCCONL(OSCCON | 0x40); //set the bit 6 of OSCCONL to lock pin re-map
}
//-----------------------------------------------------------------------------
void BinToBCD( BinDateTime *pBinDateTime, BCDDateTime *pBCDDateTime) //Convert binary time to BCD time
{
unsigned int d;
d=(pBinDateTime->BinField.BinYear)/10;
pBCDDateTime->BCDField.BCDYear= (d << 4) |(pBinDateTime->BinField.BinYear -d*10);
d=(pBinDateTime->BinField.BinMonth)/10;
pBCDDateTime->BCDField.BCDMonth= (d << 4) |(pBinDateTime->BinField.BinMonth -d*10);
d=(pBinDateTime->BinField.BinDay)/10;
pBCDDateTime->BCDField.BCDDay= (d << 4) |(pBinDateTime->BinField.BinDay -d*10);
pBCDDateTime->BCDField.BCDDOW= pBinDateTime->BinField.BinDOW;
d=(pBinDateTime->BinField.BinHour)/10;
pBCDDateTime->BCDField.BCDHour= (d << 4) |(pBinDateTime->BinField.BinHour -d*10);
d=(pBinDateTime->BinField.BinMin)/10;
pBCDDateTime->BCDField.BCDMin= (d << 4) |(pBinDateTime->BinField.BinMin -d*10);
d=(pBinDateTime->BinField.BinSec)/10;
pBCDDateTime->BCDField.BCDSec= (d << 4) |(pBinDateTime->BinField.BinSec -d*10);
}
//-----------------------------------------------------------------------------
//void BCDToBin( BinDateTime *pBinDateTime, BCDDateTime *pBCDDateTime) //Convert BCD time to binary time
//{
// pBinDateTime->BinField.BinYear = (pBCDDateTime->BCDField.BCDYear>>4)*10+pBCDDateTime->BCDField.BCDYear;
// pBinDateTime->BinField.BinMonth = (pBCDDateTime->BCDField.BCDMonth>>4)*10+pBCDDateTime->BCDField.BCDMonth;
// pBinDateTime->BinField.BinDay = (pBCDDateTime->BCDField.BCDDay>>4)*10+pBCDDateTime->BCDField.BCDDay;
// pBinDateTime->BinField.BinDOW = pBCDDateTime->BCDField.BCDDOW;
// pBinDateTime->BinField.BinHour = (pBCDDateTime->BCDField.BCDHour>>4)*10+pBCDDateTime->BCDField.BCDHour;
// pBinDateTime->BinField.BinMin = (pBCDDateTime->BCDField.BCDMin>>4)*10+pBCDDateTime->BCDField.BCDMin;
// pBinDateTime->BinField.BinSec = (pBCDDateTime->BCDField.BCDSec>>4)*10+pBCDDateTime->BCDField.BCDSec;
//}
//-----------------------------------------------------------------------------
// SetDateTime(BinDateTime *)
//
// - Audit binary date/time data
// - Convert binary date/time to binary coded decimal (BCD)
// - Write enable RTCC registers by setting RTCWREN in RCFGCAL
// - Disable interrupts and the RTCC module
// - Update RTCVAL registers with BCD date/time
// - Re-enable interrupts and the RTCC module
//-----------------------------------------------------------------------------
unsigned char SetDateTime(BinDateTime *pBinDateTime){
BCDDateTime BCDNow; //BCD date/time typedef
BCDDateTime *pBCDDateTime; //Pointer to access BCD typedef
int CurrentIPL; //Storage for interrupt priority macros
unsigned char Ctr; //Index counter
unsigned char ErrRtn=0; //Error return ind
//-------------------------------------------------------
// Audit the date time values passed to this function
// for the proper range
//-------------------------------------------------------
// debug
if (pBinDateTime->BinField.BinYear < 7 ||
pBinDateTime->BinField.BinYear > 99 ||
pBinDateTime->BinField.BinMonth > 12 ||
pBinDateTime->BinField.BinDay > 31 ||
pBinDateTime->BinField.BinDOW > 6 ||
pBinDateTime->BinField.BinHour > 24 ||
pBinDateTime->BinField.BinMin > 59 ||
pBinDateTime->BinField.BinSec > 59){
ErrRtn = 1;
return (ErrRtn);
}
//-------------------------------------------------------
// Convert binary date and time to binary coded decimal
//-------------------------------------------------------
pBCDDateTime = &BCDNow; //Refrence BCD typedef
BinToBCD(pBinDateTime, pBCDDateTime); //Convert binary time to BCD time
// **Write enable the RTCC register RCFGCAL**
// Turn on bit RTCWEN to allow updates to the RTCC register
__builtin_write_RTCWEN(); // A new builtin was released with C30 V3.02 to unlock and write enable the RTCC
// Initialize the Date and time in the RTCVAL registers
// These registers employ the RTCPTR from the RCFGCAL
// register. Each write instruction to the RTCVAL register
// decrements the pointer to the next RTCVAL register
// RTCPTR RTCVAL<15:8> RTCVAL<7:0>
// 11 ---- Year
// 10 Month Day
// 01 Weekday Hours
// 00 Minutes Seconds
//--------------------------------------------------------
SET_AND_SAVE_CPU_IPL(CurrentIPL,7); //Disable global interrupts
RCFGCALbits.RTCEN = 0; //Disable the RTCC
RCFGCALbits.RTCPTR = 3; //Set the RTCC pointer.
for (Ctr=0; Ctr<4; Ctr++) //Loop thru and set RTCVAL registers
RTCVAL = pBCDDateTime->BCDReg16[Ctr];
RCFGCALbits.RTCEN = 1; //Enable the RTCC
RCFGCALbits.RTCWREN = 0; //Lock settings (turn off write enable bit)
RESTORE_CPU_IPL(CurrentIPL); //Enable global interrupts
return (ErrRtn);
}
//-----------------------------------------------------------------------------
void ConfigRTCC(void){
datetime.BinField.BinYear= 8; //2008
datetime.BinField.BinMonth= 2; //fev
datetime.BinField.BinDOW= 3;
datetime.BinField.BinDay= 13;
datetime.BinField.BinHour= 23;
datetime.BinField.BinMin= 59;
datetime.BinField.BinSec= 10;
SetDateTime( & datetime);
}
//-----------------------------------------------------------------------------
void ReadRTCCtime(void){
BCDDateTime BCDNow, BCDNow_1; //BCD date/time typedef
unsigned char Ctr; //Index counter
// Read the Date and time from the RTCVAL registers twice et compare ==, sinon relire
do {
RCFGCALbits.RTCPTR = 3; //Set the RTCC pointer.
for (Ctr=0; Ctr<4; Ctr++) //Loop thru and set RTCVAL registers
BCDNow_1.BCDReg16[Ctr] = RTCVAL;
// reading twice and compare
RCFGCALbits.RTCPTR = 3; //Set the RTCC pointer.
for (Ctr=0; Ctr<4; Ctr++) //Loop thru and set RTCVAL registers
BCDNow.BCDReg16[Ctr] = RTCVAL;
}while(BCDNow.BCDField.BCDSec != BCDNow.BCDField.BCDSec); // make sure we have les memes Secondes
BCDdatetime=BCDNow; // update user's data
}
//-----------------------------------------------------------------------------
void initTimer(void){
// Timer1 pour l ISR des 200 us
T1CON = 0; // ensure Timer 1 is in reset state, internal timer clock Fosc/4, no prescale
TMR1 = 0; // RAZ Timer1
IFS0bits.T1IF = 0; // reset Timer 1 interrupt flag
IPC0bits.T1IP = 4; // set Timer1 interrupt priority level to 4
IEC0bits.T1IE = 1; // enable Timer 1 interrupt
PR1 = T1Period; // set Timer 1 period register
T1CONbits.TON = 1; // enable Timer 1 and start the count
}
//---------------------------------------------------------------------
// Below are the interrupt vectors for the serial receive and transmit
//---------------------------------------------------------------------
void __attribute__((interrupt, auto_psv)) _U1TXInterrupt(void){
IFS0bits.U1TXIF = 0; // clear interrupt flag
}
//---------------------------------------------------------------------
void __attribute__((interrupt, auto_psv)) _U1RXInterrupt(void){
IFS0bits.U1RXIF = 0; // clear interrupt flag
*RXPtr = U1RXREG;
if (*RXPtr == CR || *RXPtr == LF || RXPtr>=(&InData[0] +current_inputindexLimit)){
Flags.CheckRX = 1;
RXPtr = &InData[0];
}
else RXPtr++;
}
//------------------------------------------------------------------------
// Transmission over serial
void InitUART(void){
// Initialize the UART1
U1MODE = 0x8000; // enable UART1, 8 bits, 1 stop bit, no parity, RX normal
U1STA = 0x0000;
U1BRG = ((FCY/16)/BAUD) - 1; // set baud rate
RXPtr = &InData[0]; // point to first char in receive buffer
Flags.CheckRX = 0; // clear rx and tx flags
IFS0bits.U1RXIF = 0; // clear interrupt flag
IEC0bits.U1RXIE = 1; // enable RX interrupt
Flags.SendTX = 0;
Flags.SendData = 0; // clear flag
SeqComm=SeqCommMax;
U1STAbits.UTXEN = 1; // Initiate transmission
}
//-----------------------------------------------------------------------------
void SendMsg(void){
while (*TXPtr){
while (U1STAbits.UTXBF);
U1TXREG = *TXPtr++;
}
}
//------------------------------------------------------------------------
// Date/Time BCD to ASCII
void DateTimeBCDtoASCII(){
OutData1[Offsetheure ]=(BCDdatetime.BCDField.BCDHour >> 4) + 0x30;
OutData1[Offsetheure+1]=(BCDdatetime.BCDField.BCDHour & 0xF) + 0x30;
OutData1[Offsetheure+3]=(BCDdatetime.BCDField.BCDMin >> 4) + 0x30;
OutData1[Offsetheure+4]=(BCDdatetime.BCDField.BCDMin & 0xF) + 0x30;
OutData1[Offsetheure+6]=(BCDdatetime.BCDField.BCDSec >> 4) + 0x30;
OutData1[Offsetheure+7]=(BCDdatetime.BCDField.BCDSec & 0xF) + 0x30;
OutData1[OffsetDate ]=(BCDdatetime.BCDField.BCDDay >> 4) + 0x30;
OutData1[OffsetDate+1]=(BCDdatetime.BCDField.BCDDay & 0xF) + 0x30;
OutData1[OffsetDate+3]=(BCDdatetime.BCDField.BCDMonth >> 4) + 0x30;
OutData1[OffsetDate+4]=(BCDdatetime.BCDField.BCDMonth & 0xF) + 0x30;
OutData1[OffsetDate+8]=(BCDdatetime.BCDField.BCDYear >> 4) + 0x30;
OutData1[OffsetDate+9]=(BCDdatetime.BCDField.BCDYear & 0xF) + 0x30;
}
//------------------------------------------------------------------------
// SendData sends the debug information on the uart at 19200 baud
void SendData(){
DateTimeBCDtoASCII();
TXPtr = &OutData1[0];
SendMsg();
}
//---------------------------------------------------------------------
// Timer1 interrupt fait le calcul et l allumage des LED
// ISR toutes les 200 us
//---------------------------------------------------------------------
void __attribute__((interrupt, auto_psv)) _T1Interrupt( void ){
InfoLED=1;
IFS0bits.T1IF = 0;
if (++tcnt>=tcntPRD){
tcnt=0;
}
// communication dsPIC -> PC
if (!--SeqComm){
SeqComm=SeqCommMax;
Flags.SendData=1;
}
InfoLED=0;
}
//-----------------------------------------------------------------------------
//Main routine
int main(void){
setup_ports();
InitVar();
ConfigRTCC();
InitUART();
initTimer();
while(1){
if (Flags.SendData){
ReadRTCCtime();
SendData(); // send present fs serially
Flags.SendData = 0; // clear flag
}
} // end of while (1)
} // end of main
|
regards ,
robert |
|
|
Globellit
Joined: 11 Mar 2008 Posts: 6 Location: Sweden
|
RTCC pic24 |
Posted: Thu May 08, 2008 1:36 pm |
|
|
Hi Ron,
Im back and have get stucked in RTCC problem again. I saw that I missunderstod You last time. Am also tested the assembler code and finally the SOSC i s running, TANKS.
I use CCS 4.072 and run continuosly updating for latest version
I got exatly the same problem as You had, wrong read outs. I tried a unlock sequence in assembler but i am not so good to programing in that language so it is probably a lot of errors in that code anyway here it is.
in MPLAB
Code: | void RTCCUnlock(void){
asm volatile("disi #5");
asm volatile("mov #0x55, w7");
asm volatile("mov w7, _NVMKEY");
asm volatile("mov #0xAA, w8");
asm volatile("mov w8, _NVMKEY");
asm volatile("bset _RCFGCAL, #13");
asm volatile("nop");
asm volatile("nop");
} |
I translated it to CCS but no luck so far
Code: | #byte NVMKEY = 0x0766
#byte RCFGCAL = 0x0626
void mRTCCUnlock(void){
#ASM
DISI #5
MOV #0x55, w7
MOV w7, NVMKEY
MOV #0xAA, w8
MOV w8, NVMKEY
bset RCFGCAL, #13
NOP
NOP
#ENDASM
} |
|
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Tue Jun 03, 2008 5:04 am |
|
|
Hi Robert,
I have been away on vacation, but just returned. In my "vacation" I used the time also to continue some programming - to the annoyance of my wife-.
I already made the RTC in software, using the timer 1 interrupt. It works OK. However after I solved that problem I found many more, due to bugs in the compiler. Sometimes the program worked on the target system, and after recompiling the same code it stopped working. I found a number of bugs in the compiler where I used some workarounds, but in the end I got so disgusted from all the bugs I just switched to the "student edition" of the MPLAB C30 compiler.
Due to some different syntax I got first pages long of errors, but I am working to wittle that down.
First impression: I miss the boolean variable, but setting internal registers is easier dan in CCS. Also support to unlock access to protected registers like the SOSC setting. Also input / outputs are more logical (to my opinion). It is set default more strictly with respect to recognising names with different capitalisation(which I think in retrospect better). I also miss the delay_ms and delay_us functions. I have to make my own.
When my program runs again (it is about 4000 lines of code) I will report a comparison in byte size etc. and how much time it took me for the transition.
regards,
ron |
|
|
ronbreukers
Joined: 12 Mar 2008 Posts: 8 Location: the Netherlands
|
|
Posted: Wed Jun 04, 2008 6:32 am |
|
|
As a follow-up to my previous post. The conversion to the C30 compiler took me 1 1/2 days, mostly adapting the syntax and solving some timing issues.
The ROM used : CCS compiler: 13922 bytes, C30: 13347 bytes
Data memory : CCS 882 bytes, C30: 742 bytes
This last I do not understand. I had to convert a few booleans to int, because C30 does not understand booleans. I expected it to be more, not less.
By the way, I use a 24FJ32GA004. |
|
|
|
|
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
|