12F683 for REAL noobies

Discussion in 'Embedded Systems and Microcontrollers' started by mikejp56, Jul 28, 2015.

  1. mikejp56

    Thread Starter Member

    Jun 14, 2015
    49
    1
    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
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    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.
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    @Mike Pollack Try this:
    Code (Text):
    1. ' A quick hack that should toggle all port bits
    2. ' PIC12F683
    3.  
    4. program LED_Blinking
    5.  
    6. main:
    7.   ' Init is from Example 4-1 in 12F683 datasheet:
    8.    GPIO = 0x00       ' Set port f/f to all 0
    9.    CMCON0 = 0x07     ' Disable comparator IO - port is digital
    10.    ANSEL = 0x00      ' Disable analog - all pins digital
    11.    TRISIO = 0x00     ' All pins OUTPUT
    12.  
    13.   while TRUE
    14.     GPIO = 0xFF      ' all ON
    15.     Delay_ms(1000)  ' 1 second delay
    16.  
    17.     GPIO = 0x00     ' all OFF
    18.     Delay_ms(1000)  ' 1 second delay
    19.   wend              ' Endless loop
    20. 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: Jul 28, 2015
  4. mikejp56

    Thread Starter Member

    Jun 14, 2015
    49
    1
    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
     
  5. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    Good luck.
    'like' or quote the post or tag me and I'll get an alert when you reply.
    Welcome aboard!
     
    mikejp56 likes this.
  6. mikejp56

    Thread Starter Member

    Jun 14, 2015
    49
    1
    Hi John,
    I will get to this code over the weekend. Life happened!
    Regards,
    Mike
     
  7. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    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...
     
  8. mikejp56

    Thread Starter Member

    Jun 14, 2015
    49
    1
    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
     
  9. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    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.
     
  10. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    Fair enough. We'll go from there.
     
  11. mikejp56

    Thread Starter Member

    Jun 14, 2015
    49
    1
    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
     
  12. mikejp56

    Thread Starter Member

    Jun 14, 2015
    49
    1
    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
     
  13. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    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: Jul 31, 2015
Loading...