Help with dice game code errors on PIC 18F452 microcontroller

Thread Starter

Samwilliams_4

Joined Jul 18, 2021
1
Im trying to finish a dice game code on a PIC 18F452 microcontroller using assembly language by tomorrow morning and only have 7 errors left in his code. If i can fix the remaining 7 errors, i won’t have to drop the class so if anyone can help out tonight that would be greatly appreciated. Here is the code:
Code:
;;;;;; Program hierarchy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; Mainline

;   Initial

;   LoopTime

;    DecimalDisplay

;     InitLCD.

;     T40

;      DisplayV

;       DisplayC

;        constant strings

;

;;;;;;; Assembler directives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



        list  P=PIC18F452, F=INHX32, C=160, N=0, ST=OFF, MM=OFF, R=DEC, X=ON

        #include P18F452.inc

        __CONFIG  _CONFIG1H, _HS_OSC_1H  ;HS oscillator

        __CONFIG  _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_42_2L  ;Reset

        __CONFIG  _CONFIG2H, _WDT_OFF_2H  ;Watchdog timer disabled

        __CONFIG  _CONFIG3H, _CCP2MX_ON_3H  ;CCP2 to RC1 (rather than to RB3)

        __CONFIG  _CONFIG4L, _LVP_OFF_4L  ;RB5 enabled for I/O



;;;;;;; Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



        cblock  0x000           ;Beginning of Access RAM

        TMR0LCOPY               ;Copy of sixteen-bit Timer0 used by LoopTime

        TMR0HCOPY

        INTCONCOPY              ;Copy of INTCON for LoopTime subroutine

        BYTESTR:10              ;initialize it to 10-8byte

        BYTE                    ;used in DISPLAY macro

        COUNT                   ;used in T40 subroutine

    value                          ;used to store value 0 thru 20

    counter                        ;used in DELAY subroutine for scrolling
    times

    much                           ;used for scrolling loops a set # of times

    much_backup                    ;saves much (reuse after interrupt)

    tblptrl_backup                 ;saves tblptrl

    tblptrh_backup

    Random
   
    jay
    ann
    sam
    amy
    mic:4
    HEXSTR:4
    states:21
        palyer1
     player2
    b0
    b1
    b2
    Number
    mike
    number
    sum
        endc



;;;;;;; Macro definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



MOVLF   macro  literal,dest
    movlw  literal
    movwf  dest
        endm
   
POINT   macro  stringname
        MOVLF  high stringname, TBLPTRH
        MOVLF  low stringname, TBLPTRL
        endm

DISPLAY macro  register
        movff  register,BYTE
        rcall  ByteDisplay
    endm

                                   ;#include <C:\MATH18\MATHVARS.inc>

;;;;;;; Vectors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



        org  0x0000             ;Reset vector

        nop

        goto  Mainline



        org  0x0008             ;High priority interrupt vector

        goto  $                 ;Trap



        org  0x0018             ;Low priority interrupt vector

        goto  $                 ;Trap



;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



Mainline
        rcall Initial           ;Initialize everything
    rcall InitLCD                  ;initialize the LED screen
        rcall LoopTime          ;Wait for the Tacq (ten milliseconds)
    MOVLF 26,much                  ;26 messages to display
    POINT message1                 ;point to first message in program memory
    rcall DisplayC                 ;display character string
    rcall DELAY                    ;small delay so it looks like it's sliding
     tblrd*+                       ;read value into TABLAT, increment pointer
    decf much,F                    ;decrement much, rewrites to itself (does it flag Z bit?)
    ;REPEAT_
L1
        rcall DELAY                ;add a 5 sec delay
        decf much,F

    ;UNTIL_ .Z.
    bnz    L1
RL1

    ;LOOP_
L2

        MOVLF 22,much

        POINT messagec             ;set tblptr to first message [push button message]

        ;REPEAT_                   ;enter loop
