![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
mlezamir Guest
|
ccp interupt |
Posted: Fri Jul 25, 2003 1:59 pm |
|
|
Hello,
I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
This is how i configure the cpp1 module:
/**************************************************/
CCP_1_HIGH=0x08; //set the compare reg. to generate
//a match at 2048 (every .5 sec)
CCP_1_LOW=0x00; //since the clock input is at 4096 Hz
T1CON=0x03; //turn on timer 1, use external clock input
CCP1CON=0x0B; //turn on timer 1 compare, set to reset
//timer 1 and generate interrupt
PIE1=0x04; //enable the CCP1 interrupt
enable_interrupts(GLOBAL);
enable_interrupts(INT_CCP1);
/***********************************************************/
Thanks,
mle
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516370 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: ccp interupt |
Posted: Fri Jul 25, 2003 6:57 pm |
|
|
:=I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
:=
--------------------------------------------------------
Can you post a full sample program, that can be copied into
MPLAB and compiled ? This program should include the INT_CCP
routine, #fuses statement, etc.
What version of the compiler are you using, and what PIC
are you using ?
If I may ask, why aren't you using the built-in CCS functions
to do all this ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516383 |
|
![](templates/subSilver/images/spacer.gif) |
MLE Guest
|
Re: ccp interupt |
Posted: Tue Jul 29, 2003 10:14 am |
|
|
:=:=I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
:=:=
:=--------------------------------------------------------
:=Can you post a full sample program, that can be copied into
:=MPLAB and compiled ? This program should include the INT_CCP
:=routine, #fuses statement, etc.
:=
:=What version of the compiler are you using, and what PIC
:=are you using ?
:=
:=If I may ask, why aren't you using the built-in CCS functions
:=to do all this ?
--------------------------------------------------------------
I am using version 3.136 of the ccs compiler and I am programming a PIC16f877. I am very new to ccs so I am not familiar with all the built in functions. Could you tell me which ones i should be looking at.
Thanks for your help,
Emily
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516472 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: ccp interupt |
Posted: Tue Jul 29, 2003 10:32 am |
|
|
:=:=:=I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
:=:=:=
:=:=--------------------------------------------------------
:=:=Can you post a full sample program, that can be copied into
:=:=MPLAB and compiled ? This program should include the INT_CCP
:=:=routine, #fuses statement, etc.
:=:=
:=:=What version of the compiler are you using, and what PIC
:=:=are you using ?
:=:=
:=:=If I may ask, why aren't you using the built-in CCS functions
:=:=to do all this ?
:=--------------------------------------------------------------
:=
:=I am using version 3.136 of the ccs compiler and I am programming a PIC16f877. I am very new to ccs so I am not familiar with all the built in functions. Could you tell me which ones i should be looking at.
:=
:=Thanks for your help,
:=Emily
Aargh!. Just about everything you are doing!.
The compiler contains routines to initialise the CCP, configure the timers, and set the values.
SETUP_CCP1(CCP_COMPARE_RESET_TIMER); //set the CCP to reset
//the timer (automatically generates an interrupt).
SET_PWM1_DUTY(2048); //Set the count to use
SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
ENABLE_INTERRUPTS(INT_CCP);
ENABLE_INTERRUPTS(GLOBAL);
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516473 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: ccp interupt |
Posted: Tue Jul 29, 2003 6:48 pm |
|
|
Built in functions are nice but I prefer to set things up manually. It gives you a better understanding of the chip. If you are just a programmer and don't really care about the internals of the chip then use the functions. If you are an embedded systems engineer that really wants to learn his stuff, read the datasheets and set things up manually. Afterall, these built in functions make things easier but not very portable. Just my 2 cents worth.
Mark
:=:=:=:=I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
:=:=:=:=
:=:=:=--------------------------------------------------------
:=:=:=Can you post a full sample program, that can be copied into
:=:=:=MPLAB and compiled ? This program should include the INT_CCP
:=:=:=routine, #fuses statement, etc.
:=:=:=
:=:=:=What version of the compiler are you using, and what PIC
:=:=:=are you using ?
:=:=:=
:=:=:=If I may ask, why aren't you using the built-in CCS functions
:=:=:=to do all this ?
:=:=--------------------------------------------------------------
:=:=
:=:=I am using version 3.136 of the ccs compiler and I am programming a PIC16f877. I am very new to ccs so I am not familiar with all the built in functions. Could you tell me which ones i should be looking at.
:=:=
:=:=Thanks for your help,
:=:=Emily
:=Aargh!. Just about everything you are doing!.
:=The compiler contains routines to initialise the CCP, configure the timers, and set the values.
:=
:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER); //set the CCP to reset
:=//the timer (automatically generates an interrupt).
:=SET_PWM1_DUTY(2048); //Set the count to use
:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=ENABLE_INTERRUPTS(INT_CCP);
:=ENABLE_INTERRUPTS(GLOBAL);
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516479 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: ccp interupt |
Posted: Tue Jul 29, 2003 7:03 pm |
|
|
:=Built in functions are nice but I prefer to set things up manually. It gives you a better understanding of the chip. If you are just a programmer and don't really care about the internals of the chip then use the functions. If you are an embedded systems engineer that really wants to learn his stuff, read the datasheets and set things up manually. Afterall, these built in functions make things easier but not very portable. Just my 2 cents worth.
:=
--------------------------------------------------------
But "portable" means the code can be re-used in a very
limited number of niche market PIC C compilers.
That means that I would have to write code on the off-chance
that I might switch compilers someday. Also, I would have
to write it so it would be compatible with the least capable
of the compilers. I couldn't use any internal functions.
Everything would have to be *0c = 0x55; etc.
I'd rather find a compiler that seems to work reasonably well,
and stick with it, and take advantage of its features.
With regard to learning the internals of the chip, I do it
anyway. I always review the data sheet before I use a new
module, that maybe I haven't used before.
I'm not making these comments to criticize your style of
programming -- it works for you, and you like it, but I'm
not sure it should be promoted for everyone else.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516481 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: ccp interupt |
Posted: Wed Jul 30, 2003 2:34 am |
|
|
:=Built in functions are nice but I prefer to set things up manually. It gives you a better understanding of the chip. If you are just a programmer and don't really care about the internals of the chip then use the functions. If you are an embedded systems engineer that really wants to learn his stuff, read the datasheets and set things up manually. Afterall, these built in functions make things easier but not very portable. Just my 2 cents worth.
:=
:=Mark
In one way, use of the inbuilt functions, should make the code more portable. If you use the standard defines, and these functions, you can take code written for a 16F876, and largely shift it directly to something like a 18F252. Since the hardware interface is never going to be 'portable' outside the PIC family, this is the limit of portability that this type of code is ever going to have. What I dislike seeing, is code that is blatantly 'non portable', by using constructs like:
T1CON=0x08;
The most portable code, would 'mimic' the constructions used by CCS in this regard, and define the bit fields, and byte fields, in a single 'global' location, so that only these have to change to move the code to a new chip. :-)
Best Wishes
:=:=:=:=:=I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
:=:=:=:=:=
:=:=:=:=--------------------------------------------------------
:=:=:=:=Can you post a full sample program, that can be copied into
:=:=:=:=MPLAB and compiled ? This program should include the INT_CCP
:=:=:=:=routine, #fuses statement, etc.
:=:=:=:=
:=:=:=:=What version of the compiler are you using, and what PIC
:=:=:=:=are you using ?
:=:=:=:=
:=:=:=:=If I may ask, why aren't you using the built-in CCS functions
:=:=:=:=to do all this ?
:=:=:=--------------------------------------------------------------
:=:=:=
:=:=:=I am using version 3.136 of the ccs compiler and I am programming a PIC16f877. I am very new to ccs so I am not familiar with all the built in functions. Could you tell me which ones i should be looking at.
:=:=:=
:=:=:=Thanks for your help,
:=:=:=Emily
:=:=Aargh!. Just about everything you are doing!.
:=:=The compiler contains routines to initialise the CCP, configure the timers, and set the values.
:=:=
:=:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER); //set the CCP to reset
:=:=//the timer (automatically generates an interrupt).
:=:=SET_PWM1_DUTY(2048); //Set the count to use
:=:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=:=ENABLE_INTERRUPTS(INT_CCP);
:=:=ENABLE_INTERRUPTS(GLOBAL);
:=:=
:=:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516490 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: ccp interupt |
Posted: Wed Jul 30, 2003 6:20 am |
|
|
CCS hides the code for the inbuilt functions. You can't change it or see it except the asm in the lst file. If you were to switch to another compiler, chances are these functions would not exist and you would have to find a similar one with the new compiler or create you own. How many people have had problems with these functions due to bugs in the past. I seem to remember it being a big problem. Especially the eeprom routines. I have had very few problems with the CCS compiler and was quite happy with it due to the fact that I rarely used the inbuilt functions (except the delay functions!). I switched to the C18 for the PIC18's after evaluating it because it was better than the PCH for my intent. For the PIC16's, I still use the PCM. Those of you who want to use the inbuilt functions, go ahead. It can make your life easier if all goes well. But there is no subsitute for learning from experience. I believe doing these functions yourself gives you a better understanding of the chip you are working with.
:=:=Built in functions are nice but I prefer to set things up manually. It gives you a better understanding of the chip. If you are just a programmer and don't really care about the internals of the chip then use the functions. If you are an embedded systems engineer that really wants to learn his stuff, read the datasheets and set things up manually. Afterall, these built in functions make things easier but not very portable. Just my 2 cents worth.
:=:=
:=:=Mark
:=In one way, use of the inbuilt functions, should make the code more portable. If you use the standard defines, and these functions, you can take code written for a 16F876, and largely shift it directly to something like a 18F252. Since the hardware interface is never going to be 'portable' outside the PIC family, this is the limit of portability that this type of code is ever going to have. What I dislike seeing, is code that is blatantly 'non portable', by using constructs like:
:=T1CON=0x08;
:=The most portable code, would 'mimic' the constructions used by CCS in this regard, and define the bit fields, and byte fields, in a single 'global' location, so that only these have to change to move the code to a new chip. :-)
:=
:=Best Wishes
:=
:=
:=:=:=:=:=:=I'm having a problem with my #INT_CCP1 routine. I have Timer1 set to count the clock pulses on pin RC0. I have the CCP1 module set up to match every 0.5sec and reset timer1. The problem is that I only get the interrupt once and that's it. Can anyone help?
:=:=:=:=:=:=
:=:=:=:=:=--------------------------------------------------------
:=:=:=:=:=Can you post a full sample program, that can be copied into
:=:=:=:=:=MPLAB and compiled ? This program should include the INT_CCP
:=:=:=:=:=routine, #fuses statement, etc.
:=:=:=:=:=
:=:=:=:=:=What version of the compiler are you using, and what PIC
:=:=:=:=:=are you using ?
:=:=:=:=:=
:=:=:=:=:=If I may ask, why aren't you using the built-in CCS functions
:=:=:=:=:=to do all this ?
:=:=:=:=--------------------------------------------------------------
:=:=:=:=
:=:=:=:=I am using version 3.136 of the ccs compiler and I am programming a PIC16f877. I am very new to ccs so I am not familiar with all the built in functions. Could you tell me which ones i should be looking at.
:=:=:=:=
:=:=:=:=Thanks for your help,
:=:=:=:=Emily
:=:=:=Aargh!. Just about everything you are doing!.
:=:=:=The compiler contains routines to initialise the CCP, configure the timers, and set the values.
:=:=:=
:=:=:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER); //set the CCP to reset
:=:=:=//the timer (automatically generates an interrupt).
:=:=:=SET_PWM1_DUTY(2048); //Set the count to use
:=:=:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=:=:=ENABLE_INTERRUPTS(INT_CCP);
:=:=:=ENABLE_INTERRUPTS(GLOBAL);
:=:=:=
:=:=:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516493 |
|
![](templates/subSilver/images/spacer.gif) |
MLE Guest
|
Re: ccp interupt |
Posted: Wed Jul 30, 2003 1:50 pm |
|
|
ok, i've tried both manual and with the built in functions, but it still doesn't work. It will display the time once, but then it doesn't change.
Here is my program
#include "mylcd.h"
#include "1wire.h"
#include "rtc.h"
#include <string.h>
#define DegreeSymbol 223 //ascii code for degree symbol
#byte STATUS = 0x03 //address of the status register
#byte PIE1 = 0x8C //address of the PIE1 register
#byte INTCON = 0x0B //address of the INTCON register
#byte ADCON1 = 0X9F //The adcon1 register
#byte TMR0 = 0x01 //the TMR0 register
#byte T1CON = 0x10 //timer1 control reg
#byte CCP1CON = 0x17 //capture/compare control reg
#byte OPTION_REG = 0x81 //option register
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte PORTD = 0x08
#byte PORTE = 0x09
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
/*----------GLOBAL VARIABLES-----------*/
int IntStatus; //contains flags for various events
int CompareTimes; //counts the number of times a compare match occurs
long TempAvTime; //the seconds that the temperatures are averaged over
int PulseCount; //counts number of pulses per interval
int PumpRunning; //set if the pump is running
int MenuState; //corresponds to the menu display
int matches;
/*----------FUNCTIONS-----------*/
/***********CCP1_int***********************/
/*This function handles the capture and */
/*compare inturrupt routine. */
/******************************************/
#INT_CCP1
CCP1_int(){
char line1[25];
#asm
incf matches
incf CompareTimes //increment the 0.5s counter
btfsc CompareTimes,0 //check for even number (1s)
GoTo ClearCompare //skip rest if not 1s
bsf IntStatus,0 //set the "fresh time" flag
bsf IntStatus,3 //set "fresh menu" flag
incf TempAvTime //increment the temp averaging time
btfsc STATUS,2 //check for overflow in TempAvTime
incf &TempAvTime+1 //carry to high byte if overflow
ClearCompare:
bcf PIE1,2 //clear the compare flag
#endasm
/*
sprintf(line1,"\%d",matches);
lcd_clear();
lcd_puts(line1);
*/
}
/***************Main Program Starts Here*************/
void main(){
//Variables
int RTCsec, //seconds of the real-time-clock
RTCmin, //minutes of the real-time-clock
RTChour, //hour of the real-time-clock
RTCday, //day from the real-time-clock
RTCmonth, //month from the real-time-clock
RTCyear, //year from the real-time-clock
oldsec,
OldYear; //holds year of last service date
char phone[8],line1[25], line2[25], seconds[3],minutes[3],hours[3], colon[2];
/*----------configure all the ports-------*/
Set_Tris_A(0x00); //set port A to outputs
Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
//RB1 (DQin) and RB0(pulse in) inputs
Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
//RC2, RC1, RC0 inputs
Set_Tris_D(0x00); //set port D to outputs
Set_Tris_E(0x00); //set port E to outputs
PORTA = 0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
/*-----------set PIC registers------------*/
ADCON1=0b00001110;
INTCON=0b11011000; //set up interrupts and turn them on
SETUP_CCP1(CCP_COMPARE_RESET_TIMER);//set to reset TMR1, interrupt
SET_PWM1_DUTY(2048); //set the compare reg. to generate a match at 2048 (every .5 sec)
//since the clock input is at 4096 Hz
SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
/*----------------initialize variables---------*/
CompareTimes = 0;
matches = 0;
oldsec = 0;
ENABLE_INTERRUPTS(INT_CCP1);
ENABLE_INTERRUPTS(GLOBAL);
delay_us(500);
lcd_init();
lcd_clear();
strcpy(line1, "RTCtest"); // copy string
lcd_puts(line1);
delay_ms(1000);
//write to rtc
writeRTC(9, 56, 4, 24, 7,3);
while(1){
//read from rtc
readTime(&RTCsec,&RTCmin,&RTChour);
//convert time to binary
RTCsec=convert2BIN(RTCsec);
RTCmin=convert2BIN(RTCmin);
RTChour=convert2BIN(RTChour);
if (IntStatus\%2 == 1){
//if(RTCsec!=oldsec){ //***use this if statement and it works
//convert numeric values to strings
#asm
bcf IntStatus,0
#endasm
sprintf(seconds,"\%d",RTCsec);
sprintf(minutes,"\%d",RTCmin);
sprintf(hours,"\%d",RTChour);
strcpy(line1, "Time "); // copy string
strcpy(colon, ":");
//display on LCD
lcd_clear();
lcd_puts(line1);
lcd_puts(hours);
lcd_puts(colon);
lcd_puts(minutes);
lcd_puts(colon);
lcd_puts(seconds);
}
}//end of infinite while loop
}//end of main()
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516501 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: ccp interupt |
Posted: Wed Jul 30, 2003 5:20 pm |
|
|
:=ok, i've tried both manual and with the built in functions, but it still doesn't work. It will display the time once, but then it doesn't change.
I went through your program and made a few comments.
I don't believe I've found every problem, but I've
run out of time to work on it, for now. (Got to get
my own work done). See my comments in the code below.
:=
:=Here is my program
:=
:=#include "mylcd.h"
:=#include "1wire.h"
:=#include "rtc.h"
:=#include <string.h> // string.h
:=
:=#define DegreeSymbol 223 //ascii code for degree symbol
:=#byte STATUS = 0x03 //address of the status register
:=#byte PIE1 = 0x8C //address of the PIE1 register
:=#byte INTCON = 0x0B //address of the INTCON register
:=#byte ADCON1 = 0X9F //The adcon1 register
:=#byte TMR0 = 0x01 //the TMR0 register
:=#byte T1CON = 0x10 //timer1 control reg
:=
:=#byte CCP1CON = 0x17 //capture/compare control reg
:=#byte OPTION_REG = 0x81 //option register
:=
:=#byte PORTA = 0x05
:=#byte PORTB = 0x06
:=#byte PORTC = 0x07
:=#byte PORTD = 0x08
:=#byte PORTE = 0x09
:=
:=#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
:=
:=/*----------GLOBAL VARIABLES-----------*/
:=int IntStatus; //contains flags for various events
:=int CompareTimes; //counts the number of times a compare match occurs
:=long TempAvTime; //the seconds that the temperatures are averaged over
:=int PulseCount; //counts number of pulses per interval
:=int PumpRunning; //set if the pump is running
:=int MenuState; //corresponds to the menu display
:=int matches;
:=
:=/*----------FUNCTIONS-----------*/
:=
:=
:=/***********CCP1_int***********************/
:=/*This function handles the capture and */
:=/*compare inturrupt routine. */
:=/******************************************/
:=#INT_CCP1
:=CCP1_int(){
:= char line1[25];
:=#asm
:= incf matches
:= incf CompareTimes //increment the 0.5s counter
:= btfsc CompareTimes,0 //check for even number (1s)
:= GoTo ClearCompare //skip rest if not 1s
:= bsf IntStatus,0 //set the "fresh time" flag
:= bsf IntStatus,3 //set "fresh menu" flag
:= incf TempAvTime //increment the temp averaging time
:= btfsc STATUS,2 //check for overflow in TempAvTime
:= incf &TempAvTime+1 //carry to high byte if overflow
:=ClearCompare:
:= bcf PIE1,2 //clear the compare flag
:=#endasm
:=/*
:= sprintf(line1,"\%d",matches);
:= lcd_clear();
:= lcd_puts(line1);
:=*/
:=}
:=
:=/***************Main Program Starts Here*************/
:=void main(){
:=
:=//Variables
:=int RTCsec, //seconds of the real-time-clock
:= RTCmin, //minutes of the real-time-clock
:= RTChour, //hour of the real-time-clock
:= RTCday, //day from the real-time-clock
:= RTCmonth, //month from the real-time-clock
:= RTCyear, //year from the real-time-clock
:= oldsec,
:= OldYear; //holds year of last service date
:=
:=
:=char phone[8],line1[25], line2[25], seconds[3],minutes[3],hours[3], colon[2];
:=
:=/*----------configure all the ports-------*/
:=Set_Tris_A(0x00); //set port A to outputs
:=Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
:= //RB1 (DQin) and RB0(pulse in) inputs
:=Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
:= //RC2, RC1, RC0 inputs
:=Set_Tris_D(0x00); //set port D to outputs
:=Set_Tris_E(0x00); //set port E to outputs
:=PORTA = 0;
:=PORTB = 0;
:=PORTC = 0;
:=PORTD = 0;
:=PORTE = 0;
:=
:=/*-----------set PIC registers------------*/
:=ADCON1=0b00001110;
The next line turns on the following bits:
bit 7 = Enable global interrupts
bit 6 = Enable peripheral interrupts
bit 4 = Enable external interrupts on Pin B0
bit 3 = Enable RB interrupts
This is the equivalent of these CCS lines:
enable_interrupts(INT_EXT);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
Is that your intention ?
Note that you're enabling global interrupts here,
and also later on in the program.
:=INTCON=0b11011000; //set up interrupts and turn them on
:=
:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER);//set to reset TMR1, interrupt
:=SET_PWM1_DUTY(2048); //set the compare reg. to generate a match at 2048 (every .5 sec)
:= //since the clock input is at 4096 Hz
:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=
:=/*----------------initialize variables---------*/
:=CompareTimes = 0;
:=matches = 0;
:=oldsec = 0;
:=
I think you should make sure the CCP1 interrupt flag
is cleared, before enabling interrupts. Example:
#bit CCPIF_BIT = 0x0C.2 // Put this line above main()
Then clear the bit by putting this line here:
CCPIF_BIT = 0;
:=ENABLE_INTERRUPTS(INT_CCP1);
:=ENABLE_INTERRUPTS(GLOBAL);
:=
:=delay_us(500);
:=lcd_init();
:=lcd_clear();
:=
:=strcpy(line1, "RTCtest"); // copy string
:=lcd_puts(line1);
:=delay_ms(1000);
:=
:=//write to rtc
:=writeRTC(9, 56, 4, 24, 7,3);
:=
:=while(1){
:=
:=//read from rtc
:=readTime(&RTCsec,&RTCmin,&RTChour);
:=
:=//convert time to binary
:=RTCsec=convert2BIN(RTCsec);
:=RTCmin=convert2BIN(RTCmin);
:=RTChour=convert2BIN(RTChour);
:=
:=if (IntStatus\%2 == 1){
:=//if(RTCsec!=oldsec){ //***use this if statement and it works
:=//convert numeric values to strings
:=#asm
:=bcf IntStatus,0
:=#endasm
:=sprintf(seconds,"\%d",RTCsec);
:=sprintf(minutes,"\%d",RTCmin);
:=sprintf(hours,"\%d",RTChour);
:=
:=strcpy(line1, "Time "); // copy string
:=strcpy(colon, ":");
:=
:=//display on LCD
:=lcd_clear();
:=lcd_puts(line1);
:=lcd_puts(hours);
:=lcd_puts(colon);
:=lcd_puts(minutes);
:=lcd_puts(colon);
:=lcd_puts(seconds);
:=
:=}
:=
:=}//end of infinite while loop
:=
:=}//end of main()
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516508 |
|
![](templates/subSilver/images/spacer.gif) |
MLE Guest
|
Re: ccp interupt |
Posted: Thu Jul 31, 2003 2:31 pm |
|
|
Hi,
Thank you for your help. I made the changes you suggested, but unfortunately the problem still persists. The ccp1 interrupt is not being triggered. I replaced the if statement
if (IntStatus\%2 == 1){
with the following if statement
if ((TMR1H && TMR1L)==0){
The second statement works, which means that timer1 is getting reset by the capture/compare module, but it's not running the interrupt routine. I don't understand why it won't run the interrupt routine.
Emily
:=:=
:=:=Here is my program
:=:=
:=:=#include "mylcd.h"
:=:=#include "1wire.h"
:=:=#include "rtc.h"
:=:=#include <string.h> // string.h
:=:=
:=:=#define DegreeSymbol 223 //ascii code for degree symbol
:=:=#byte STATUS = 0x03 //address of the status register
:=:=#byte PIE1 = 0x8C //address of the PIE1 register
:=:=#byte INTCON = 0x0B //address of the INTCON register
:=:=#byte ADCON1 = 0X9F //The adcon1 register
:=:=#byte TMR0 = 0x01 //the TMR0 register
:=:=#byte T1CON = 0x10 //timer1 control reg
:=:=
:=:=#byte CCP1CON = 0x17 //capture/compare control reg
:=:=#byte OPTION_REG = 0x81 //option register
:=:=
:=:=#byte PORTA = 0x05
:=:=#byte PORTB = 0x06
:=:=#byte PORTC = 0x07
:=:=#byte PORTD = 0x08
:=:=#byte PORTE = 0x09
:=:=
:=:=#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
:=:=
:=:=/*----------GLOBAL VARIABLES-----------*/
:=:=int IntStatus; //contains flags for various events
:=:=int CompareTimes; //counts the number of times a compare match occurs
:=:=long TempAvTime; //the seconds that the temperatures are averaged over
:=:=int PulseCount; //counts number of pulses per interval
:=:=int PumpRunning; //set if the pump is running
:=:=int MenuState; //corresponds to the menu display
:=:=int matches;
:=:=
:=:=/*----------FUNCTIONS-----------*/
:=:=
:=:=
:=:=/***********CCP1_int***********************/
:=:=/*This function handles the capture and */
:=:=/*compare inturrupt routine. */
:=:=/******************************************/
:=:=#INT_CCP1
:=:=CCP1_int(){
:=:= char line1[25];
:=:=#asm
:=:= incf matches
:=:= incf CompareTimes //increment the 0.5s counter
:=:= btfsc CompareTimes,0 //check for even number (1s)
:=:= GoTo ClearCompare //skip rest if not 1s
:=:= bsf IntStatus,0 //set the "fresh time" flag
:=:= bsf IntStatus,3 //set "fresh menu" flag
:=:= incf TempAvTime //increment the temp averaging time
:=:= btfsc STATUS,2 //check for overflow in TempAvTime
:=:= incf &TempAvTime+1 //carry to high byte if overflow
:=:=ClearCompare:
:=:= bcf PIE1,2 //clear the compare flag
:=:=#endasm
:=:=/*
:=:= sprintf(line1,"\%d",matches);
:=:= lcd_clear();
:=:= lcd_puts(line1);
:=:=*/
:=:=}
:=:=
:=:=/***************Main Program Starts Here*************/
:=:=void main(){
:=:=
:=:=//Variables
:=:=int RTCsec, //seconds of the real-time-clock
:=:= RTCmin, //minutes of the real-time-clock
:=:= RTChour, //hour of the real-time-clock
:=:= RTCday, //day from the real-time-clock
:=:= RTCmonth, //month from the real-time-clock
:=:= RTCyear, //year from the real-time-clock
:=:= oldsec,
:=:= OldYear; //holds year of last service date
:=:=
:=:=
:=:=char phone[8],line1[25], line2[25], seconds[3],minutes[3],hours[3], colon[2];
:=:=
:=:=/*----------configure all the ports-------*/
:=:=Set_Tris_A(0x00); //set port A to outputs
:=:=Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
:=:= //RB1 (DQin) and RB0(pulse in) inputs
:=:=Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
:=:= //RC2, RC1, RC0 inputs
:=:=Set_Tris_D(0x00); //set port D to outputs
:=:=Set_Tris_E(0x00); //set port E to outputs
:=:=PORTA = 0;
:=:=PORTB = 0;
:=:=PORTC = 0;
:=:=PORTD = 0;
:=:=PORTE = 0;
:=:=
:=:=/*-----------set PIC registers------------*/
:=:=ADCON1=0b00001110;
:=
:=
:=The next line turns on the following bits:
:=bit 7 = Enable global interrupts
:=bit 6 = Enable peripheral interrupts
:=bit 4 = Enable external interrupts on Pin B0
:=bit 3 = Enable RB interrupts
:=
:=This is the equivalent of these CCS lines:
:=enable_interrupts(INT_EXT);
:=enable_interrupts(INT_RB);
:=enable_interrupts(GLOBAL);
:=
:=Is that your intention ?
:=
:=Note that you're enabling global interrupts here,
:=and also later on in the program.
:=
:=:=INTCON=0b11011000; //set up interrupts and turn them on
:=:=
:=:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER);//set to reset TMR1, interrupt
:=:=SET_PWM1_DUTY(2048); //set the compare reg. to generate a match at 2048 (every .5 sec)
:=:= //since the clock input is at 4096 Hz
:=:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=:=
:=:=/*----------------initialize variables---------*/
:=:=CompareTimes = 0;
:=:=matches = 0;
:=:=oldsec = 0;
:=:=
:=
:=I think you should make sure the CCP1 interrupt flag
:=is cleared, before enabling interrupts. Example:
:=
:=#bit CCPIF_BIT = 0x0C.2 // Put this line above main()
:=
:=Then clear the bit by putting this line here:
:=
:=CCPIF_BIT = 0;
:=
:=:=ENABLE_INTERRUPTS(INT_CCP1);
:=:=ENABLE_INTERRUPTS(GLOBAL);
:=:=
:=:=delay_us(500);
:=:=lcd_init();
:=:=lcd_clear();
:=:=
:=:=strcpy(line1, "RTCtest"); // copy string
:=:=lcd_puts(line1);
:=:=delay_ms(1000);
:=:=
:=:=//write to rtc
:=:=writeRTC(9, 56, 4, 24, 7,3);
:=:=
:=:=while(1){
:=:=
:=:=//read from rtc
:=:=readTime(&RTCsec,&RTCmin,&RTChour);
:=:=
:=:=//convert time to binary
:=:=RTCsec=convert2BIN(RTCsec);
:=:=RTCmin=convert2BIN(RTCmin);
:=:=RTChour=convert2BIN(RTChour);
:=:=
:=:=if (IntStatus\%2 == 1){
:=:=//if(RTCsec!=oldsec){ //***use this if statement and it works
:=:=//convert numeric values to strings
:=:=#asm
:=:=bcf IntStatus,0
:=:=#endasm
:=:=sprintf(seconds,"\%d",RTCsec);
:=:=sprintf(minutes,"\%d",RTCmin);
:=:=sprintf(hours,"\%d",RTChour);
:=:=
:=:=strcpy(line1, "Time "); // copy string
:=:=strcpy(colon, ":");
:=:=
:=:=//display on LCD
:=:=lcd_clear();
:=:=lcd_puts(line1);
:=:=lcd_puts(hours);
:=:=lcd_puts(colon);
:=:=lcd_puts(minutes);
:=:=lcd_puts(colon);
:=:=lcd_puts(seconds);
:=:=
:=:=}
:=:=
:=:=}//end of infinite while loop
:=:=
:=:=}//end of main()
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516532 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: ccp interupt |
Posted: Thu Jul 31, 2003 5:28 pm |
|
|
This statement is incorrect:
if ((TMR1H && TMR1L)==0){
it should be
if ((TMR1H==0) && (TMR1L==0)){
or
if (!TMR1H && !TMR1L){
Mark
:=Hi,
:=Thank you for your help. I made the changes you suggested, but unfortunately the problem still persists. The ccp1 interrupt is not being triggered. I replaced the if statement
:=
:=if (IntStatus\%2 == 1){
:=
:=with the following if statement
:=
:=if ((TMR1H && TMR1L)==0){
:=
:=The second statement works, which means that timer1 is getting reset by the capture/compare module, but it's not running the interrupt routine. I don't understand why it won't run the interrupt routine.
:=
:=Emily
:=
:=
:=
:=
:=
:=:=:=
:=:=:=Here is my program
:=:=:=
:=:=:=#include "mylcd.h"
:=:=:=#include "1wire.h"
:=:=:=#include "rtc.h"
:=:=:=#include <string.h> // string.h
:=:=:=
:=:=:=#define DegreeSymbol 223 //ascii code for degree symbol
:=:=:=#byte STATUS = 0x03 //address of the status register
:=:=:=#byte PIE1 = 0x8C //address of the PIE1 register
:=:=:=#byte INTCON = 0x0B //address of the INTCON register
:=:=:=#byte ADCON1 = 0X9F //The adcon1 register
:=:=:=#byte TMR0 = 0x01 //the TMR0 register
:=:=:=#byte T1CON = 0x10 //timer1 control reg
:=:=:=
:=:=:=#byte CCP1CON = 0x17 //capture/compare control reg
:=:=:=#byte OPTION_REG = 0x81 //option register
:=:=:=
:=:=:=#byte PORTA = 0x05
:=:=:=#byte PORTB = 0x06
:=:=:=#byte PORTC = 0x07
:=:=:=#byte PORTD = 0x08
:=:=:=#byte PORTE = 0x09
:=:=:=
:=:=:=#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=
:=:=:=/*----------GLOBAL VARIABLES-----------*/
:=:=:=int IntStatus; //contains flags for various events
:=:=:=int CompareTimes; //counts the number of times a compare match occurs
:=:=:=long TempAvTime; //the seconds that the temperatures are averaged over
:=:=:=int PulseCount; //counts number of pulses per interval
:=:=:=int PumpRunning; //set if the pump is running
:=:=:=int MenuState; //corresponds to the menu display
:=:=:=int matches;
:=:=:=
:=:=:=/*----------FUNCTIONS-----------*/
:=:=:=
:=:=:=
:=:=:=/***********CCP1_int***********************/
:=:=:=/*This function handles the capture and */
:=:=:=/*compare inturrupt routine. */
:=:=:=/******************************************/
:=:=:=#INT_CCP1
:=:=:=CCP1_int(){
:=:=:= char line1[25];
:=:=:=#asm
:=:=:= incf matches
:=:=:= incf CompareTimes //increment the 0.5s counter
:=:=:= btfsc CompareTimes,0 //check for even number (1s)
:=:=:= GoTo ClearCompare //skip rest if not 1s
:=:=:= bsf IntStatus,0 //set the "fresh time" flag
:=:=:= bsf IntStatus,3 //set "fresh menu" flag
:=:=:= incf TempAvTime //increment the temp averaging time
:=:=:= btfsc STATUS,2 //check for overflow in TempAvTime
:=:=:= incf &TempAvTime+1 //carry to high byte if overflow
:=:=:=ClearCompare:
:=:=:= bcf PIE1,2 //clear the compare flag
:=:=:=#endasm
:=:=:=/*
:=:=:= sprintf(line1,"\%d",matches);
:=:=:= lcd_clear();
:=:=:= lcd_puts(line1);
:=:=:=*/
:=:=:=}
:=:=:=
:=:=:=/***************Main Program Starts Here*************/
:=:=:=void main(){
:=:=:=
:=:=:=//Variables
:=:=:=int RTCsec, //seconds of the real-time-clock
:=:=:= RTCmin, //minutes of the real-time-clock
:=:=:= RTChour, //hour of the real-time-clock
:=:=:= RTCday, //day from the real-time-clock
:=:=:= RTCmonth, //month from the real-time-clock
:=:=:= RTCyear, //year from the real-time-clock
:=:=:= oldsec,
:=:=:= OldYear; //holds year of last service date
:=:=:=
:=:=:=
:=:=:=char phone[8],line1[25], line2[25], seconds[3],minutes[3],hours[3], colon[2];
:=:=:=
:=:=:=/*----------configure all the ports-------*/
:=:=:=Set_Tris_A(0x00); //set port A to outputs
:=:=:=Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
:=:=:= //RB1 (DQin) and RB0(pulse in) inputs
:=:=:=Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
:=:=:= //RC2, RC1, RC0 inputs
:=:=:=Set_Tris_D(0x00); //set port D to outputs
:=:=:=Set_Tris_E(0x00); //set port E to outputs
:=:=:=PORTA = 0;
:=:=:=PORTB = 0;
:=:=:=PORTC = 0;
:=:=:=PORTD = 0;
:=:=:=PORTE = 0;
:=:=:=
:=:=:=/*-----------set PIC registers------------*/
:=:=:=ADCON1=0b00001110;
:=:=
:=:=
:=:=The next line turns on the following bits:
:=:=bit 7 = Enable global interrupts
:=:=bit 6 = Enable peripheral interrupts
:=:=bit 4 = Enable external interrupts on Pin B0
:=:=bit 3 = Enable RB interrupts
:=:=
:=:=This is the equivalent of these CCS lines:
:=:=enable_interrupts(INT_EXT);
:=:=enable_interrupts(INT_RB);
:=:=enable_interrupts(GLOBAL);
:=:=
:=:=Is that your intention ?
:=:=
:=:=Note that you're enabling global interrupts here,
:=:=and also later on in the program.
:=:=
:=:=:=INTCON=0b11011000; //set up interrupts and turn them on
:=:=:=
:=:=:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER);//set to reset TMR1, interrupt
:=:=:=SET_PWM1_DUTY(2048); //set the compare reg. to generate a match at 2048 (every .5 sec)
:=:=:= //since the clock input is at 4096 Hz
:=:=:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=:=:=
:=:=:=/*----------------initialize variables---------*/
:=:=:=CompareTimes = 0;
:=:=:=matches = 0;
:=:=:=oldsec = 0;
:=:=:=
:=:=
:=:=I think you should make sure the CCP1 interrupt flag
:=:=is cleared, before enabling interrupts. Example:
:=:=
:=:=#bit CCPIF_BIT = 0x0C.2 // Put this line above main()
:=:=
:=:=Then clear the bit by putting this line here:
:=:=
:=:=CCPIF_BIT = 0;
:=:=
:=:=:=ENABLE_INTERRUPTS(INT_CCP1);
:=:=:=ENABLE_INTERRUPTS(GLOBAL);
:=:=:=
:=:=:=delay_us(500);
:=:=:=lcd_init();
:=:=:=lcd_clear();
:=:=:=
:=:=:=strcpy(line1, "RTCtest"); // copy string
:=:=:=lcd_puts(line1);
:=:=:=delay_ms(1000);
:=:=:=
:=:=:=//write to rtc
:=:=:=writeRTC(9, 56, 4, 24, 7,3);
:=:=:=
:=:=:=while(1){
:=:=:=
:=:=:=//read from rtc
:=:=:=readTime(&RTCsec,&RTCmin,&RTChour);
:=:=:=
:=:=:=//convert time to binary
:=:=:=RTCsec=convert2BIN(RTCsec);
:=:=:=RTCmin=convert2BIN(RTCmin);
:=:=:=RTChour=convert2BIN(RTChour);
:=:=:=
:=:=:=if (IntStatus\%2 == 1){
:=:=:=//if(RTCsec!=oldsec){ //***use this if statement and it works
:=:=:=//convert numeric values to strings
:=:=:=#asm
:=:=:=bcf IntStatus,0
:=:=:=#endasm
:=:=:=sprintf(seconds,"\%d",RTCsec);
:=:=:=sprintf(minutes,"\%d",RTCmin);
:=:=:=sprintf(hours,"\%d",RTChour);
:=:=:=
:=:=:=strcpy(line1, "Time "); // copy string
:=:=:=strcpy(colon, ":");
:=:=:=
:=:=:=//display on LCD
:=:=:=lcd_clear();
:=:=:=lcd_puts(line1);
:=:=:=lcd_puts(hours);
:=:=:=lcd_puts(colon);
:=:=:=lcd_puts(minutes);
:=:=:=lcd_puts(colon);
:=:=:=lcd_puts(seconds);
:=:=:=
:=:=:=}
:=:=:=
:=:=:=}//end of infinite while loop
:=:=:=
:=:=:=}//end of main()
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516535 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: ccp interupt |
Posted: Thu Jul 31, 2003 5:37 pm |
|
|
The compiler handles clear the interrupt flag when the interrupt fires. However, in your ISR you clear the interrupt enable bit with this statement:
bcf PIE1,2 //clear the compare flag
Thus the interrupt will only fire once. You probably meant to use this:
bcf PIR1,2 //clear the compare flag
but again is unnecessary since the compiler handles this for you.
Mark
:=ok, i've tried both manual and with the built in functions, but it still doesn't work. It will display the time once, but then it doesn't change.
:=
:=Here is my program
:=
:=#include "mylcd.h"
:=#include "1wire.h"
:=#include "rtc.h"
:=#include <string.h>
:=
:=#define DegreeSymbol 223 //ascii code for degree symbol
:=#byte STATUS = 0x03 //address of the status register
:=#byte PIE1 = 0x8C //address of the PIE1 register
:=#byte INTCON = 0x0B //address of the INTCON register
:=#byte ADCON1 = 0X9F //The adcon1 register
:=#byte TMR0 = 0x01 //the TMR0 register
:=#byte T1CON = 0x10 //timer1 control reg
:=
:=#byte CCP1CON = 0x17 //capture/compare control reg
:=#byte OPTION_REG = 0x81 //option register
:=
:=#byte PORTA = 0x05
:=#byte PORTB = 0x06
:=#byte PORTC = 0x07
:=#byte PORTD = 0x08
:=#byte PORTE = 0x09
:=
:=#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
:=
:=/*----------GLOBAL VARIABLES-----------*/
:=int IntStatus; //contains flags for various events
:=int CompareTimes; //counts the number of times a compare match occurs
:=long TempAvTime; //the seconds that the temperatures are averaged over
:=int PulseCount; //counts number of pulses per interval
:=int PumpRunning; //set if the pump is running
:=int MenuState; //corresponds to the menu display
:=int matches;
:=
:=/*----------FUNCTIONS-----------*/
:=
:=
:=/***********CCP1_int***********************/
:=/*This function handles the capture and */
:=/*compare inturrupt routine. */
:=/******************************************/
:=#INT_CCP1
:=CCP1_int(){
:= char line1[25];
:=#asm
:= incf matches
:= incf CompareTimes //increment the 0.5s counter
:= btfsc CompareTimes,0 //check for even number (1s)
:= GoTo ClearCompare //skip rest if not 1s
:= bsf IntStatus,0 //set the "fresh time" flag
:= bsf IntStatus,3 //set "fresh menu" flag
:= incf TempAvTime //increment the temp averaging time
:= btfsc STATUS,2 //check for overflow in TempAvTime
:= incf &TempAvTime+1 //carry to high byte if overflow
:=ClearCompare:
:= bcf PIE1,2 //clear the compare flag
:=#endasm
:=/*
:= sprintf(line1,"\%d",matches);
:= lcd_clear();
:= lcd_puts(line1);
:=*/
:=}
:=
:=/***************Main Program Starts Here*************/
:=void main(){
:=
:=//Variables
:=int RTCsec, //seconds of the real-time-clock
:= RTCmin, //minutes of the real-time-clock
:= RTChour, //hour of the real-time-clock
:= RTCday, //day from the real-time-clock
:= RTCmonth, //month from the real-time-clock
:= RTCyear, //year from the real-time-clock
:= oldsec,
:= OldYear; //holds year of last service date
:=
:=
:=char phone[8],line1[25], line2[25], seconds[3],minutes[3],hours[3], colon[2];
:=
:=/*----------configure all the ports-------*/
:=Set_Tris_A(0x00); //set port A to outputs
:=Set_Tris_B(0x33); //make RB5, RB4(BUTTONS),
:= //RB1 (DQin) and RB0(pulse in) inputs
:=Set_Tris_C(0xD7); //RC7, RC6 (for Hserin/Hserout), RC4(RTC),
:= //RC2, RC1, RC0 inputs
:=Set_Tris_D(0x00); //set port D to outputs
:=Set_Tris_E(0x00); //set port E to outputs
:=PORTA = 0;
:=PORTB = 0;
:=PORTC = 0;
:=PORTD = 0;
:=PORTE = 0;
:=
:=/*-----------set PIC registers------------*/
:=ADCON1=0b00001110;
:=INTCON=0b11011000; //set up interrupts and turn them on
:=
:=SETUP_CCP1(CCP_COMPARE_RESET_TIMER);//set to reset TMR1, interrupt
:=SET_PWM1_DUTY(2048); //set the compare reg. to generate a match at 2048 (every .5 sec)
:= //since the clock input is at 4096 Hz
:=SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1); //use external clock
:=
:=/*----------------initialize variables---------*/
:=CompareTimes = 0;
:=matches = 0;
:=oldsec = 0;
:=
:=ENABLE_INTERRUPTS(INT_CCP1);
:=ENABLE_INTERRUPTS(GLOBAL);
:=
:=delay_us(500);
:=lcd_init();
:=lcd_clear();
:=
:=strcpy(line1, "RTCtest"); // copy string
:=lcd_puts(line1);
:=delay_ms(1000);
:=
:=//write to rtc
:=writeRTC(9, 56, 4, 24, 7,3);
:=
:=while(1){
:=
:=//read from rtc
:=readTime(&RTCsec,&RTCmin,&RTChour);
:=
:=//convert time to binary
:=RTCsec=convert2BIN(RTCsec);
:=RTCmin=convert2BIN(RTCmin);
:=RTChour=convert2BIN(RTChour);
:=
:=if (IntStatus\%2 == 1){
:=//if(RTCsec!=oldsec){ //***use this if statement and it works
:=//convert numeric values to strings
:=#asm
:=bcf IntStatus,0
:=#endasm
:=sprintf(seconds,"\%d",RTCsec);
:=sprintf(minutes,"\%d",RTCmin);
:=sprintf(hours,"\%d",RTChour);
:=
:=strcpy(line1, "Time "); // copy string
:=strcpy(colon, ":");
:=
:=//display on LCD
:=lcd_clear();
:=lcd_puts(line1);
:=lcd_puts(hours);
:=lcd_puts(colon);
:=lcd_puts(minutes);
:=lcd_puts(colon);
:=lcd_puts(seconds);
:=
:=}
:=
:=}//end of infinite while loop
:=
:=}//end of main()
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516536 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|