The worst programmer ever to grace this forum - ME!


Closed Thread
Results 1 to 40 of 50

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default The worst programmer ever to grace this forum - ME!

    Ok, I've been on about 8 hours trying to get a damn LED to light using PICBAsic - nothing!

    I have a PICkit 2 (the board comes with a PIC16F690), everything works fine with 'hello world' tutorial Microchip provide (which proves the chip & LED is fine). Assembly language make my brain spontaneously combust so I would like to learn a higher level language such as basic (which seems at least a little akin to DEC DCL...something I used about 10 years ago)...I'm beginning to wish I hadn't.


    Right to my simple problem - more than anything in the world right now, I want to see that stupid little LED on my PICkit 2 low pin count board light up!

    Most of the 'flash an led' example basic programs work on the PIC's Port A...now I thought it would be a simple case of changing the references conatined therein to PortC (the 4 leds on the Pickit board are attached to Port C)

    But when I change not a lot happens!

    I'm aware that the 16f690 has analogue ports turned on as default & Ive seen some mention that this can be remedied with a commands along these lines

    ANSEL = 0
    ANSELH = 0

    but the microcode studio GUI doesn't seem to recognise those commands (I'm new to this interface but it seems to darken/bold commands it's happy with)

    Could some one humour me here & cut/paste in the ludicrously simple basic code for PIC Basic Pro that I need to light an LED on portc.1 of my 16f690.

    I can then put this all to rest & pour petrol over my pickit 2 whilst moonwalking backwards to "The eye of the Tiger".




    FWIW, This is the latest code I've tried (based on this link http://www.digital-diy.net/16F%20Exa...LED's.aspx )....

    Symbol LED_1 = PortC.0 ' Define a symbol in the program

    TRISC.0 = 0 ' Make PORTC.0 an output
    PORTC.0 = 0 ' and set it low (0V)

    Main:

    If LED_1 = 0 then ' Check the status of the LED
    LED_1 = 1 ' and toggle it
    Else
    LED_1 = 0
    Endif

    DelaymS 1000 ' Delay for 1 second (compiler errors with this line - I guess the command isn't right!)
    Goto Main ' Loop forever




    Basic Schhmasic....
    Last edited by HankMcSpank; - 14th March 2009 at 00:41.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Here, this chaser works with the hardware you are using:
    MPASM required, you must comment out the config in the .inc file for 16f690 in PBP root.
    Code:
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON  
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF 
    @ __config  MyConfig 
    
    DEFINE OSC 4
    PortA = 0
    PortB = 0
    PortC = 0
    TRISA = 0
    TRISB = 0
    TRISC = 0
    i var byte
    
    main:
    portc = 0
    pause 500
    for i = 1 to 15; step -1
    portC = i
    i=i  << 1 
    pause 250
    next i
    goto main
    end
    Here's a blinkey:
    Code:
    DEFINE OSC 4
    PortA = 0
    PortB = 0
    PortC = 0
    TRISA = 0
    TRISB = 0
    TRISC = 0
    
    LED_1 var PortC.0 ' Define an alias in the program
    led_1 = 0
    
    Main:
    HIGH LED_1
    PAUSE 1000
    LOW LED_1
    PAUSE 1000
    Goto Main ' Loop forever
    end
    OK here is your code reworked:
    Code:
    DEFINE OSC 4
    LED_1 VAR BIT  ' PORT FLAG BIT
    LED_1 = 0      ' SET INITIAL VALUE
    TRISC.0 = 0 ' Make PORTC.0 an output
    
    
    Main:
    IF LED_1 = 0 THEN
    LED_1=1
    ELSE
    LED_1 = 0
    ENDIF
    PORTC.0 = LED_1
    
    
    
    
    PAUSE 250 ' Delay for 1 second (compiler errors with this line - I guess the command isn't right!)
    Goto Main ' Loop forever
    It appears as though the PIC cannot read and change it's own output without an intermediary like a flag variable. Probably
    A RMW thing, I do not know.
    Last edited by Archangel; - 14th March 2009 at 02:07.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Ok, many thanks for helping me.

    When I enter the code you recommended below *and*comment *all* the entries in the 16f690.inc (c:\PBP) I get 121 compiler errors (I have MPASM selected under the assembler tab ...I'm using the defaul selections when I select MPASM eg INHX8SM)...


    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF
    @ __config MyConfig

    DEFINE OSC 4
    PortA = 0
    PortB = 0
    PortC = 0
    TRISA = 0
    TRISB = 0
    TRISC = 0
    i var byte

    main:
    portc = 0
    pause 500
    for i = 1 to 15; step -1
    portC = i
    i=i << 1
    pause 250
    next i
    goto main
    end


    but when I reenable all the comments in the .inc file, i only get 2 errors (relating to line 63 in the corresponding asm file - if my counting is correct, it's this line __config MyConfig ....is there an easier way to establish the line that's erroring from what's being reportred in the results field?)
    Last edited by HankMcSpank; - 14th March 2009 at 10:16.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HankMcSpank View Post
    When I enter the code you recommended below *and*comment *all* the entries in the 16f690.inc
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    To me, that FAQ assumes a fair degree of previous knowledge!

    if I'm reading it right, the 16F690.inc file tells the assembler to configure the PIC for 'what's out there'?

    What's doing my head in is the sheer number of 16f690.inc files there are on my PC...

    c:\mpasm\16f690.inc (which looks a whole lot different to the others!)

    c:\pbp\16f690.inc (the one that Joe S said I should comment out - not sure which lines ...all of them?)

    c:\pbp\inc\ (a whole lot of files in here!)


    At the risk of sounding incredibly slow - help!

    Once again, all I want is the correct code to 'set the chip correctly' for me to then start my simple journey to get an LED, firstly lit, then flashing (wheee!)

    Joe.S kindly posted a 'chaser' earlier ( & said I needed to comment out the inc file in c:\pbp ....which lines?!)

    I'm perplexed that this chip should be so troublesome at the very first base ....from a newbie's perspective, it's probably the most prevelant since it's bundled in with the low pin count board on on the Pickit 2 starter. It might have been useful to have a "So you got a 16F690 PIC & you've arrived here after using the Pickit 2....here are some things you should know/do!" type thread.

    I'm an absolute novice here.....are we saying there's an issue with the PIC itself...or just this particular PIC in combination with PICBasic? (fwiw, I'm suspecting the latter as the PIC is fine using the Micropchip Assembler)

    Many thanks in anticipation.
    Last edited by HankMcSpank; - 14th March 2009 at 14:41.

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    In your 16F690.INC only comment out the __config line. Leave everything else
    as-is.

    Then something like this should work if you're disabling analog inputs & comparators;
    Code:
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON  
    @MyConfig = MyConfig & _MCLRE_ON & _BOR_OFF 
    @ __config  MyConfig 
    
    DEFINE OSC 4
    
        i var byte
        
        ANSEL=0      ' all digital
        ANSELH=0     ' analog module disabled
        CM1CON0=0
        CM2CON0=0
        PortC = 0
        TRISC = 0
    
    
    main:
        portc = 0
        pause 500
        for i = 1 to 15
        portC = i
        pause 150
        next i
        goto main
        end
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Melabs U2 Programmer Command Line Options
    By Robert Wells in forum General
    Replies: 5
    Last Post: - 3rd July 2009, 02:11
  2. problems with USB programmer
    By malc-c in forum General
    Replies: 7
    Last Post: - 10th May 2007, 20:14
  3. USB programmer problems
    By uiucee2003 in forum USB
    Replies: 2
    Last Post: - 15th August 2006, 23:47
  4. General Programmer Questions
    By mslaney in forum General
    Replies: 1
    Last Post: - 17th December 2004, 18:16

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts