![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jacko_0417
Joined: 06 Apr 2017 Posts: 2
|
Need help for 12F675 |
Posted: Fri Apr 07, 2017 12:05 am |
|
|
Hi everybody,
I'm a new user in PIC. I use PIC12f675 and i try to write the program for turn on led with internal oscillator. But can't work.
I use PCWHD compiler.
Anybody can help me modify it?
Thanks.
When GP2 switch on(0V)-> GP0.GP1 output high 1 minute.
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( 0b11111100 ); // 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
}
void led_on (void)
{
output_high (GP0);
output_high (GP1);
delay_ms (18000);
}
void led_off (void)
{
output_low (GP0);
output_low (GP1);
delay_ms (180);
}
void main()
{
int1 x1;
x1 = INPUT(PIN_A2);
while (TRUE)
{
if (x1==0)
led_on();
else
led_off();
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19384
|
|
Posted: Fri Apr 07, 2017 1:09 am |
|
|
First, you don't want/need to be writing to OSCCAL.
OSCCAL is automatically loaded from a value stored in the chip. If this has been erased, the chip may not boot at all (it'll jump to the stored value, and what happens then depends on what is at this location...).
Always when debugging you need to work on one thing at a time. So the first thing to test is:
Code: |
#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(INTERNAL=4000000)
//Using 'internal' tells the compiler to do the setup for the internal oscillator
void main(void)
{
//Test the chip is actually working
while (TRUE)
{
output_toggle(PIN_A0);
delay_ms(1000);
}
}
|
Now this is known as the 'flash an LED' test.
It is a simple program to just flash an LED (in this case on pin A0).
This tells you straight away a whole suite of things:
1) If it doesn't work at all, your chip is not working. Could be:
a) Incorrect wiring.
b) Damaged chip.
c) The stored OSCCAL value has been erased.
If you suspect 'c', then look at this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=45467&highlight=osccal>
Which shows how to write the middle value back to the chip.
Some programmers have in their software an option to automatically generate a new value for this.
2) If it does work, it tells you you have your oscillator settings right if the LED flashes at the right rate.
3) Only once you have got your chip working, move on to actually trying to write your code.
Now there are some comments about this:
You refer to one minute, but have 18000mSec (180 seconds -> 3 minutes)...
You have an 'init' routine that is never called (not actually needed, but keeping things tidy is always better).
You read the input once. Outside the loop. So unless the input is actually high/low at the moment you switch the chip on, the read will be missed... |
|
![](templates/subSilver/images/spacer.gif) |
jacko_0417
Joined: 06 Apr 2017 Posts: 2
|
|
Posted: Fri Apr 07, 2017 1:43 am |
|
|
hi Ttelmah
thank you very much.
your info Very helpful with me. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|