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

Test my code

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



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

Test my code
PostPosted: Sun May 23, 2004 11:02 pm     Reply with quote

Dear All,

I have a nasty suspicion that my programmer is not working, could someone please test my code i.e program a chip:

PCM V3.168
PIC16f874 - USING 4MHz crystal, LCD connected to port D - using ccs drivers.

I can either send the HEX file, the source file


Many thanks for responding
_________________
Best Regards
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

code
PostPosted: Sun May 23, 2004 11:24 pm     Reply with quote

Code:


#if defined(__PCM__)
#include <16F874.h>
#device ICD=TRUE
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOPUT,NOBROWNOUT
#use delay(clock=4000000)
#endif

#include <lcd.c>




#byte INTCON = 0x0b


int sec=0; //second
int min=0;//minute
int hrs=0; //hour
int milli=0;
int increment = 0;
int flag=0;
int data=0;


void display()
   {   
       lcd_init();     
      if (flag==1)
      {
         lcd_gotoxy(0,1);
         printf(lcd_putc,"%02U:%02U",hrs,min);      
      }
      else
      {
         lcd_gotoxy(1,1);
         printf(lcd_putc,"%S",data);   
      }   
   }   
#int_rtcc
void clock_isr()
{
    increment++;
   if (increment==2)
   {   milli++;
      increment=0;
   }
   if (milli==10) // 10*100ms = 1second passed
   {
      sec++;
      milli=0;
   }   
   if (sec==60) // 60*1sec = minute
   {
       sec=0;
       min++;
       flag=1;
   }
   if (min==60)
   {
      min=0;
       hrs++;
      flag=1;
   }
   
   if ((hrs==24) || (hrs && min==0)) //24:00 - reset all variables and place 0:00
   {
      sec=0;
      hrs=0;
      flag=1;
   }
   if (milli < 10) //milli lower than 10 exit after incrementing milli
      set_RTCC(60); //setup TMR0 to count upto 100ms
      
}   


   
   



void main()
{
   INTCON = 0xa0;
   
   setup_counters(RTCC_INTERNAL,RTCC_DIV_256);

   set_RTCC(60);
   
   
   while(1)
   {
      if (flag)
      {
         display();
         flag=0; // clear new data flag
      }
   

   }
   



}


THANK YOU[/code]
_________________
Best Regards
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

Function
PostPosted: Mon May 24, 2004 12:32 am     Reply with quote

The above progrsam is a simple implementation of a "Real time clock"

I have tried to programming it myself,
but unfortunalty I get unexpected results
_________________
Best Regards
ckielstra



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

View user's profile Send private message

PostPosted: Mon May 24, 2004 1:38 am     Reply with quote

What "unexpected results" do you get? Can you be more specific?

Code:
if ((hrs==24) || (hrs && min==0)) //24:00 - reset all variables and place 0:00

This looks suspicious; every hour (except 0:00) you will reset all variables.

Also you call Display only when flag==1, so in Display() you will only display the time. never the line with Data.


Last edited by ckielstra on Mon May 24, 2004 1:52 am; edited 1 time in total
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

PostPosted: Mon May 24, 2004 1:45 am     Reply with quote

After I have programmed the PIC and pressed reset it takes about
8 seconds for the program to start, when it does start the seconds go
twice as slow

I have calculated that an interrupt should occur every 49ms, my clock
increments every 2 ISR calls i.e 100ms

I have checked clock, PSU, connectivity,LCD

I have not enabled the powerup timer

Regards
_________________
Best Regards
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Mon May 24, 2004 7:36 am     Reply with quote

Why call lcd_init() each time you run display()? lcd_init() should be called once near the start of your main()

Ignore the LCD for the moment and ignore your clock variable values. You say it is running too slow? Check your crystal value, check your capacitors (or your resonator as the case may be). Is it correct? You indicate a 4MHz crystal and you have the XT fuse which is correct. Use an oscilloscope and x10 probe to check that the oscillator is running. Probe OSC2 which I believe is the "driven" pin but check the PIC data sheet to be sure. You can probe either pin but probing the non-driven pin is more likely to affect the measurement.

Use one of your I/O pins as an output and each time through your interrupt toggle the pin's state. Use an oscilloscope to check that it is running at the correct speed.

Something else to check. Turn off your interrupt and modify your main() to call display() over and over and over. Add two lines to your display() code for this test. First instruction in the subroutine should set that pin high. Last instruction before leaving the subroutine should set that pin low. Use your oscilloscope to time how fast the routine is running. Is it taking longer than the interrupt period? Alternatively you could look at the LST file and count cycles but this is faster. There is a little bit of error associated with the overhead of toggling the pin, 2 cycles if you are using fast I/O, 8 (I think) if you are using standard i/o
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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