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

PIC16F877A at 20MHz

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



Joined: 06 Nov 2021
Posts: 92

View user's profile Send private message

PIC16F877A at 20MHz
PostPosted: Tue Jan 17, 2023 12:02 pm     Reply with quote

It may be ridiculous question but I am stuck.
Code:
#include <16F877A.h>
#fuses xt, NOWDT, BROWNOUT, NOPROTECT, NOLVP, NOPUT
#use delay(clock=4M)
#use standard_io(D)
void main()
{
  set_tris_d(0x00);
  output_d(0x00);

   while(TRUE)
   {
      output_high(pin_D0);
      delay_ms(1000);
       output_low(pin_D0);
      delay_ms(1000);
   }

}

This example code works at 4 MHz.

When I try this
Code:
#include <16F877A.h>
#fuses HS, NOWDT, BROWNOUT, NOPROTECT, NOLVP, NOPUT
#use delay(clock=20M)
#use standard_io(D)
void main()
{
  set_tris_d(0x00);    //JUST REPLACED 'XT' WITH 'HS' AND '4M' WITH '20M'
  output_d(0x00);

   while(TRUE)
   {
      output_high(pin_D0);
      delay_ms(1000);
       output_low(pin_D0);
      delay_ms(1000);
   }

}


same code does not work at 20MHz.
If crystal is ok then what can be problem?

using 2x22pF capacitor with both crystal
PrinceNai



Joined: 31 Oct 2016
Posts: 479
Location: Montenegro

View user's profile Send private message

PostPosted: Tue Jan 17, 2023 12:32 pm     Reply with quote

When I go with the wizard and 20MHz crystal, the only setup for clock is this:

Code:

#use delay(crystal=20000000)


and from help:

Code:

#use delay(clock=20M, crystal)


This should set the fuses correctly.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 17, 2023 1:17 pm     Reply with quote

Possible reasons for it working at 4 MHz but not at 20 MHz:

1. You have the "LF" version of the PIC.
2. You are missing the 0.1 uF ceramic caps on each Vdd pin to ground.
3. You really have a 16F877 and the part number on it says PIC16F877-04.
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