Discussion in "Project Help" started by    rogermado    Apr 26, 2020.
Sun Apr 26 2020, 01:29 am
#1
Hello everyone,

sorry in advance if i'm not in the right section of the forum to ask this question :

Well, i'm making a school project based on the PIC16F877A. And i have already written the code in MPLabx IDE 5.35. I've simulated it on MPLabX and it worked just fine! the problem is when i use the software "REAL PIC SIMULATOR" i'm not able to make it work. The 7seg display stucks and the results i'm waiting are pretty weird and impredictable. By the way, i build the code i wrote on MPLAB in a hex file then i opened it on Real Pic Simulator.I wonder if there is a "good" way to go from MBLab to Real pic simulator with no problems along the way. Thank you very much in advance for your help,

RogerMado
Sun Apr 26 2020, 03:12 am
#2
Some simulators handle displays better than others.
If you post as much of your code and circuit diagram as possible
we can try it in "Real Pic Simulator" and Proteus.

Meanwhile try writing test code to do very simple things
such as displaying just one character.
First find what works.. then add to it.
Sun Apr 26 2020, 11:23 am
#3
@ExperimenterUK, thanks for your reply. You'll find the code below. thanks again RogerMado





;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F877A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F877A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************


list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.






;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving

CNT_7_SEG EQU 0X24






ORG 0x000 ; processor reset vector
nop ; nop required for icd
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
test_1
BTFSS INTCON,INTF
goto test_2
call service_interrupt_2
test_2
BTFSS INTCON,RBIF
goto Sortir
call service_interrupt
Sortir
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
call ConfigPortB ; RB3 en output RB0:RB2 en input RB4:RB7 en input
call ConfigPortD ; configuration du portd en output
call ConfigPortC ; configuration de RC0 en output
call ConfigPortA ; configuration du porta en input

call configinte

BSF PORTC,RC0 ; alimente le 7 segments
movlw 0X3f
movwf PORTD
boucle
reset_zones
BTFSS PORTC,RC1
goto boucle_reset
movlw 0Xf7
movwf PORTD
boucle_reset
goto boucle
goto $
JUMP_TO_BANK1
BSF STATUS,RP0
BCF STATUS,RP1
RETURN
JUMP_TO_BANK0
BCF STATUS,RP0
BCF STATUS,RP1
RETURN
ConfigPortA
CALL JUMP_TO_BANK1
MOVLW 0X11
movwf TRISA
call JUMP_TO_BANK0
return
ConfigPortB
CALL JUMP_TO_BANK1
movlw B'11111111'
movwf TRISB
CALL JUMP_TO_BANK0
return
ConfigPortD
CALL JUMP_TO_BANK1
MOVLW 0X00
MOVWF TRISD
CALL JUMP_TO_BANK0
return
ConfigPortC
CALL JUMP_TO_BANK1
movlw 0XFE
movwf TRISC
CALL JUMP_TO_BANK0
return
configinte
CALL JUMP_TO_BANK1
movlw 0X98
movwf INTCON
movlw 0X80
movfw OPTION_REG
CALL JUMP_TO_BANK0
return
service_interrupt
movf PORTB,W
BCF INTCON,RBIF
movwf PORTB
BCF INTCON,GIE
TEST1
BTFSS PORTB,RB4
GOTO TEST2
GOTO SHOW1
TEST2
BTFSS PORTB,RB5
GOTO TEST3
GOTO SHOW2
TEST3
BTFSS PORTB,RB6
GOTO TEST4
GOTO SHOW3
TEST4
BTFSS PORTB,RB7
GOTO end_interrupt
GOTO SHOW4
SHOW1
movlw 0X06
movwf PORTD
GOTO end_interrupt
SHOW2
movlw 0X5B
movwf PORTD
GOTO end_interrupt
SHOW3
movlw 0X4F
movwf PORTD
GOTO end_interrupt
SHOW4
movlw 0X66
movwf PORTD
GOTO end_interrupt
end_interrupt
return
service_interrupt_2
BCF INTCON, GIE
BCF INTCON, INTF
movlw 0XF7
movwf PORTD
return
end
Tue Apr 28 2020, 01:51 pm
#4
The code is hard to read.
Please zip it and attach it to your post.
Before you zip, it please add lots of comments to explain how each part works.
Imagine you are explaining each step to someone who has never seen your project before.
This is good practise, because if you come back to this code in a few months
you will have forgotten how it works.
Also please zip and post a circuit diagram, even if it is only a rough sketch.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

EdwardFew
Mon Mar 18 2024, 01:14 pm
EmeryPah
Mon Mar 18 2024, 11:51 am
RobertMax
Sun Mar 17 2024, 10:22 pm
DanielJar
Fri Mar 15 2024, 06:52 pm
Tuzaimecor
Fri Mar 15 2024, 02:32 am
PromotionFoode
Thu Mar 14 2024, 08:11 pm
EdwardGeawn
Sun Mar 10 2024, 12:24 pm
ZacharyShado
Sat Mar 09 2024, 10:04 am