Searching \ for 'Newbee Programing prob's (w/code)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=newbee+programing
Search entire site for: 'Newbee Programing prob's (w/code)'.

Truncated match.
PICList Thread
'Newbee Programing prob's (w/code)'
2000\02\15@113552 by Ken Godee

flavicon
face
Breadboarded first circuit with Picmicro, wrote a test program
in Mplab / Mpasm. Runs/assembles sucessful in Mplab sim
w/watch windows etc.
Programed chip using a Micro Engineering Labs EPIC programer.
Circuit has 8 leds on portb, when powered up all leds light up
(portb high, not what it is supposed to do). Thought it was a
problem with my circuit or one of the parts etc. After changing
parts, testing etc., for the fun of it I took a demo program that came
with the programer made some changes assembled it using melabs Pic Macro
Assembler program and programed the chip and the circuit worked just like
it is suppose to? Tried many changes to program in Mplab/Mpasm and
reprograming the chip with the same results (runs well in sim, but does
not run in circuit) and program demo from melabs works. I must be missing
something. I really want to use Mplab/Mpasm for developing. I have
included the code below, any help would appreciated. I'm using;
PIC16F84A-20, Mplab v4.12.12, EPIC programer from Micro Egineering Lab.
***************************************************************
#1)below program from Mplabs - (crude, should work but does not)
email may have played with tabs and line length
***************************************************************
list      p=16F84A
include <p16f84a.inc>

__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC

portb   equ     0x06
count   equ     0x0c
;---------------------------
           org       0x000
;
start   movlw   0x00    ;load W with 0x00
          tris       portb     ;copy W tristate, port B outputs

          clrf       portb     ;all lines low
;

          bsf        portb,0   ;turn on led

go            bsf             portb,0   ;turn on led
          call       delay     ;delay via sub
          bcf        portb,0   ;turn off led
;
          bsf        portb,1   ;turn on led
          call       delay     ;delay via sub
          bcf        portb,1   ;turn off led
;
          bsf        portb,2   ;turn on led
          call         delay   ;delay via sub
          bcf        portb,2   ;turn off led
;
          bsf        portb,3   ;turn on led
          call         delay   ;delay via sub
          bcf        portb,3   ;turn off led
;
          bsf        portb,4   ;turn on led
          call       delay     ;delay via sub
          bcf        portb,4   ;turn off led
;
          bsf        portb,5   ;turn on led
          call         delay   ;delay via sub
          bcf        portb,5   ;turn off led
;
          bsf        portb,6   ;turn on led
          call       delay     ;delay via sub
          bcf        portb,6   ;turn off led
;
          bsf        portb,7   ;turn on led
          call       delay     ;delay via sub
          bcf        portb,7   ;turn off led
;
          goto go            ;repeat
;
delay   movlw   0x02    ;decimal 10
           movwf       count   ;load counter
repeat  decfsz  count,f ;decrement counter
          goto repeat  ;not 0
          return                     ;counter 0, end delay
;
end
************************************************************
#2) below from melabs demo (assembled w/ Pic Macro Assembler)
This code works.
email may have played with tabs and line length
*************************************************************
       maclib  'p16f8x.inc'
;
       device  pic16f84,hs_osc,wdt_off,pwrt_on,protect_off
;
leds    =       portb           ;led output port
;
dir_b   =       00h             ;all out
;
         org     0ch             ;start of ram space
;
binary  ds      1               ;binary count
cnt_low ds      1               ;delay counters
cnt_mid ds      1
cnt_high ds     1
;
      org     0               ;reset vector
;
       jmp     start           ;go to beginning of program on reset
;
      org     5               ;start of code space
;
          retw    'DEMO84 Rev 1.3'
;
;
; delay for about 1 second based on 4mhz clock cycle
;
delay    mov     cnt_high,#4
      clr     cnt_mid
      clr     cnt_low
delay1  nop
      djnz    cnt_low,delay1
      djnz    cnt_mid,delay1
       djnz    cnt_high,delay1
       ret
;
;
; it all starts here
;
start     mov     leds,#0         ;start with all leds off
          setb    rp0             ;point to register page 1
          mov     trisb,#dir_b    ;set port b data direction register
          clrb    rp0             ;point back to register page 0
;
;
; main loop to send binary sequence to port b
;
       mov     binary,#1       ;start with first led on
;
mainloop mov    leds,binary     ;send the binary count to the leds
;
             call    delay           ;wait around a second
;
             inc     binary          ;increment to next binary value ;
             jmp     mainloop        ;do it forever
;

2000\02\15@115710 by Andy Baker

flavicon
face
I think your program may be working completely OK. Assuming you are using a
4MHz clock, your problem may be that you are only delaying of the order of
2us after turning each LED on, before turning it off again. So, you are
cycling through the LEDs faster than the eye can react, so they all appear
on.

The ME labs version is using a cunning 3 stage counter, so that it actually
counts to 4 * 256 * 256 each time you call delay. Yours only counts to 2.

If you change yours to be something like:

delay
       movlw           0x04
       movwf           cnt_high
       clrf            cnt_mid
       clrf            cnt_low

delayloop
       decfsz  cnt_low
       goto            delayloop
       decfsz  cnt_mid
       goto            delayloop
       decfsz  cnt_high
       goto            delayloop
       return

And put something like this at the top of your file, it should work better.

       cnt_low equ 0x0d
       cnt_mid equ 0x0e
       cnt_high        equ 0x0f

Note that MPLAB assembler and ME lab assembler language are not the same.
The above is as near as I can get to the ME lab delay loop using MPLAB. Pick
one or you're going to get very confused!

Good luck, and keep on trying, it is worth it,

Andy



{Original Message removed}

2000\02\15@120921 by James Paul

flavicon
face
It appears to me as though you have only 10uS delay.  This is
going so fast that it appears as though all LED's are on at
once.  Try increasing your delay.

                                     Regards,

                                       Jim



On Tue, 15 February 2000, Ken Godee wrote:

{Quote hidden}

spam_OUTjimTakeThisOuTspamjpes.com

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...