View previous topic :: View next topic |
Author |
Message |
smiles
Joined: 20 Feb 2008 Posts: 33
|
My problem Timer 0 |
Posted: Wed Feb 27, 2008 9:54 am |
|
|
Hi! My crystal is 4MHz, I have a relay connected with PIN_C0 (PIC16F877A)
Here is my code, I intend to wait for 2 seconds by timer and then interrupt will activate the relay, then delay 2 seconds again and deactivate relay, this thing will repeat and repeat (ok and it's not like I expect, nothing happen, my hardware is okay)
Code: |
int count;
#int_RTCC
void RTCC_isr()
{
set_timer0(6);
if (count==2000)
{
output_high(PIN_C0);
delay_ms(2000);
count=0;
}
else
count++;
}
//**********************
void main()
{
// TODO: USER CODE!!
InitPic();
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
count=0;
do
{
output_low(PIN_C0);
}
while(1);
}
//**********************
void InitPic()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_4);
output_b(0x00);
output_d(0x00);
}
//**********************
|
Could you tell me where I am wrong, thanks ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 27, 2008 12:48 pm |
|
|
Quote: | int count;
#int_RTCC
void RTCC_isr()
{
set_timer0(6);
if (count==2000)
{
|
Download the CCS manual:
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
Go to page 49 in the Acrobat reader (page 37 in the manual).
It has a table of data types, and their sizes. What is the size
of an 'int' in CCS ? Can you compare it to 2000 ? |
|
|
smiles
Joined: 20 Feb 2008 Posts: 33
|
|
Posted: Wed Feb 27, 2008 7:51 pm |
|
|
Oh I forgot, I will repair it |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Feb 28, 2008 1:59 am |
|
|
I hope your program isn't intending on doing anything else.
Having that delay_ms(2000); in the ISR will stop anything else from running.
Even if this is the only code in your PIC you may want to revise the way you do this as it is bad practice. |
|
|
|