Problem with 12F683 and MikroC

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
netomx
Posts: 10
Joined: 30 Jul 2011 07:17

Problem with 12F683 and MikroC

#1 Post by netomx » 19 Aug 2013 08:12

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?

hexreader
Posts: 1782
Joined: 27 Jun 2010 12:07
Location: England

Re: Problem with 12F683 and MikroC

#2 Post by hexreader » 19 Aug 2013 16:53

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.
Attachments
pintest.rar
(8.61 KiB) Downloaded 118 times
junk.rar
(8.4 KiB) Downloaded 106 times
Start every day with a smile...... (get it over with) :)

netomx
Posts: 10
Joined: 30 Jul 2011 07:17

Re: Problem with 12F683 and MikroC

#3 Post by netomx » 19 Aug 2013 17:12

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 :)
Attachments
629-Dallas-uart.zip
(10.23 KiB) Downloaded 102 times

hexreader
Posts: 1782
Joined: 27 Jun 2010 12:07
Location: England

Re: Problem with 12F683 and MikroC

#4 Post by hexreader » 19 Aug 2013 18:14

change

Code: Select all

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

Code: Select all

     CMCON0 = 7;      // disable comparator
Start every day with a smile...... (get it over with) :)

netomx
Posts: 10
Joined: 30 Jul 2011 07:17

Re: Problem with 12F683 and MikroC

#5 Post by netomx » 20 Aug 2013 00:03

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!

Post Reply

Return to “mikroBasic PRO for PIC General”