a led dice using a pic 16f84

14

Upload: daryl-jayson-manalo

Post on 26-Mar-2015

258 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: A LED Dice using a PIC 16F84
Page 2: A LED Dice using a PIC 16F84

A die (plural dice, from Old French dé, from Latin datum "something which is given or played”) is a small throwable object with multiple resting attitudes, used for generating random numbers or other symbols.

A traditional die is a cube (often with corners slightly rounded), with each of its six faces showing a different number. The design as a whole is aimed at each die providing one randomly determined integer, in the range from one to six, with each of those values being equally likely.

Page 3: A LED Dice using a PIC 16F84
Page 4: A LED Dice using a PIC 16F84

We will design an electronic simulation of 2 dice, implemented using LEDs. A single push button will control the rolling of the dice in the following manner;◦ When the button is pushed for a short period (say less

that 0.5 sec), the dice turn on, and display the result of the last roll.

◦ If the button is pushed for greater than about 0.5 Seconds, both dice are cleared then roll independently, eventually slowing, and stopping after the button is released.

◦ In all cases, the result is displayed for 50 seconds, and then the dice turns itself off.

Page 5: A LED Dice using a PIC 16F84

Opposing Corner dots (1) and (3) appear simultaneously.

Opposing Corner dots (2) and (4) appear simultaneously.

Middle dots (5) and (6) appear simultaneously.

The Central dot (7) operates independently.

The good thing that this means is that we can present a single die display using only 4 output pins on the micro.  To display 2 separate dies, we only needed 8 pins.

Page 6: A LED Dice using a PIC 16F84

Driving LEDs with a PIC microcontroller is a simple exercise. Because the outputs can drive 50mA, we can drive the LED directly with a series current limiting resistor to protect the LED. The diagram shows typical connection details.

Page 7: A LED Dice using a PIC 16F84

A single push button interface into a PIC can be implemented simply by connecting a push button between the supply voltage, (VCC) and an input that provides an interrupt. The figure provides an example. Note that the input is held ‘low’ by a 4k7 resistor to ensure that random noise picked up on the input pin does not cause an input to be recorded.

Page 8: A LED Dice using a PIC 16F84

In our circuit, the microprocessor consumes approximately 7uA while it is in its standby ‘sleep’ mode.

The current consumption will increase to about 120mA during operation

Page 9: A LED Dice using a PIC 16F84

First, the word that we want to write is loaded into the ‘W’ register, then the ‘W’ register is written to Port B.

We can use this sequence of operations to output the bit pattern to display a dice roll of 6. From the schematic diagram, we can see that the first die is attached to Port A, bits 0 – 3 in the following way;

Port A(0) - Centre LED Port A(1) - Corner LEDs (1) and (3). Port A(2) - Corner LEDs (2) and (4). Port A(3) - Middle LEDs (5) and (6).

Page 10: A LED Dice using a PIC 16F84

To display the pattern for a 6, all corner LEDs, and all middle LEDs are on, but the centre LED is off. This equates to bit pattern of b’00001110’. So, to display a 6, we simply execute the instructions:

MOVLW B’00001110’ MOVWF PortA Similarly, to display a 1 (the centre LED), we

would use; MOVLW B’00000001’ MOVWF PortA

Page 11: A LED Dice using a PIC 16F84

In order to wake up from sleep mode, we need to have an ‘interrupt’ occur. Interrupts can be caused from a variety of sources, but they always signal some external change.

The LED Dice project that we are building has the pushbutton connected to bit 1 of Port B (PB0). This pin is also functions as an ‘interrupt’ input. When the voltage level on this pin changes, an interrupt is generated, causing the PIC to stop whatever it was doing, and to do something else. It is this interrupt that causes the PIC to wake up from it’s sleep mode.

Page 12: A LED Dice using a PIC 16F84

In our project, the easiest method that we can use to generate a random number is to sample the internal timer (TMR0), which is constantly incrementing at ¼ of the clock speed (about 256KHz), and store it in a variable continuously, as long as the button is held down.

Our PIC 16F84 microprocessor has 68 memory locations that are able to be used as variables. To define a variable, we simply declare a constant that refers to a particular memory location, and store numbers in that memory location as required.

Page 13: A LED Dice using a PIC 16F84
Page 14: A LED Dice using a PIC 16F84

Presentors: ECE 4202Tep LascierasManalo, Daryl Jayson I.Boyet NocheOblea, JaysonVivas, Jeff