L3

        rcall DisplayC                ;display character string

        rcall DELAY                   ;small delay so it looks like it's sliding

        tblrd*+                       ;read value into TABLAT, increment pointer

        decf much,F                   ;decrement much, rewrites to itself (does it flag Z bit?)

        ;UNTIL_ .Z.                ;exit conditio
        bnz    L3
RL3
;
;       
;
;        LOOP_
;
;        MOVLF 23,much
;
;        POINT number00    ;set tblptr to first message [player 1 message]
;
;        REPEAT_        ;enter loop
;
;        rcall DisplayC    ;display character string
;
;        rcall DELAY    ;small delay so it looks like it's sliding
;
;        tblrd*+        ;read value into TABLAT, increment pointer
;
;        decf much,F    ;decrement much, rewrites to itself (does it flag Z bit?)
;
;        UNTIL_ .Z.        ;exit condition
;
;    ENDLOOP_        ;inf loop, only interrupts can stop it
;   
;ENDLOOP_

Loop
         MOVLF 0,states+40
   rcall Randomn
   lfsr 0,states                ;set up pointer here to send values stored in states to states+39 to correct LED

    ;REPEAT_                       ;enter loop
L4
      rcall Delay
      movff POSTINC0, number

    ;IF_

        ;AND_

                ;number,0==1
                btfss number,0
                bra    L5

            ;number,1==0
            btfsc number,1
            bra    L5

            ;number,2==0
            btfsc number,2
            bra    L5

            ;number,3==0
            btfsc number,3
            bra    L5

            ;number,4==0
            btfsc number,4
            bra    L5

            ;number,5==0
            btfsc number,5
            bra    L5

            ;number,6==0
            btfsc number,6
            bra    L5

            ;number,7==0
            btfsc number,7
            bra    L5

        ;ENDAND_

        rcall DICE1

    ;ENDIF_
L5


    ;IF_ number,0==0
    btfsc number,0
    bra    L6

        ;AND_

            ;number, 1==1
            btfss number,1
            bra    L6

            ;number, 2==0
            btfsc number,2
            bra    L6

            ;number, 3==0
            btfsc number,3
            bra    L6

            ;number, 4==0
            btfsc number,4
            bra    L6

            ;number, 5==0
            btfsc number,5
            bra    L6

            ;number, 6==0
            btfsc number,6
            bra    L6

            ;number, 7==0
            btfsc number,7
            bra    L6

        ;ENDAND_

        rcall DICE2

    ;ENDIF_
L6


    ;IF_ number,0==1
    btfss number,0
    bra    L7

        ;AND_

         ;number, 1==1
         btfss number,1
         bra    L7

         ;number, 2==0
         btfsc number,2
         bra    L7

         ;number, 3==0
         btfsc number,3
         bra    L7

         ;number, 4==0
         btfsc number,4
         bra    L7

         ;number, 5==0
         btfsc number,5
         bra    L7

         ;number, 6==0
         btfsc number,6
         bra    L7

         ;number, 7==0
         btfsc number,7
         bra    L7

        ;ENDAND_

        rcall DICE3

    ;ENDIF_
L7


    ;IF_ number,0==0
    btfsc number,0
    bra    L8

        ;AND_

            ;number,1==0
            btfsc number,1
            bra    L8

            ;number,2==1
            btfss number,2
            bra    L8

            ;number,3==0
            btfsc number,3
            bra    L8

            ;number,4==0
            btfsc number,4
            bra    L8

            ;number,5==0
            btfsc number,5
            bra    L8

            ;number,6==0
            btfsc number,6
            bra    L8

            ;number,7==0
            btfsc number,7
            bra    L8

        ;ENDAND_

        rcall DICE4

    ;ENDIF_
