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

Problem with PIC16F72 WDT Program ..

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



Joined: 16 Sep 2008
Posts: 7

View user's profile Send private message

Problem with PIC16F72 WDT Program ..
PostPosted: Thu Sep 18, 2008 1:04 am     Reply with quote

Dear Friends,,
I'm using CCS C compiler for PIC16F72.

I've written code to implement WDT, but after compiled there are 2 warnings came out and i burnt the program into MCU and fixed on machine, nothing was running at all.


>>>Warning 206 Line 105(1,1): Variable of this data type is never greater than this constant

>>>Warning 204 Line 106(1,1): Condition always FALSE

Line 105 and 106 were highlighted in below code.

I don't know where goes wrongly, below is my code.

I sincerely appreciate your prompt help.

Code:

#include <16F72.h>
#fuses RC,WDT,PROTECT

#use delay(clock=4000000)

/*###################################################################################
// define input & output
###################################################################################*/

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)

#byte PortA = 0x05
#byte PortB = 0x06
#byte PortC = 0x07
#byte TMR0 = 0x01
#byte INTCON = 0x8B
#byte ADCON1 = 0x9F
#byte ADCON0 = 0x1F
#byte STATUS = 0x83

#bit iSTH    = PortA.0     
#bit iCTH    = PortA.1     
.
.
.

/*##############################################
// Timer Defines
###############################################*/

#define RTCC_PRELOAD (256 - 39)

#define UVLight_TIMER_TICKS         10  // 100ms
#define PUMP_TIMER_TICKS            10  // 100ms
#define ProduceWater_TIMER_TICKS    10  // 100ms
#define Display_TIMER_TICKS         10   // 100ms

// GLOBALS
int GC_UVLight_timer;
int GC_PUMP_timer;
int GC_ProduceWater_timer;
int GC_Display_timer;
unsigned int cnt = 0;         

#define INTS_PER_SECOND 100
int int_count;

int16 FAN_Seconds=0;
int16 UVOn_Seconds=0;
int16 UVOff_Seconds=0;

/*##############################################
// WDT   
###############################################*/

void interrupt()
{
   cnt++;
   TMR0   =  96;                //   on time
   INTCON = 0x20;
   if(cnt > 65534)     // ======Line 105======
   {                         // ======Line 106======
       cnt = 0;
   }
}
.
.
.
.
.
.
void main()
{
   STATUS &= 0x9F;       
   PortA=0;
   PortB=0;
   PortC=0;         
   STATUS &= 0xBF;   
   TMR0  = 96;       
   cnt = 0;         
   
 

   ADCON1  = 6; 
   set_tris_A(0b00001011);
   set_tris_b(0b10000000);
   set_tris_c(0b00000000);       
   STATUS &= 0x9F;               
   ADCON0  = 0;           

///////////////////////////////////////////////////
   // Initialize the software timers for each task. //
   ///////////////////////////////////////////////////
   
   GC_UVLight_timer        = UVLight_TIMER_TICKS ;
   GC_ProduceWater_timer   = ProduceWater_TIMER_TICKS;
   GC_PUMP_timer           = PUMP_TIMER_TICKS;
   GC_Display_timer         = Display_TIMER_TICKS;     
   fUVIsDone=0;
   fUVOn60SecDone=0;
   fUVOn120SecDone=0;
   int_count = INTS_PER_SECOND;

   ////////////////////////////////////
   //     Setup the RTCC/ Timer0     //
   ////////////////////////////////////
   
   setup_counters(RTCC_INTERNAL, RTCC_DIV_256);
   set_rtcc(RTCC_PRELOAD);
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
 
   while(true)
   {
      check_ProduceWater();
      check_Pump();
      check_UVLight();
      check_Display();

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 18, 2008 1:27 am     Reply with quote

There is a problem with your understanding of the size of an 'int' in CCS.
Look in this section in the CCS manual. It has a table on the data types:
Quote:
Basic and Special types

http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

Don't attempt to set the bank select bits. The compiler will do it.
Get rid of all the lines where you write to the STATUS register.

There is no need to write directly to the INTCON register.
CCS has functions to enable/disable interrupts.

If you want a more reliable program, use the CCS functions instead
of writing directly to registers. It's much easier to write the code.
There will be less mistakes. If you use the CCS functions, you don't
even need to set the TRIS. The compiler will handle it for you.
To do that, you need to also remove the fast_io() lines.
brett777_L



Joined: 16 Sep 2008
Posts: 7

View user's profile Send private message

PostPosted: Thu Sep 18, 2008 9:51 pm     Reply with quote

Thank you PCM, i've change "int" to "int16"..

but i still don't understand
Quote:

Don't attempt to set the bank select bits. The compiler will do it.
Get rid of all the lines where you write to the STATUS register.

There is no need to write directly to the INTCON register.
CCS has functions to enable/disable interrupts.


You got any example code can show me ? thanks a lot.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 18, 2008 10:25 pm     Reply with quote

There is sample code in most of the topics on this forum.
There is sample code in the Code Library forum.
There is sample code in the CCS Examples and the Drivers directories
on your hard disk.

You will not see any sample programs that change the STATUS register
to select the RAM banks. CCS does it automatically.

I suggest that you start with a simple program that blinks an LED.
Guest








PostPosted: Sun Sep 28, 2008 8:09 pm     Reply with quote

This is my first time to use CCS, i still don't understand why i can't do like this :

#define STATUS = 0x03
#byte STATUS = 003
#byte TMR0 = 0x11
#byte ADCON0 = 0x1F

If it is not suggested , any other ways ?

I used this way in mikro C before..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 28, 2008 8:19 pm     Reply with quote

You can write directly to registers with CCS, but don't try to set the
bank select bits in the 16F PICs, like you're doing here:
Quote:
void main()
{
STATUS &= 0x9F;
PortA=0;
PortB=0;
PortC=0;
STATUS &= 0xBF;
TMR0 = 96;
cnt = 0;


The CCS compiler will select the correct bank for you. Let the compiler
do it.
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