12F683 for REAL noobies

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Would someone please post a simple program for blinking an LED that can be entered into mikroBasic Pro for PICs v6.6.1? I have found programs for other PICs and programs for mikroBasic Pro that are for other pics. When I try to get it to compile, I get errors galore. I am using a 12F683 and a serial port JDM programmer. My pic and my programmer both work because I can download a hex file and load it and it runs, but I want to write it myself.
Thanks for any help!
Regards,
Mike
 

JohnInTX

Joined Jun 26, 2012
4,787
I have found programs for other PICs and programs for mikroBasic Pro that are for other pics. When I try to get it to compile, I get errors galore.
That's usually because those programs do direct references to IO, SFRs etc. that don't exist in your particular PIC. That's the problem with trying to find stuff on the 'net. Better just to write your own. When you work on this level, you have to know something (a lot, really) about the specific hardware you are using.

I use MikroC not MikroBasic BUT if you get a project going in MB and post the code, we can help you along with configuring the PIC.

A simple program will include:
Setting up the hardware configuration for your particular PIC - specifying the oscillator type, speed, and the other stuff you find in project properties.
Initializing the PORT values and TRIS to define the IO direction of each line AND resolving any multiple uses of the port pin. It's datasheet time..
Writing a simple program that sets a 1 to the port, delays then sets a 0 and loops.

Post what you have and we can take a look.
 

JohnInTX

Joined Jun 26, 2012
4,787
@Mike Pollack Try this:
Code:
' A quick hack that should toggle all port bits
' PIC12F683

program LED_Blinking

main:
  ' Init is from Example 4-1 in 12F683 datasheet:
   GPIO = 0x00       ' Set port f/f to all 0
   CMCON0 = 0x07     ' Disable comparator IO - port is digital
   ANSEL = 0x00      ' Disable analog - all pins digital
   TRISIO = 0x00     ' All pins OUTPUT

  while TRUE
    GPIO = 0xFF      ' all ON
    Delay_ms(1000)  ' 1 second delay

    GPIO = 0x00     ' all OFF
    Delay_ms(1000)  ' 1 second delay
  wend              ' Endless loop
end.
I installed the demo version of MikroBASIC (just for you) and found that the default project was flashing an LED for an 18F. That made many errors when the 12F was selected so I hit the datasheet, found the name of the IO and fixed it. Its easier for me because this not my first rodeo.

One thing you'll still have to do is to set up the PIC configuration bits in Project->Edit Project. This is unrelated to BASIC, but its essential to get the PIC hardware running in the real world.

Have fun!
 
Last edited:

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi JohnInTX,
Thanks so much for your efforts! I will try this code out tomorrow after work. It's too late now and I can't think straight anymore.
Regards,
Mike
 

JohnInTX

Joined Jun 26, 2012
4,787
Ha! No worries.
I'll be thin next week but will check in on the tablet and lots of other good folks here to help!
While thinkin' on that - any compelling reason to use BASIC instead of C? other than maybe you own the compiler...
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi John,
I have been building hardware my whole life; software not so much! I can cobble together some light VB or LabView, but for SW I just think that easier is better, at least for now.
Regards,
Mike
 

atferrari

Joined Jan 6, 2004
4,785
When I try to get it to compile, I get errors galore.
From them you will learn. Believe me.

Why not to try to program the most basic: an output pin, going up and down? (VERY slowly so you can see it with a DMM if no scope is around). I learnt digital basics with a needle VOM.

From there to a blinking LED it is just some more 6 (or 8) weeks of trying. :) :)

Buena suerte.
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi atferrari,
I am a hardware guy; I can use a scope or connect an LED and resistor to a pin to monitor its state. It's getting the state to change that is the problem. As I told JohnInTX I will continue this weekend, and I will post my progress.
Regards,
mike
 

Thread Starter

mikejp56

Joined Jun 14, 2015
70
Hi JohnInTX and atferrari,
I got the LED_Blinking program to work! No errors, and LED is blinking. So I know that HW, SW, and FW are all good! Next thing is to try to change to different LEDS. I'll keep you posted.

PS A question for you JohnInTX; do/did you post in the MSFN forums? There was a John there and his tagline was always "have fun". I kind of noticed that you do the same. Just wondering.

Have a nice weekend fellows!
Mike
 

JohnInTX

Joined Jun 26, 2012
4,787
A question for you JohnInTX; do/did you post in the MSFN forums?
MSFN? I'm 'John' over at the Microchip forums but haven't been there in awhile. I prefer the company here. But I frequently tag 'Have fun' since its usually good advice.
Thanks for the feedback and glad you had success!

er.. Have fun!
 
Last edited:
Top