L8

   

   

    ;IF_ number,0==1
    btfss number,0
    bra    L9

        ;AND_

            ;number,1==0
            btfsc number,1
            bra    L9

            ;number,2==1
            btfss number,2
            bra    L9

            ;number,3==0
            btfsc number,3
            bra    L9

            ;number,4==0
            btfsc number,4
            bra    L9

            ;number,5==0
            btfsc number,5
            bra    L9

            ;number,6==0
            btfsc number,6
            bra    L9

            ;number,7==0
            btfsc number,7
            bra    L9

        ;ENDAND_

        rcall DICE5

    ;ENDIF_
L9

    ;IF_ number,0==0
    btfsc number,0
    bra    L10

        ;AND_

         ;number,1==1
         btfss number,1
         bra    L10

         ;number,2==1
         btfss number,2
         bra    L10

         ;number,3==0
         btfsc number,3
         bra    L10

         ;number,4==0
         btfsc number,4
         bra    L10

         ;number,5==0
         btfsc number,5
         bra    L10

         ;number,6==0
         btfsc number,6
         bra    L10

         ;number,7==0
         btfsc number,7
         bra    L10

        ;ENDAND_

        rcall DICE6

    ;ENDIF_
L10
    rcall summation
    rcall addition
    bra Loop

;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; This subroutine performs all initializations of variables and registers.



Initial

        MOVLF B'11100001',TRISA  ;Set I/O for PORTA

        MOVLF B'00000000',TRISB  ;Set I/O for PORTB

        MOVLF B'11010011',TRISC  ;Set I/0 for PORTC

        MOVLF B'00001110',TRISD  ;Set I/O for PORTD

        MOVLF B'00000000',TRISE  ;Set I/O for PORTE

        MOVLF B'10001000',T0CON  ;Set up Timer0 for a looptime of 10 ms

        MOVLF B'00010000',PORTA  ;Turn off all four LEDs driven from PORTA

        MOVLF B'11001110',ADCON1  ;set Fosc/16 / ADRESL /RA0 analoge/else where is digital

        MOVLF B'01000001',ADCON0  ;GO_DONE =0 / RE2 SELECTED to read from 

    rcall InitLCD                  ;initialize the LCD

    bsf RCON,IPEN                  ;enable high prio interrupt

    bsf TRISB,1                    ;set TRISB,1 so PORTB,1 is an input

    bsf INTCON2,INTEDG1            ;set rising edge

    bsf INTCON3,INT1IP             ;set high prio

    bcf INTCON3,INT1IF             ;clear flag

    bsf INTCON3,INT1IE             ;enable interrupt source

    bsf INTCON,GIEH       

    bsf INTCON,GIEL                ;enable global interrupts     

        return

   

;;;;;;; InitLCD subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; Initialize the Optrex 8x2 character LCD.

; First wait for 0.1 second, to get past display's power-on reset time.



InitLCD

        MOVLF 10,COUNT          ;Wait 0.1 second

        ;REPEAT_
L11

          rcall LoopTime        ;Call LoopTime 10 times

          decf COUNT,F

        ;UNTIL_ .Z.
        bnz    L11
RL11



        bcf PORTE,0             ;RS=0 for command

        POINT LCDstr            ;Set up table pointer to initialization string

        tblrd*                  ;Get first byte from string into TABLAT

        ;REPEAT_
L12

          bsf PORTE,1           ;Drive E high

          movff TABLAT,PORTD    ;Send upper nibble

          bcf PORTE,1           ;Drive E low so LCD will process input

          rcall LoopTime        ;Wait ten milliseconds

          bsf PORTE,1           ;Drive E high

          swapf TABLAT,W        ;Swap nibbles

          movwf PORTD           ;Send lower nibble

          bcf PORTE,1           ;Drive E low so LCD will process input

          rcall LoopTime        ;Wait ten milliseconds

          tblrd+*               ;Increment pointer and get next byte

          movf TABLAT,F         ;Is it zero?

        ;UNTIL_ .Z.
        bnz    L12
RL12

        return



