Need PIC help, Please.

Discussion in 'The Projects Forum' started by Pinnacle187, Apr 28, 2016.

  1. Pinnacle187

    Thread Starter New Member

    Apr 28, 2016
    13
    0
    Hey guys I'm having trouble writing a code for a project I have (I have to make a working circuit). I'm using a PIC16F88 and I'm trying to display numbers from 0 - 9 on a 8 pin display and I can't manage to do it, I have to write the code in assembler. The program has to consider 3 buttons: one that turns on the circuit, one that increases count, and one that decrease count, the delay between each number is 5 seconds.

    This is what I have until now:
    Contador = counter (it's in spanish)
    Code (ASM):
    1.  
    2. ;Pre-processor Directives
    3. ;----------------------------------------
    4.  
    5.   LIST   P=16F88
    6.   INCLUDE  P16F88.INC
    7.   __CONFIG   _CONFIG1,3F61
    8.   __CONFIG  _CONFIG2,3FFC
    9.  
    10.  
    11. ; Definitions (#Define)
    12. ;----------------------------------------
    13.   CBLOCK
    14.   CONTADOR1
    15.   ENDC
    16.   TIMX EQU  0X21
    17.     TIMY  EQU  0X22
    18.   TIMZ EQU  0X23
    19.   #DEFINE  DISPLAY  PORTB
    20.  
    21. ;Initial direction in program memory
    22.  
    23. ;----------------------------------------
    24. ORG  0
    25. ;START
    26. ;-------------------------------------
    27. PREINICIO
    28.   BSF  STATUS,RP0
    29.   CLRF  DISPLAY
    30.   BCF  STATUS,RP0
    31.   CLRF  CONTADOR1
    32.  
    33. START
    34. BTFSS  PORTA,0
    35.   GOTO  START
    36.   CLRF  CONTADOR1
    37.   MOVF  CONTADOR1,W
    38.   CALL  SIETE_SEGMENTOS
    39.   MOVWF  DISPLAY
    40.   CALL  RETARDO
    41.  
    42. CONTAR
    43.   INCF  CONTADOR1,F
    44.   MOVLW  .10
    45.   SUBWF  CONTADOR1,W
    46.   BTFSC  STATUS,C
    47.   GOTO  START
    48.   MOVF  CONTADOR1,W
    49.   CALL  SIETE_SEGMENTOS
    50.   MOVWF  DISPLAY
    51.   CALL  RETARDO
    52.   GOTO  CONTAR
    53.  
    54.   ADDWF  PCL,F
    55.  
    56. TABLA
    57.   RETLW  B'01101111'
    58.   RETLW  B'01111111'
    59.   RETLW  B'00000111'
    60.   RETLW  B'01111101'
    61.   RETLW  B'01101101'
    62.   RETLW  B'01100110'
    63.   RETLW  B'01001111'
    64.   RETLW  B'01011011'
    65.   RETLW  B'00000110'
    66.   RETLW  B'00111111'
    67.   RETURN
    68.  
    69. RETARDO
    70.   MOVLW  .6
    71.   MOVWF  TIMX
    72.   MOVLW  .19
    73.   MOVWF  TIMY
    74.   MOVLW  .172
    75.   MOVWF  TIMZ
    76.  
    77. DEL
    78.   DECFSZ   TIMZ,F
    79.   GOTO  DEL
    80.   DECFSZ  TIMY,F
    81.   GOTO  DEL
    82.   DECFSZ  TIMX,F
    83.   GOTO  DEL
    84.   NOP
    85.   RETURN
    86.   END
    87. END
    88.  
    edited by moderator: code tags inserted, deleted COLOR tags
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Hi Pinnacle, welcome to the forums.

    (In the future please use code tags to post code so the formatting stays. Easier than looking to your link, especially for those of us using devices not a PC to view.)

    What does your code do incorrectly? How sure of the hardware are you?

    Before writing any code can you make a flowchart of how the code should flow? Simple words outlining steps is fine, don't need all the graphics. Basically it is a pseudo code version to outline what steps you see as necessary.
     
  3. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,507
    2,367
  4. TheButtonThief

    Active Member

    Feb 26, 2011
    219
    38
    Are you asking for help on a homework/coursework assignment?
     
  5. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,645
    759
    The first button controls the power, right? If so, it is not involved with the code.

    Question: have you got any simple working program for that micro? Once you get one, things should be really easier because a proper flow diagram as already suggested will help.

    The 8 pins display, is it a port?

    Aprendé a caminar antes de salir corriendo.
     
Loading...