Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F84 Dice Game

Status
Not open for further replies.

sparky72

Member
First of all let me say that this is just a hobby for me in my retirement years, that I enjoy very much. My knowledge of micro controllers is very limited, and I am learning, but after many hours of trying to get this thing to work I have decided that I need some help. The original code is assembly and uses a 16F84 pic. I want to convert the program to use a 16F628A pic. I have added the movlw 0x07 & movwf CMCON to just after the org
0000 instruction, to the original code. My question is, since the original code for the 16f84 uses an external RC osc. and I want to use the internal OSC. in the 16f628A. What changes do I need to make in the configuration settings? The schematic has a 10k pull up resistor to the MCLRE pin. Do I need to disable this using the 16f628A pic? I have tried many config settings that would quick build and load into the pic using a pickit2 programmer but would not work. I have attached a copy of the schematic. Thanks in advance for any help that I may receive.
 
Dice game

Here is the attachment
 

Attachments

  • image5.gif
    image5.gif
    33.5 KB · Views: 547
It would help to post the code aswell as the diagram.

Have you constructed the circuit as shown?
I notice the diagram doesn't show the power and ground for the Pic.
 
Last edited:
Dice game

Yes I have connected vdd and vss. I am using a L7805 regulator with a 9 volt battery. Thanks for the quick reply.
 
What about the config fuse for activating the internal oscillator?
 
Last edited:
This is where I seem to be hung up. I have used Nigel's 0x3D18 but it did not work. All the leds would light up when the button switch was closed but would stay lit until the button was released. No sequencing takes place.
 
Ok use this:

3F30

That gives Power on reset, Mclre, and,Internal osc no clk out.

And have a look here:

file:///C:/Program%20Files/Microchip/MPASM%20Suite/Template/Code/

For the details on the 16F628 config setup.

BTW, as you're new to this, when playing with the ADC inputs, be careful NOT to feed them anything over 5V unless u have a healthy 1k-10K or so in series. I fried the adc on a 16f886 last Sunday diddling about on a breadboard...forgot the resistor.
 
Last edited:
All the leds would light up when the button switch was closed but would stay lit until the button was released. No sequencing takes place.
Exactly what I found, once I'd got it assembled by removing;
Code:
LEDTest		EQU	B'00001111'

But once I'd commented out 'Sleep'

Code:
MAINLOOP
				; enable interrupts on port B
	   movfw	  PORTB
	   movlw	B'00010000'	; Leave the GIE bit off, we simply want to
				; wake from sleep,  not jump to an interrupt
				; routine.
				; and enable INT (PB0) interrupts.
	   movwf	INTCON		; set the interrupt reg.

	
	   ;sleep			; wait for an interrupt.
	

				; yay, we have a button down...
	   movfw	PORTB
	   call	    short_delay

	   movlw	b'00000000'	; dissable interrupts
	   movwf	INTCON

it seemes to work with your (Nigel's) config. ;)
 
HouseOfwax Things are looking up a bit. At least now when I apply power some leds light up. When I push the switch on all the leds light up. If I hold it on for 5 seconds or so, I will get a different combination of leds to light up. However they do not roll, they just change each time I push the switch,and not necessarily look like a dice. Another thing the leds seem to flicker all the time they are lit.
 
We both seem to have the exact same results. I was using Nigel's LED board design which is in no way the same as the diagram, though gives me an indication.
I can't say much more on the subject, as I didn't have the time to look too closely at the code. Though, I do have a 16F84 around which I may try with the original code tomorrow. Having said that, I couldn't compile the .ASM that you supplied without the removal of previously said line.
Though through a bit of Googling, I do note that many people have successfully built the project. . . :?
 
Thanks for staying with me on my little project. I would be interested to know how you make out using the 16f84. Anther concern that I have is, when the dice roll, are the leds supposed to flash in different sequences and then come to a stop or is the sequencing done internally only and show only when you release the switch?
 
RandomA is not changing in the following sub-routine:

Code:
Calculate_Result    
        movfw    RandomA        ; get the random number
        andlw    7        ; get the lower 3 bits        
        movwf    DieAVal        ; make them the dice value
        swapf    RandomA, 0
        andlw    7
        movwf    DieBVal
        return

Try adding:

Code:
Calculate_Result    
        movfw    RandomA        ; get the random number
        andlw    7        ; get the lower 3 bits        
        movwf    DieAVal        ; make them the dice value
        swapf    RandomA, 0
        swapf    RandomA, 1
        andlw    7
        movwf    DieBVal
        return
 
Thanks colin55 & HouseOFWax. I tried your suggestions but still a no go. The code will compile, and load into the chip using the Pickit2 program but still no luck. I wonder if anyone has got the dice game working the way it should using a 16f628A chip? I would be pleased to hear from anyone that did. Anyone that I saw on the net were using the 16f84. Meanwhile I will keep trying to get this thing to work, while still being open for any more suggestions. If I have any success I will post my results
 
are the leds supposed to flash in different sequences and then come to a stop or is the sequencing done internally only and show only when you release the switch?

Having looked closer at the code, yes, they do flash in different sequences and then come to a stop. However, what I have discovered is the timing is far too fast to be able to see it.

I have lengthened the timings and they do change and then stop. I also got rid of the flashing by commenting out the clrf DieA / clrf DieB (which is not needed since we're not using the sleep command).
Code:
; display the result of the dice roll
Display
	    call	Display_Result
	    movlw	0x100;80			; very long delay
	    call	var_delay
	
	    ;clrf	DieA			; we have finished showing the value
	    ;clrf	DieB			; turn off all leds, and jump
								; back to the main loop.  
								; we will sleep shortly, till
								; somebody wakes us up...
	    goto   MAINLOOP

I didn't manage to try the 16f84 as the one I have has got RB0 (internally) damaged.

I'd suggest playing with the timing code and once things are slow enough to see what is going on, try Colin55's suggestion.
 
After a bit more messing about with the authors timing code, I ripped it out and replaced it with Nigel's.
It now seems much better, though as I said, I don't have a 'die' LED arrangement.
Have a look, see what you think.
 

Attachments

  • Dicegame_test.asm
    12.1 KB · Views: 188
Good morning HouseOFwax. I am having a problem building the asm file that you sent to me. It is saying that the countA, CountB and count1 are not previously defined. Looking forward to hearing from you.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top