View previous topic :: View next topic |
Author |
Message |
lychek Guest
|
I need example code ( blink led ) for 12f675 with int. osc |
Posted: Mon Feb 14, 2005 4:27 am |
|
|
Hi every body,
I'm a new user in PIC. i want to start with PIC12f675 and i try to write the program for only blink the led with internal oscillator. but cannot work.
If any body has an this example please send to me.
thank |
|
|
Guest
|
|
Posted: Mon Feb 14, 2005 8:36 am |
|
|
Why don't you start with the mid range PIC, there are plenty of forum for
the mid-range PIC in here so it will help you better understand the PIC
with more examples that people has posted here. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Feb 14, 2005 10:40 am |
|
|
Better idea, why not post your code so people can tell you where you went wrong. |
|
|
lychek Guest
|
|
Posted: Tue Feb 15, 2005 11:07 pm |
|
|
Hi,
This is source code that i try to compile and test with PIC12f675
#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#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 init()
{
set_tris_a( 0b11100001 ); // set GP0 output, all other inputs
setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D
}
main()
{
init();
output_low( GP2 ); // set low
output_low( GP3 ); // set low
output_low( GP4 ); // set low
while ( TRUE ) // blink LED
{
output_high( GP1 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP1 ); // turn LED off
delay_ms( 250 ); // wait 250ms
}
}
No error when i compile this code with ccs, but when i test with ic PIC 12f675 no signal at pin GP1.Could you tell me what wrong with this source code ?
Could you explain me how to set internal oscillator and for 4Mhz exactly ?
thank you
lychek |
|
|
Paolino
Joined: 19 Jan 2004 Posts: 42
|
|
Posted: Wed Feb 16, 2005 4:14 am |
|
|
In my opinion, if GP0 is the blinking output your code should be:
set_tris_a( 0b11110 ); // set GP0 output, all other inputs
Try like this and let us know.
Paolo. |
|
|
lychek Guest
|
|
Posted: Wed Feb 16, 2005 6:51 am |
|
|
Hi
i set set_tris_a( 0b11111110 ); // set GP0 input, all other outputs
and i try to blink the led at pin GP1 and GP2 GP3 GP4 is to low. After i test it the result is wrong ( GP1 is not blink and GP3 is High.
i try to change the set_tris_a( 0b11000001 ); // set GP0 output, all other inputs like u told me and the result is the same( GP0 is not blink)
Do you have an other idea or code example for blink the led with use intenal oscillator?
Thank you
KEO Lychek |
|
|
Guest
|
|
Posted: Wed Feb 16, 2005 10:15 am |
|
|
"set_tris_a( 0b11111110 ); // set GP0 input, all other outputs "
set_tris_a(........GP4, GP3, GP2, GP1, GP0)
and 1 = input
0 = output
if you want GP0 as intput and all others output
set_tris_a( 0b00000001 ); |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Wed Feb 16, 2005 1:13 pm |
|
|
Your original code looked fine (your comments were off though). One thing to note is that GP3 is only an input so you can not use it as an output. The following modification should blink your LED on GP1 (modified from your code):
Code: |
#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#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 init()
{
set_tris_a( 0b11111101 ); // set GP1 output, all other inputs
setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D
}
main()
{
init();
while ( TRUE ) // blink LED
{
output_high( GP1 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP1 ); // turn LED off
delay_ms( 250 ); // wait 250ms
}
}
|
If this does not work, what compiler version are you using?. You should look at the listing to make sure the ADC and COMPARATOR functions are being turned off (CMCON = 7, ANSEL = 0). The compiler may not be doing its work.
Finally (and I have to ask this), is the LED connected through a resistor and directly to ground with the proper polarity (or is it connected to another GPIO or something else). Just make sure that toggling GP1 will have the desired effect on the electronics (the PICKit, for example, can cause some confussion with its array of LEDs).
Let us know how you do. |
|
|
lychek Guest
|
|
Posted: Thu Feb 17, 2005 10:48 pm |
|
|
Hi,
I try to compile this code but it doesn't work. but when i delete intrc_io and compile again, it is working.
the code is:
#include <12F675.h>
#device ADC=10
#fuses NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#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 init()
{
set_tris_a( 0b11111101 ); // set GP1 output, all other inputs
setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D
}
main()
{
init();
while ( TRUE ) // blink LED
{
output_high( GP1 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP1 ); // turn LED off
delay_ms( 250 ); // wait 250ms
}
}
Compiler that i use is PCWH Compiler
IDE version 3.43
PCB version 3.204
PCM version 3.204
PCH version 3.204
After i compile this code, i use icprog to tranfer to ic and i change the oscillator to INTOSC GP4 manually the result is working properly.
When i set the fuse like that #fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR and then i open icprog the oscillator is set to INTOSC GP4 automatically, the result doesn't work.
Do you know this problem? is from compiler?
Thank you very much |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
Lost Oscillator Calibration? |
Posted: Fri Feb 18, 2005 1:58 pm |
|
|
Maybe the internal oscillator calibration is lost. Can you read this back from ICPROG?
You could modify the code as follows and see if it works. If it does, the oscillator calibration is most likely lost.
Code: | #include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#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
#byte OSCCAL = 0x90
void init()
{
OSCCAL = 0x80; // set internal oscillator to mid frequency
set_tris_a( 0b11111101 ); // set GP1 output, all other inputs
setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D
}
main()
{
init();
while ( TRUE ) // blink LED
{
output_high( GP1 ); // turn LED on
delay_ms( 250 ); // wait 250ms
output_low( GP1 ); // turn LED off
delay_ms( 250 ); // wait 250ms
}
} |
There have been a few threads on this:
http://www.ccsinfo.com/forum/viewtopic.php?t=21576&highlight=osccal+rom |
|
|
lychek Guest
|
|
Posted: Sun Feb 20, 2005 8:16 am |
|
|
Hi,
I can read the code from ic using icprog.
I try to test ur code that u give me, the led doesn't blink. it's still have problem. How to calibrate the internal oscillator?
Thank |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Feb 20, 2005 9:31 am |
|
|
Check the last location and see if it is a retlw instruction. If not, then it is gone. The programmer protects this last location and won't allow you to program it. I have fooled the programmers in the past by specifying a chip that has more memory and then putting a value in there at the correct memory location. |
|
|
Guest
|
Re: I need example code ( blink led ) for 12f675 with int. o |
Posted: Wed Aug 03, 2005 5:37 pm |
|
|
lychek wrote: | Hi every body,
I'm a new user in PIC. i want to start with PIC12f675 and i try to write the program for only blink the led with internal oscillator. but cannot work.
If any body has an this example please send to me.
thank |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Aug 03, 2005 5:53 pm |
|
|
Mark wrote: | Better idea, why not post your code so people can tell you where you went wrong. |
|
|
|
Guest
|
Re: I need example code ( blink led ) for 12f675 with int. o |
Posted: Tue Dec 20, 2005 3:31 pm |
|
|
lychek wrote: | Hi every body,
I'm a new user in PIC. i want to start with PIC12f675 and i try to write the program for only blink the led with internal oscillator. but cannot work.
If any body has an this example please send to me.
thank |
|
|
|
|