PIC16F877A code not running on EASYPIC V7

Thread Starter

roxi60

Joined Sep 2, 2018
73
Hello.
Enclosed code is one simple example from Bate's book "Interfacing Pic microcontroller".
The codes run properly in Proteus VMS, but not on EasyPic V7 board (to start and stop blinking I use RB1 and 2 buttons in pull up setting). Only RD6 and RD3 are lighted up constantly, but no light sequence like in the simulation.

I had same problems (not running on easypicv7) for other codes with this 16F877A.

I don't know if it is a problem of configuration or so (I remember in the past that to make 16F628A I had to pull down RB4, for instance...).
I don't know if something similar is needed here...

Thank you for any kind suggestion/advise.

Bye

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Source File:   LED2.ASM
;  Author:  MPB
;  Date:  2-1-13
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;  Slow output binary count is stopped, started
;  and reset with push buttons.
;
;  Processor:  PIC 16F877A
;
;  Hardware:  Prototype
;  Clock:  RC = 40kHz
;  Inputs:  Port B: Push Buttons
;  RB1, RB2 (active low)
;  Outputs:  Port D: LEDs (active high)
;
;  WDTimer:  Disabled
;  PUTimer:  Enabled
;  Interrupts:  Disabled
;  Code Protect:  Disabled
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   PROCESSOR 16F877   ; Define MCU type
   __CONFIG 0x3733     ; Set config fuses

; Register Label Equates....................................

PORTB  EQU  06   ; Port B Data Register
PORTD  EQU  08   ; Port D Data Register
TRISD   EQU  88   ; Port B Direction Register
Timer  EQU  20   ; GPR used as delay counter

; Input Bit Label Equates ..................................

Inres  EQU  1   ; 'Reset' input button = RD0
Inrun  EQU  2   ; 'Run' input button = RD1

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  CODE  0  ; Program code start address

; Initialise Port B (Port A defaults to inputs).............

  BANKSEL   TRISD  ; Select bank 1
  MOVLW  b'00000000'     ; Port B Direction Code
  MOVWF   TRISD     ; Load the DDR code into F86
  BANKSEL   PORTD  ; Select bank 0
  GOTO   reset  ; Jump to main loop


; 'delay' subroutine ........................................

delay:  
  MOVWF    Timer     ; Copy W to timer register
down: 
  DECFSZ    Timer     ; Decrement timer register
  GOTO     down     ; and repeat until zero
  RETURN  ; Jump back to main program


; Start main loop ...........................................

reset:
  CLRF  PORTD  ; Clear Port B Data

start:
  BTFSS    PORTB,Inres     ; Test reset button
  GOTO     reset     ; and reset Port B if pressed
  BTFSC    PORTB,Inrun     ; Test run button
  GOTO    start     ; and repeat if n pressed

  INCF     PORTD     ; Increment output at Port B
  MOVLW    0FF     ; Delay count literal
  CALL   delay  ; Jump to subroutine 'delay'
  GOTO     start     ; Repeat main loop always

  END     ; Terminate source code
Mod edit: posted code and schematic from .zip
 

Attachments

Last edited by a moderator:

Thread Starter

roxi60

Joined Sep 2, 2018
73
Hello Ian.
I install it by connecting it from external breadboard to OSC1 pin13 of easypic v7 mcu as required in the schematic.

Thank you
 

JohnInTX

Joined Jun 26, 2012
4,787
A few things besides the obvious i.e. check wiring, make sure power and ground are run to all of the boards, proper voltages to all power supply pins etc.
Try to see if the oscillator is running. A first order check is to measure the voltage on OSC2. It should be 30-50% of Vdd. If it's 5v or 0, the oscillator is not running.
Consider adding a simple LED test to turn them all on, delay awhile, then turn them all off before starting the main program. That will tell you that the PIC is running.
Make sure the variable resistor is at least 3K per PIC spec. I'd suggest putting a 3k fixed resistor in series with the variable R to be sure.
Try commenting out the switch input lines and just let it free run. When you get the LEDs counting at the right speed, add the switch code back.
Counting on a PORT can introduce r-m-w problems. Consider keeping the counter in RAM then just writing it to the PORT using MOVWF.
Double check the config bits. Your drawing and the code have different values (although both specify RC oscillator).
Make sure your programmer is not in the debug mode.

Finally, keep in mind that Proteus will 'run' with a configuration that won't work on hardware i.e. it can 'run' with no oscillator shown on the schematic.

Good luck!

Code:
;-----------------------------------
; getting rid of r-m-w problem
;-----------------------------------

PORTDimg equ 21 ; maintains an image of PORTD for modifications/counting
..
reset:
  clrf PORTD
  clrf PORTDimg  ; init both

...

  incf PORTDimg,F  ;increment the IMAGE
  movf PORTDimg,W ; then copy to port without r-m-w
  movwf PORTD
 

Thread Starter

roxi60

Joined Sep 2, 2018
73
Many thanks John for your kind and exhaustive suggestion.

I managed the problem by substituiting the configuration as in code part below.
I guess that in 0x3733 there was the problem (maybe the "in circuit debug enable").

Now it works properly also on easypicv7 hardware.

Thank you very much again.


Code:
;    PROCESSOR 16F877    ; Define MCU type
;    __CONFIG 0x3733        ; Set config fuses
   
list P = 16F877A
include P16F877A.inc
__config _RC_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_ON
 
Top