Beginner's PIC Assembly Problem

Discussion in 'Programmer's Corner' started by DBK, Mar 21, 2011.

  1. DBK

    Thread Starter New Member

    Mar 21, 2011
    1
    0
    Hi, im relatively new to programming and I just need some quick help. I have the pickit 2 with an included pic16f690. I have been trying to create a simple program that will simply blink an LED on and off continuously. It seems to build successfully but when i program it into the micro, it turns on and then blinks off twice before staying on the rest of the time. So it's not looping the way it should. I've done a lot of troubleshooting but I just can't seem to find the problem. If you guys need any more information let me know. Any help is much appreciated :)

    Here's my code:

    list p=16f690
    #include <p16F690.inc>
    __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
    org 0

    ;CONSTANTS

    STATUS equ 03h
    TRISC equ 87h
    PORTC equ 07h
    COUNT1 equ 08h ;08h and 09h are "unimplemented"
    COUNT2 equ 09h

    ;SET UP PORTS

    bsf STATUS,5 ;switch to Bank 1
    movlw B'000000000' ;sets PORTC all to output
    movwf TRISC
    bcf STATUS,5 ;switch back to Bank 0

    START
    movlw B'00000001' ;moves value into w register
    movwf PORTC ;from w to PORTC causing the LED to go LOW
    Call DELAY ;goes through DELAY subroutine
    movlw B'00000000' ;moves value into w register
    movwf PORTC ;from w to PORTC causing the LED to go HIGH
    Call DELAY
    goto START

    ;Delay Subroutine

    DELAY
    LOOP
    decfsz COUNT1,1 ;Counts down by 1 from 255
    goto LOOP ;when COUNT1 is 0, it skips to LOOP2
    LOOP2
    decfsz COUNT2,1 ;so overall counts down from 255 255 times
    goto LOOP ;when COUNT2 is 0, it returns to the main code
    return

    end
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    There's no need to define the first 3. Don't use 08h and 09h, start at 20h for your variables.
     
  3. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    If I were you, I'd try this delay routine:

    Delay
    Loop1 decfsz COUNT1,1;
    . goto Loop1;
    . decfsz COUNT1,1;
    . goto Loop1;

    This is the standard delay loop for PIC ASM and it has always worked for me. It's definitely worth a go :D
    Good luck!
    Der Strom

    P.S. Don't mind the periods
     
  4. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    By the way, you have your "High"s and "Low"s backwards. A 1 means high, a 0 means low.
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
Loading...