;;;;;;; T40 subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; Pause for 40 microseconds  or 40/0.4 = 100 clock cycles.

; Assumes 10/4 = 2.5 MHz internal clock rate.



T40

        movlw 100/3             ;Each REPEAT loop takes 3 cycles

        movwf COUNT

        ;REPEAT_
L13

          decf COUNT,F

        ;UNTIL_  .Z.
        bnz    L13
RL13

        return



;HipriISR subroutine

   

;HipriISR
;
;    movff much,much_backup            ;saves important registers
;
;    movff TBLPTRL,tblptrl_backup       
;
;    movff TBLPTRH,tblptrh_backup
;
;    IF_ INTCON3,INT1IF==1
;
;        IF_ value,4==0
;
;        rcall Int1Inc
;
;        ELSE_
;
;        rcall Int1Dec
;
;        ENDIF_
;
;    ENDIF_           
;
;    movff tblptrl_backup,TBLPTRL        ;retrieve tblptrl
;
;    movff tblptrh_backup,TBLPTRH        ;retrieve tblptrh
;
;    movff much_backup,much            ;retrieve much
;
                                ;       retfie FAST                ;unique return for high pri interrupts
;
   

;Int1Handler Increment subroutine (loop attempt)

;   
;
                                ;   Int1Inc    ;if the value is 0 (which it was initialized as above), display 0 to 20
;
;        POINT number00    ;set tblptr to point to relevant character string
;
;        MOVLF 20,times    ;20 displays
;
;        MOVLF 0,value    ;may be unnecessary, test more
;
;        REPEAT_

;        DISPLAY value    ;display binary value
;
;        incf value,F    ;increment 0 to 20
;
;        rcall DisplayC    ;display decimal value (ASCII)
;
;        btg PORTA,3    ;random test condition
;
;        tblrd*+        ;read TABLAT, increment tblptrl
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY    ;brief delay so we can see what happens (.8s)
;
;        decf times,F    ;decrement, rewrite to itself
;
;        UNTIL_ .Z.
;
;        DISPLAY value    ;display binary value (21 displays, but we only want to increment 20x)
;
;        rcall DisplayC    ;display decimal value (ASCII)
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY        ;brief delay so we can see what happens (.8s)
;
;    bcf INTCON3,INT1IF    ;reset flag
;
                                ;   return
;
;   
;
;;Int1Dec subroutine (loop)
;
;;if bit 4==1 (hopefully the value is 20), display 20 to 0
;
;
;
                                ;   Int1Dec
;
;        POINT number20    ;set tblptr to point to relevant character string
;
;        MOVLF 20,times    ;20 displays
;
;        MOVLF 20,value    ;might not be necessary, more testing needed
;
;        REPEAT_
;
;        DISPLAY value    ;display binary value 20x
;
;        decf value,F    ;decrement 20 to 0
;
;        rcall DisplayV    ;display decimal value (ASCII)
;
;        tblrd*+        ;read TABLAT, increment tblptrl
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY    ;brief delay so we can see what happens (.8s)
;
;        decf times,F    ;decrement, rewrite to itself
;
;        UNTIL_ .Z.        ;stop looping when Z bit flags
;
;        DISPLAY value    ;display binary value (21 displays, but we only want to decrement 20x, or it messes up the conditional)
;
;        rcall DisplayV    ;display decimal value (ASCII)
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY
;
;        rcall DELAY        ;brief delay so we can see what happens (.8s)
;
;        bcf INTCON3,INT1IF    ;reset flag
;
                                ;       return



;;;;;;; DecimalDisplay subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   

ByteDisplay

    lfsr 0,BYTESTR+8

    ;REPEAT_
L14

        clrf WREG

        rrcf BYTE,F

        rlcf WREG,F

        iorlw 0x30                 ;inclusive or a 1 or 0 with 0x30

        movwf POSTDEC0

        movf FSR0L,W

        sublw low BYTESTR

    ;UNTIL_ .Z.
    bnz    L14
