Page 1 of 1

Problem with 12F683 and MikroC

Posted: 19 Aug 2013 08:12
by netomx
Hello. I'm getting here because I'm desesperate. I can't make my code work! :@

MikroC v6.0

Code:

Code: Select all

//unsigned temp;
//char error = 0;
//sbit error_led at GP2_bit;

void Init() {
     TRISIO = 0;
     GPIO = 0;
     CMCON0 = 1;
     ANSEL = 0;


     //error = Soft_UART_Init(&GPIO, 0, 1, 9600, 0);
     //if (error > 0)
     //    while (1) {
     //         error_led = ~error_led;
     //         Delay_ms(1000);
     //   }
}

void main() {
     Init();
     while (1) {
         //Ow_Reset(&GPIO, 4);                         // Onewire reset signal
         //Ow_Write(&GPIO, 4, 0xCC);                   // Issue command SKIP_ROM
         //Ow_Write(&GPIO, 4, 0x44);                   // Issue command CONVERT_T
         //Delay_ms(750);
         //Ow_Reset(&GPIO, 4);
         //Ow_Write(&GPIO, 4, 0xCC);                   // Issue command SKIP_ROM
         //Ow_Write(&GPIO, 4, 0xBE);                   // Issue command READ_SCRATCHPAD

         //temp =  Ow_Read(&GPIO, 4);
         //temp = (Ow_Read(&GPIO, 4) << 8) + temp;
         //temp = 0x40;
         //Soft_UART_Write(temp);
         GP5_bit = ~GP5_bit;
         Delay_ms(500);
     }
}
NOTE: Yes, it is commented because I am soo desesperate, I'm just trying to make a LED blink :(

Config:

INTOSCIO
All disabled (except Fail-Safe Monitor)
8 MHz
5Volts in Vcc

Connections:

Vcc: 5V
Vss: Ground
GP2: Led to ground


Any clues?

Re: Problem with 12F683 and MikroC

Posted: 19 Aug 2013 16:53
by hexreader
Your code works, but at the wrong frequency.

If it does not work for you, then I guess you have a hardware problem or your configuration bits are set incorrectly.
8 MHz
Default internal clock frequency is 4 MHz, not 8.

Check out the OSCCON register in the datasheet to see how to set other frequencies.
GP2: Led to ground
Never connect an LED directly to ground. Add a series resistor (330 Ohms should do) to limit the current.

Two complete projects attached, your and one of mine. Both work.

Re: Problem with 12F683 and MikroC

Posted: 19 Aug 2013 17:12
by netomx
Thanks for checking my project. I have set 8MHz in the project menu, and also tried with OSCCON too, none of them work. Have tried with 2 12F683, so I don't think they're damaged.

I'm attaching my project, maybe I'm not seeing something.

Btw, nice name of my project: junk :cry:

Will try using a resistor in the LED tonight :)

Re: Problem with 12F683 and MikroC

Posted: 19 Aug 2013 18:14
by hexreader
change

Code: Select all

     CMCON0 = 1;      // enable comparator  - see datasheet
to:

Code: Select all

     CMCON0 = 7;      // disable comparator

Re: Problem with 12F683 and MikroC

Posted: 20 Aug 2013 00:03
by netomx
hexreader wrote:change

Code: Select all

     CMCON0 = 1;      // enable comparator  - see datasheet
to:

Code: Select all

     CMCON0 = 7;      // disable comparator
That, OSCCON, and the "RESET PIN FUNCTION" made it work. Strangely, in my other projects worked from the project files, and now from the osccon.

Thanks!