Special Offer
It is currently 30 Jul 2014 18:25

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 19 Aug 2013 08:12 
Offline

Joined: 30 Jul 2011 07:17
Posts: 10
Hello. I'm getting here because I'm desesperate. I can't make my code work! :@

MikroC v6.0

Code:

//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?


Top
 Profile  
 
PostPosted: 19 Aug 2013 16:53 
Online

Joined: 27 Jun 2010 12:07
Posts: 540
Location: England
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.

Quote:
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.

Quote:
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 35 times
junk.rar [8.4 KiB]
Downloaded 32 times

_________________
Experienced hobbyist
Top
 Profile  
 
PostPosted: 19 Aug 2013 17:12 
Offline

Joined: 30 Jul 2011 07:17
Posts: 10
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 29 times
Top
 Profile  
 
PostPosted: 19 Aug 2013 18:14 
Online

Joined: 27 Jun 2010 12:07
Posts: 540
Location: England
change
     CMCON0 = 1;      // enable comparator  - see datasheet
to:
     CMCON0 = 7;      // disable comparator

_________________
Experienced hobbyist


Top
 Profile  
 
PostPosted: 20 Aug 2013 00:03 
Offline

Joined: 30 Jul 2011 07:17
Posts: 10
hexreader wrote:
change
     CMCON0 = 1;      // enable comparator  - see datasheet
to:
     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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group