RL14

   

    lfsr 0,BYTESTR

    MOVLF 0xC0,BYTESTR             ;location (where in the LCD will it be displayed)

    clrf BYTESTR+9                 ;sets last bit to 0 as an exit condition

    rcall DisplayV

        return

   

;;;;;;; DisplayV subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; This subroutine is called with FSR0 containing the address of a variable

; display string.  It sends the bytes of the string to the LCD.  The first

; byte sets the cursor position.  The remaining bytes are displayed, beginning

; at that position.



DisplayV

        bcf PORTE,0             ;Drive RS pin low for cursor positioning code

        ;REPEAT_
L15

          bsf PORTE,1           ;Drive E pin high

          movff INDF0,PORTD     ;Send upper nibble

          bcf PORTE,1           ;Drive E pin low so LCD will accept nibble

          bsf PORTE,1           ;Drive E pin high again

          swapf INDF0,W         ;Swap nibbles

          movwf PORTD           ;Write lower nibble

          bcf PORTE,1           ;Drive E pin low so LCD will process byte

          rcall T40             ;Wait 40 usec

          bsf PORTE,0           ;Drive RS pin high for displayable characters

          movf PREINC0,W        ;Increment pointer, then get next byte

        ;UNTIL_ .Z.             ;Is it zero?
        bnz    L15
RL15

        return



;;;;;;;;DisplayC subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; This subroutine is called with TBLPTR containing the address of a constant

; display string.  It sends the bytes of the string to the LCD.  The first

; byte sets the cursor position.  The remaining bytes are displayed, beginning

; at that position.

; This subroutine expects a normal one-byte cursor-positioning code, 0xhh, or

; an occasionally used two-byte cursor-positioning code of the form 0x00hh.



DisplayC

        bcf PORTE,0             ;Drive RS pin low for cursor-positioning code

        tblrd*                  ;Get byte from string into TABLAT

        movf TABLAT,F           ;Check for leading zero byte

        ;IF_ .Z.
        bnz    L16

          tblrd+*               ;If zero, get next byte

        ;ENDIF_
L16

        ;REPEAT_
L17

          bsf PORTE,1           ;Drive E pin high

          movff TABLAT,PORTD    ;Send upper nibble

          bcf PORTE,1           ;Drive E pin low so LCD will accept nibble

          bsf PORTE,1           ;Drive E pin high again

          swapf TABLAT,W        ;Swap nibbles

          movwf PORTD           ;Write lower nibble

          bcf PORTE,1           ;Drive E pin low so LCD will process byte

          rcall T40             ;Wait 40 usec

          bsf PORTE,0           ;Drive RS pin high for displayable characters

          tblrd+*               ;Increment pointer, then get next byte

          movf TABLAT,F         ;Is it zero?

        ;UNTIL_ .Z.
        bnz    L17
RL17

        return

      

;;;;;;; Delay subroutine;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



DELAY

    movlw 20                       ;20*10ms=200 msec delay

    movwf counter                  ;copies contents of WREG to register counter

    movlw 0                        ;reset WREG to 0 (clear it for later use if needed)

        again                      ;enter a loop

        rcall LoopTime             ;call up subroutine LoopTime for 10ms delay

        decf counter,F             ;decrement counter, rewrite to itself

        bnz again                  ;branch to again if NZ status bit is 0 (loops 100x until counter is 0)

return                          ;ALWAYS NECESSARY AT END OF SUBROUTINE

   

;;;;;;;;;;;;;;; random generator;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
summation
    movff number, WREG
    addwf sum,W
    daw
    movff WREG,sum
    swapf sum,F
    movff sum,PORTB
    rcall DELAY
    swapf sum,F
    movff sum,PORTB
     lfsr 1, mic                   ; displays the sum in decimal
     MOVLF 0xC6, POSTINC1
     movf sum, W
    swapf WREG,W
    bcf WREG,7
    bcf WREG,6
    bcf WREG,5
    bcf WREG,4
     movwf POSTINC1
    movf sum, W
    bcf WREG,7
    bcf WREG,6
    bcf WREG,5
    bcf WREG,4
    movwf POSTINC1
    MOVLF 0x00, INDF1
    lfsr 1, mic
    rcall DisplayV
 
   return

  
