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

Need help for 12F675

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



Joined: 06 Apr 2017
Posts: 2

View user's profile Send private message

Need help for 12F675
PostPosted: Fri Apr 07, 2017 12:05 am     Reply with quote

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();
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 1:09 am     Reply with quote

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...
jacko_0417



Joined: 06 Apr 2017
Posts: 2

View user's profile Send private message

PostPosted: Fri Apr 07, 2017 1:43 am     Reply with quote

hi Ttelmah
thank you very much.
your info Very helpful with me.
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