|
|
View previous topic :: View next topic |
Author |
Message |
karthickiw
Joined: 09 Aug 2007 Posts: 82 Location: TN, India
|
problem with 12F675 internal clock setting.. |
Posted: Tue Feb 19, 2008 11:09 am |
|
|
Hello,
i write the program for LED bilking using PIC12F675. i use internal clock and connect the LED in GP0 through the resister.
This is my program,
Code: | #include <12f675.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,INTRC, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
void main(void)
{
set_tris_a(0b00000001);
while (1) {
output_HIGH(GP0);
delay_ms(500);
output_LOW(GP0);
delay_ms(500);
}
} |
but LED don't on... i don't know what is problem ? please help me...
*i am using 5 volt SMPS for power supply. |
|
|
Audi80
Joined: 07 Sep 2007 Posts: 41
|
|
Posted: Tue Feb 19, 2008 11:23 am |
|
|
Hi there the first thing to do is to look at your device header file and see if the setup_oscillator(OSC_4MHZ) option exists if it does set the oscillator to de desired frequency. And check if the led is well polarized.
Code: |
setup_oscillator(OSC_4MHZ);
|
In the beginning of the main();
i´d advice you to use the 32Mhz i belive it´s better. Hope it helps |
|
|
bwhiten
Joined: 26 Nov 2003 Posts: 151 Location: Grayson, GA
|
|
Posted: Tue Feb 19, 2008 12:28 pm |
|
|
You have the TRIS set up backwards I think. A 1 indicates an input and a 0 indicates an output, so pin A0 is set up as an input. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 19, 2008 12:41 pm |
|
|
Quote: | I´d advice you to use the 32Mhz i belive it´s better |
The 12F675 internal oscillator only runs at 4 MHz. This is in the data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/41190E.pdf
Quote: | see if the setup_oscillator(OSC_4MHZ) option exists |
It does not exist. The internal oscillator is selected with the #fuses
statement. It can't be changed at run-time.
Quote: | You have the TRIS set up backwards |
That's correct, but it won't have any effect on his program because
he has not specified fast i/o mode. The output_low() and output_high()
statements will be compiled into ASM code that sets the correct TRIS
before setting the pin to high or low.
Post your compiler version. In earlier versions there were two or
three bugs that could make your program fail to work. There are
work-arounds available, if that is the case. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 19, 2008 10:21 pm |
|
|
In your version (3.185), the start-up code inserted by the compiler is
not correct. It doesn't setup the ADCON and CMCON registers properly.
Try the following program. It turns off the comparator and the A/D
with two lines of code.
Code: | #include <12F675.h>
#device adc=8
#fuses INTRC_IO, NOWDT, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5
//========================
void main()
{
setup_comparator(NC_NC);
setup_adc(ADC_OFF);
while(1) {
output_HIGH(GP0);
delay_ms(500);
output_LOW(GP0);
delay_ms(500);
}
} |
|
|
|
Ttelmah Guest
|
|
Posted: Wed Feb 20, 2008 3:18 am |
|
|
What is the 'history' of the PIC?.
One possibility is that the chip may have been fully erased. The internal oscillator, is dependant on having the top location in the ROM, containing a single 'RETLW' instruction, which contains the adjustment value for the clock. The compiler automatically inserts a call to this location into the code. If the location has been erased, this will result in the code never executing...
Most programmers have an option to 'protect' this location (in fact they simply save it, and then write it back). This must be enabled.
Read the chip,with your programmer. Look at what value is stored in this top location. If it reads 34xx, then this is not the problem. If the '34' is not there, this is the problem. In this case, you can put a value 'back', by adding a #ROM statement to your code. The result will be that the clock will be less accurate (since it won't have the factory adjusted value), but at least it'll run.
The location is 0x3FF, and a value of '80' hex, is the best starting point (0x3480 as the instruction).
Best Wishes |
|
|
|
|
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
|