; HipriISR
                                ; rcall InitLCD
                                ;rcall Loop
;  bcf INTCON3,INT0IF
;  retfie
 
 
addition
    lfsr 1, HEXSTR              ; loads address of HEXSTR to fsr- to display HEXSTR
    MOVLF 0xC2, POSTINC 1
                                   ;rcall Convert; converts lower nibble of BYTE to hex and stores in W
    MOVLF 0x00, INDF1
    lfsr 1, HEXSTR                 ; loads address of HEXSTR to fsr0 to display
    POINT msg0x
    rcall DisplayC                 ; calls display
    rcall Display V                ; calls display V to display HEXSTR

   
;;;;;;;;;;Convert lower Nibble subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine converts lower nibble of Byte and converts it into ASCII hex value;;;

;convert
;    movff number, WREG
;    addwf laff, W
;    movff WREG, laff
;    swap laff, F
;    movff laff, WREG
;    bcf WREG,7
;    bcf WREG,6
;    bcf WREG,5
;    bcf WREG,4
;    movwf will
;    movlw 10
;    subwf will, W
   
   
;IF_ .N. ; if it is less than 9
;    bsf will, 4
;    ELSE_
;    movlw 9
;    subwf will,F
;    bsf will, 6
;    ENDIF_
;   
;    movff will, POSTINC1 ; now checking lower nibble
;    bcf will,7
;    bcf will,6
;    bcf will,5
;    bcf will,4
;   
;    movwf will
;     movlw 10
;     subwf will, W
;    
;     IF_.N. ;if it is less than 9
;     bsf will,4
;     bsf will,5
;     ELSE_
;     movlw 9
;     subwf will, F
;     bsf will,6
;     ENDIF_
;     movff will, POSTINC1; now checking lower nibble
;    
;     return
    
    
Randomn

    BCF STATUS,C

    rlcf WREG,F

    xorwf Random,W

    rlcf WREG,F

    rlcf WREG,F

    rlcf WREG,F

    rlcf Random,F

    xorwf Random,F

    movff Random,b1

    andlw B'00000111'              ;8 random numbers

    andwf b1,F

    DISPLAY b1

    rcall DELAY

return
Delay

    MOVLF 100,mike

    bnz again

    rcall LoopTime

    decf mike,F

        bnz again

   

    return

   

   

DICE1                           ; number1 on dice

    bsf PORTD,2

    clrf PORTC

    POINT One_1

    rcall DisplayC

    rcall Delay

    return



DICE2                           ; number2 on dice

    clrf PORTD

    bsf PORTC,0

    bsf PORTC,5

    bcf PORTC,1

    bcf PORTC,2

    bcf PORTC,3

    bcf PORTC,4

    POINT Two_2

    rcall DisplayC

    rcall Delay

    return

   

DICE3                           ; number3 on dice

    bsf PORTD,2

    bsf PORTC,0

    bsf PORTC,5

    bcf PORTC,1

    bcf PORTC,2

    bcf PORTC,3

    bcf PORTC,4

    POINT Three_3

    rcall DisplayC

    rcall Delay

    return

   

DICE4                           ; number4 on dice

    clrf PORTD

    bsf PORTC,0

    bsf PORTC,2

    bsf PORTC,3

    bsf PORTC,5

    bcf PORTC,1

    bcf PORTC,4

    POINT Four_4

    rcall DisplayC

    rcall Delay

    return

   

