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 support@ccsinfo.com

pic 18F4550 - ccs-PCB - timer0

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Louati



Joined: 26 Mar 2012
Posts: 16

View user's profile Send private message

pic 18F4550 - ccs-PCB - timer0
PostPosted: Sat Sep 08, 2012 2:43 am     Reply with quote

Hello,
I'm testing the timer0 of my pic 18f4550 by toggling the pin_B7 each 1.6384 second but the program didn't work !
The code:


#include <18f4550.h>
#FUSES NOWDT
#FUSES WDT128
#FUSES PLL1
#FUSES CPUDIV1
#FUSES NOUSBDIV
#FUSES INTRC_IO
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES BORV27
#FUSES NOVREGEN
#FUSES NOPBADEN
#FUSES NOLPT1OSC
#FUSES NOMCLR
#FUSES NOLVP
#FUSES NOXINST
#use delay(clock=8000000)
//
#byte portb = 0xF81
#byte trisb = 0xF93
//

int i=0;

#INT_TIMER0
void v_x()
{
i++;
if (i==50) {output_toggle(PIN_B7); i=0;}
}

void main()
{
portb=0;
trisb=0;
setup_timer_0(T1_INTERNAL);
setup_timer_0(T0_DIV_256);
setup_timer_0(8);
enable_interrupts(INT_TIMER0);
whiel(1);
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 08, 2012 6:10 am     Reply with quote

First a few comments:
1) When posting code, please use the 'code' buttons. This will help to preserve the formatting of your code and makes for easier reading.
2) Please only post tested code.
Code:
whiel(1);
This doesn't compile so we know for sure it is not the code you have tested with.
3) Always post your compiler version number
4)
Code:
#byte portb = 0xF81
#byte trisb = 0xF93
These lines can be left out as with CCS the compiler will manage the TRIS register for you, unless you disable this by specifying '#USE FAST_IO'. It is best to have the compiler handle the TRIS register as it keeps your program code smaller and easier to port to other processors where the addresses may be different. Only when memory usage or speed is critical you should manage the TRIS registers yourself.

Now the real problems in your code:
5)
Code:
setup_timer_0(T1_INTERNAL);
Where did this come from? You are using a define for Timer1 in the Timer0 setup!?!?!? Replace by RTCC_INTERNAL. Yes, I know it is stupid that it isn't called T0_INTERNAL, or perhaps this has been fixed in one of the newer compiler versions? I'm still at 4.077
6) Setting up timers is to be done in one call, not in 3 calls. Replace:
Code:
setup_timer_0(T1_INTERNAL);
setup_timer_0(T0_DIV_256);
setup_timer_0(8);
by:
Code:
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);

7) You forgot to enable the global interrupt flag. Add the following line to your code (after the Timer0 enable):
Code:
enable_interrupts(INT_TIMER0);
enable_interrupt(GLOBAL);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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