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

pic microcontroller 16f887

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



Joined: 20 Oct 2013
Posts: 4

View user's profile Send private message Yahoo Messenger MSN Messenger

pic microcontroller 16f887
PostPosted: Sun Oct 20, 2013 9:55 am     Reply with quote

Please I have problem with this project I am working on. I want to know if I miss something in the code. Its working fine on Proteus but the display is not working fine on board.
Code:

#include <16F887.h>
#use delay(clock=20000000)
#fuses XT,NOWDT,NOLVP
#use rs232(baud=9600,xmit =PIN_C6, rcv = PIN_C7)
#include "lcd.c"

//RTC variables
#define XTAL_FREQUENCY  4000000
#define TIMER1_FREQUENCY (XTAL_FREQUENCY / 4) // 1 clock tick = 1 instr. cycle = crystal frequency / 4
int32 Ticker;
int8 Seconds=0;

int8 Year=13,Month=06,Days=24,Hours=23,Minutes=55;

// Test whether a given year is a leap year.
#define IS_LEAP(year) (year%4 == 0)

//    Initialize RTC
void Initialize_RTC(void)
{
  Ticker = TIMER1_FREQUENCY;                  // initialize clock counter to number of clocks per second
  setup_timer_1( T1_INTERNAL | T1_DIV_BY_1 ); // initialize 16-bit Timer1 to interrupt
                                              // exactly every 65536 clock cycles
                                              // (about 76 times per second)
  enable_interrupts( INT_TIMER1 );            // Start RTC
}

#int_TIMER1
void TIMER1_isr()
{
  Ticker -= 65536;                        // Decrement ticker by clocks per interrupt
  if ( Ticker < 65536 )                   // If second has expired
  {  Ticker += TIMER1_FREQUENCY;          //   Increment ticker by clocks per second
     seconds++;                           //   Increment number of seconds
  }

  if(Seconds == 60) {Minutes++; Seconds=0;
    if(Minutes == 60) {Hours++; Minutes=0;
      if(Hours == 24) {Days++; Hours=0;
        if (  (Days == 29 && Month==2 && !IS_LEAP(Year))
           || (Days == 30 && Month==2)
           || (Days == 31 && (Month==4 || Month==6 || Month==9 || Month==11 ))
           || (Days == 32)
           ) {Month++;Days=0;}
        if(Month == 13) {Year++; Month=0;}
  }}}
}

void main()
{
  int8 prev_second;
  Initialize_RTC();
  enable_interrupts( GLOBAL );
   lcd_init();
  // loop forever
  while(true)
  {
    if (seconds != prev_second)
    {
      prev_second = seconds;
      lcd_gotoxy(2,1);
      printf(lcd_putc,"Date:");
      lcd_gotoxy(7,1);
      printf(lcd_putc," %d:%d:%d \r\n",Days,Month,Year);

      lcd_gotoxy(2,2);
      printf(lcd_putc,"Time:");
      lcd_gotoxy(7,2);
      printf(lcd_putc," %d:%d:%d \r\n",Hours,Minutes,seconds);
    }
  }
}

http://www.youtube.com/watch?v=IV1s6n1Apt0
http://www.microscale-embedded.com/blog/?p=157#comment-362
_________________
ALWAYS TRUST IN GOD.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 10:13 am     Reply with quote

In the video it looks like it is working properly then something changes
but you dont indicate what you are doing when the display messes up.

It is working and then goes crazy so offhand it looks like a
connection problem if I were to make a wild guess.
_________________
Google and Forum Search are some of your best tools!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 10:33 am     Reply with quote

Quote:
but the display is not working fine on board.

Look closely at your program. It's packed full of inconsistencies.
For example, you have #use delay() set for 20 MHz, presumably because
your board has a 20 MHz crystal on the PIC. But then you use an XT
oscillator fuse. But the PIC data sheet says to use HS for 20 MHz.
The 20 MHz crystal won't run with an XT fuse. It runs on Proteus
because Proteus doesn't care about oscillator fuses. Real boards really care:
Quote:
#include <16F887.h>
#use delay(clock=20000000)
#fuses XT,NOWDT,NOLVP
#use rs232(baud=9600,xmit =PIN_C6, rcv = PIN_C7)
#include "lcd.c"


Again, in the code below you have an oscillator speed mistake. Your
#use delay() is set for 20 MHz, but your #define for Xtal (means crystal)
frequency is set for only 4 MHz. Fix it.
Quote:
//RTC variables
#define XTAL_FREQUENCY 4000000
#define TIMER1_FREQUENCY (XTAL_FREQUENCY / 4) // 1 clock tick = 1 instr. cycle = crystal frequency / 4
int32 Ticker;
int8 Seconds=0;
uthman77



Joined: 20 Oct 2013
Posts: 4

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sun Oct 20, 2013 3:19 pm     Reply with quote

THANKS FOR YOUR FEED BACKS @PCM PROGRAMMER, U MEAN I SHOULD DELETE THE #FUSE LINE OF THE CODE AND ALSO CHANGE BOTH DELAY TO 4MHZ?
_________________
ALWAYS TRUST IN GOD.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 3:23 pm     Reply with quote

Post a link to the website for your PIC board (the website of the manufacturer of your board).
uthman77



Joined: 20 Oct 2013
Posts: 4

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sun Oct 20, 2013 3:28 pm     Reply with quote

YOU MEAN THE MANUFACTURER OF MY BREAD BOARD IF YOU DONT MIND LET ME HAVE YOUR MAIL ITS EASIER TO SEND YOU THE CIRCUIT DIAGRAM AND EVERYTHING..PLEASE I WILL BE VERY GLAD.
_________________
ALWAYS TRUST IN GOD.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 20, 2013 3:50 pm     Reply with quote

I'm not giving out my email.

Just look at your board and see if your board has a crystal for the PIC.
If it has a crystal, read the frequency on the crystal and post it here.
uthman77



Joined: 20 Oct 2013
Posts: 4

View user's profile Send private message Yahoo Messenger MSN Messenger

PostPosted: Sun Oct 20, 2013 3:56 pm     Reply with quote

if u are asking the value of the crystal i used i use a crystal of 4khz it was written on it sjk 4.000...i think now i figure out a mistake am supposed to use 4mhz.
_________________
ALWAYS TRUST IN GOD.
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