DICE5                           ; number5 on dice

    bsf PORTD,2

    bsf PORTC,0

    bsf PORTC,2

    bsf PORTC,3

    bsf PORTC,5

    bcf PORTC,1

    bcf PORTC,4

    POINT Five_5

        rcall DisplayC

    rcall Delay
   
DICE6                           ; number6 on dice

    clrf PORTD

    bsf PORTC,0

    bsf PORTC,1

    bsf PORTC,2

    bsf PORTC,3

    bsf PORTC,4

    bsf PORTC,5

    POINT Six_6

    rcall DisplayC

    rcall Delay
;;;;;;;;;;;;;;;interrupt;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;calculating result;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   

;;;;;;; LoopTime subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;

; This subroutine waits for Timer0 to complete its ten millisecond count

; sequence. It does so by waiting for sixteen-bit Timer0 to roll over. To obtain

; a period of precisely 10000/0.4 = 25000 clock periods, it needs to remove

; 65536-25000 or 40536 counts from the sixteen-bit count sequence.  The

; algorithm below first copies Timer0 to RAM, adds "Bignum" to the copy ,and

; then writes the result back to Timer0. It actually needs to add somewhat more

; counts to Timer0 than 40536.  The extra number of 12+2 counts added into

; "Bignum" makes the precise correction.



Bignum  equ     65536-25000+12+2



LoopTime

       ;REPEAT_
L18

       ;UNTIL_ INTCON,TMR0IF == 1       
       btfss INTCON,TMR0IF
       bra    L18
RL18

        movff INTCON,INTCONCOPY  ;Disable all interrupts to CPU

        bcf INTCON,GIEH

        movff TMR0L,TMR0LCOPY   ;Read 16-bit counter at this moment

        movff TMR0H,TMR0HCOPY

        movlw low Bignum

        addwf TMR0LCOPY,F

        movlw high Bignum

        addwfc TMR0HCOPY,F

        movff TMR0HCOPY,TMR0H

        movff TMR0LCOPY,TMR0L   ;Write 16-bit counter at this moment

        bcf INTCON,TMR0IF       ;Clear Timer0 flag

        bsf INTCON,GIE

       return

   

;;;;;;;;;constant strings;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LCDstr db 0x33,0x32,0x28,0x01,0x0c,0x06,0x00  ;Initialization string for LCD

message1 dB  "\x80Hello!! \x00"

message2 dB  "\xc7We      \x00"

message3 dB  "\xc6Wel     \x00"

message4 dB  "\xc5Welc    \x00"

message5 dB  "\xc4Welco   \x00"

message6 dB  "\xc3Welcom  \x00"

message7 dB  "\xc2Welcome \x00"

message8 dB  "\xc1Welcome \x00"

message9 dB  "\xc0elcome T\x00"

message10 dB "\xc0lcome To\x00"

message11 dB "\xc0come To \x00"

message12 dB "\xc0ome To D\x00"

message13 dB "\xc0me To Di\x00"

message14 dB "\xc0e To Dic\x00"

message15 dB "\xc0 To Dice\x00"

message16 dB "\xc0To Dice \x00"

message17 dB "\xc0o DIce \x00"

message18 dB "\xc0 Dice G\x00"

message19 dB "\xc0Dice Ga\x00"

message20 dB "\xc0ice Gam\x00"

message21 dB "\xc0ce Game\x00"

message22 dB "\xc0e Game \x00"

message23 dB "\xc0Game  \x00"

message24 dB "\xc0ame   \x00"

message25 dB "\xc0me    \x00"

message26 dB "\xc0e     \x00"

       

messagec dB  "\xc0        \x00"  ;Push the Button to Start!

message29 dB "\xc7P/x00"

message30 dB "\xc6Pu/x00"

message31 dB "\xc5Pus/x00"

message32 dB "\xc4Push/x00"

message33 dB "\xc3Push /x00"

message34 dB "\xc2Push t/x00"

message35 dB "\xc1Push th/x00"

message36 dB "\xc0Push the/x00"

