Friday, August 28, 2009

hardware of pic microcontroller

PIC Microcontroller Circuit Hardware Description

There are two I/O ports in the 16C54 - one 8 bit & the other 4 bit. The 8 bit port, Port B, is connected to the 7 segment display. Three pins of the 4 bit Port A are used. The other pin is tied high. Pin 4 of the PIC is also tied high to give a power-on reset.

A 150 ohm resistor acts as a current limiting resistor for each display. PIC ports have a maximum sourcing current of 40mA. The maximum current for the LED display is 200mA so it is the PIC that R1 and R2 is protecting, not the display.

The PIC uses its internal RC clock oscillator option (with the 10K resistor, R3, and the 330pF capacitor, C2) and runs at about 330kHz. The switch is connected to input RA0. Normally this line is pulled high via R4 to +5V, but when the switch is closed the input is pulled low. The software detects the falling edge as a dice roll.

Software Description

When power is first applied, the PIC does a power-on reset. It goes to Start. The first task is to initialize the various internal options such as the direction of the I/O ports and the status of any outputs (high or low.) The watchdog timer
is switched on and the initial value of some RAM locations are set.

The dice now settles down in the main program loop, Main. It continuously loops about 4000 times a second to see if the switch has been pressed, flash the decimal point, generate the next random number and reset the watchdog timer. Then when a Roll (switch press) is detected, the program jumps through to Main02. The two dice are rolled and displayed sequentially in Output. Note how the second random number is generated by the length of time the roll switch is depressed. Display outputs the random numbers to the 7 segment LED displays by multiplexing to them. At the end of Output the program returns to Main.

Various subroutines - Display, Delay, Roll, Flash, Random and two look-up tables for the display, Look_Up_Seg and Look_Up_Digit are listed in the final part of the program. Note the Rand01 code segment in Random and why it is there.

If there is no keypress for 50 flashes then the PIC goes into sleep mode at the end of the Flash subroutine. The oscillator is turned off and ports A & B are configured as inputs.

Now with the PIC in sleep mode the watchdog timer is not being reset anymore. It was not turned off when the PIC went to sleep. It now times out about every 1.3 seconds to check if the key is being pressed. If no keypress is found then it goes back to sleep. But if it is then the PIC wakesup, resets the ports, starts to flash the decimal point and it is ready to roll again on the next keypress.

No comments:

Post a Comment