View previous topic :: View next topic |
Author |
Message |
Khansokhua
Joined: 06 Nov 2021 Posts: 92
|
PIC16F877A at 20MHz |
Posted: Tue Jan 17, 2023 12:02 pm |
|
|
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
|
|
Posted: Tue Jan 17, 2023 12:32 pm |
|
|
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
|
|
Posted: Tue Jan 17, 2023 1:17 pm |
|
|
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. |
|
|
|