message37 dB "\xc0ush the /x00"

message38 dB "\xc0sh the B/x00"

message39 dB "\xc0h the Bu/x00"

message40 dB "\xc0 the But/x00"

message41 dB "\xc0the Butt/x00"

message42 dB "\xc0he Butto/x00"

message43 dB "\xc0e Button/x00"

message44 dB "\xc0 Button /x00"

message45 dB "\xc0Button t/x00"

message46 dB "\xc0utton to/x00"

message47 dB "\xc0tton to /x00"

message48 dB "\xc0ton to S/x00"

message49 dB "\xc0on to St/x00"

message50 dB "\xc0n to Sta/x00"

message51 dB "\xc0 to Star/x00"

message52 dB "\xc0to Start/x00"

message53 dB "\xc0o Start!/x00"

;message54 dB"\x8000000000\x00"    ;modular way to end the program (add when I finish the important stuff)

One_1 db "\x80Dice0001    \x00"  ; One 1

Two_2 db "\x80Dice0010   \x00"  ; Two 2

Three_3 db "\x80Dice0011   \x00"  ; Three 3

Four_4 db "\x80Dice0100    \x00"  ; Four 4

Five_5 db "\x80Dice0101    \x00"  ; Five 5

Six_6 db "\x80Dice0100    \x00"  ; Six 6

Hex_1 db "\xC00x01   \x00"      ;Hex One

Hex_2 db "\xC00x02   \x00"      ;Hex Two

Hex_3 db "\xC00x03   \x00"      ;Hex Three

Hex_4 db "\xC00x04   \x00"      ;Hex Four

Hex_5 db "\xC00x05   \x00"      ;Hex Five

Hex_6 db "\xC00x06   \x00"      ;Hex Six


;numberc dB "\x8000000000\x00"    ;modular way to end the program (in reverse) but it didn't work

number00 dB "\x87Pl      \x00"  ;0 to 20 in ASCII (for decimal display)

number01 dB "\x86Pla     \x00"

number02 dB "\x85Play    \x00"

number03 dB "\x84Playe   \x00"

number04 dB "\x83Player  \x00"

number05 dB "\x82Player 1\x00"

number06 dB "\x81layer 1 \x00"

number07 dB "\x80ayer 1 R\x00"

number08 dB "\x80yer 1 Ro\x00"

number09 dB "\x80er 1 Rol\x00"

number10 dB "\x80r 1 Roll\x00"

number11 dB "\x80 1 Roll \x00"

number12 dB "\x801 Roll N\x00"

number13 dB "\x80 Roll No\x00"

number14 dB "\x80Roll Now\x00"

number15 dB "\x80oll Now \x00"

number16 dB "\x80ll Now  \x00"

number17 dB "\x80l Now   \x00"

number18 dB "\x80 Now    \x00"

number19 dB "\x80Now     \x00"

number20 dB "\x80ow      \x00"

number21 dB "\x80w       \x00"

number22 dB "\x80        \x00"



numb00 dB "\x87Pl      \x00"   

numb01 dB "\x86Pla     \x00"

numb02 dB "\x85Play    \x00"

numb03 dB "\x84Playe   \x00"

numb04 dB "\x83Player  \x00"

numb05 dB "\x82Player 2\x00"

numb06 dB "\x81layer 2 \x00"

numb07 dB "\x80ayer 2 R\x00"

numb08 dB "\x80yer 2 Ro\x00"

numb09 dB "\x80er 2 Rol\x00"

numb10 dB "\x80r 2 Roll\x00"

end
Mod edit- code tags. JohnInTX
 
Last edited by a moderator:

JohnInTX

Joined Jun 26, 2012
4,556
Welcome to AAC!
Post the error list, please.
Also, tell us what assembler and IDE you are using.

One immediate problem is that you have enabled interrupts but the service routines are traps and will hang the code right there.
 
Last edited:
Top