Circuit for a test circuit with the PIC16F84A

19,787

Circuit Image

To start working with microcontrollers, several essential items are required. The PICSTART Plus kit, part number DV003001, was purchased from Microchip. This kit contains a sample PIC16F84 microcontroller chip, which in this case is a PIC16F84A chip. This chip features 18 pins and operates as an 8-bit device. The data sheet for the PIC16F84A consists of only 88 pages, making it simpler to navigate compared to the 18F chip. However, it is important to note that the 16F series does not support USB connectivity. The kit also includes a programmer unit, which is responsible for writing programs to the chip and interfaces with a computer's serial port. For newer computers, a USB to Serial Converter may be necessary. The programmer is compatible with both the 18-pin PIC16F and the 40-pin PIC18F chips. Additionally, the kit provides a compiler, assembler, and the MPLAB IDE, which offers a development environment for various chips and supports programming in C and Assembly languages. The IDE includes a simulator and debugger. While awaiting the kit's arrival, it is advisable to read the PIC16F84A data sheet, particularly the pin configuration on page 3. Special attention should be paid to the oscillator circuit, which is essential for operation. The PIC16F84A chip supports four oscillator configurations: LP (Low Power Crystal), XT (Crystal/Resonator), HS (High Speed Crystal/Resonator), and RC (Resistor/Capacitor). A standard oscillator circuit typically employs a crystal and two capacitors, ranging from 15 pF to 33 pF. These components can be sourced from The Electronic Goldmine. Additional required items include a breadboard, an IC extraction tool, a 5-volt regulator (7805), LEDs, and resistors. For the LEDs, low-power 15mA 3-volt types were used. The resistor value was calculated as R=(5V-3V)/(15mA)=133kΩ, leading to the use of 150 kΩ resistors. These components are available at local RadioShack stores.

The provided assembly code snippet demonstrates a simple LED control program for the PIC16F84A microcontroller. The program initializes the microcontroller's registers and sets up the necessary configurations to control the state of LEDs connected to PORTB. The initial setup includes defining processor-specific variables and configuring the `_CONFIG` settings to disable code protection and watchdog timer features while enabling the power-up timer with the XT oscillator configuration.

The main program flow begins by loading a specific value into the working register and configuring PORTB pins for output. The program enters a loop where it calls a subroutine to change the state of the LEDs and then pauses for a brief period before repeating the process. The delay mechanism is implemented using two delay counters, and the `change_leds` subroutine manipulates the `led_counter` variable to control which LEDs are illuminated.

The program concludes with a reset routine that reinitializes the `led_counter` to a predefined value, ensuring that the LED control cycle can repeat indefinitely. This example illustrates fundamental microcontroller programming concepts, including register manipulation, subroutine calls, and delay generation, which are essential for developing embedded applications.You will need a few items to begin working with microcontrollers. I purchased the PICSTART Plus Part Number: DV003001 kit from Microchip. This kit includes the following: A sample PIC16F84 microcontroller chip: My kit actually came with a PIC16F84A chip. This is a 18 pin, 8-bit chip. The PIC16F84A data sheet is only 88 pages. So this is easier than the 18F chip. But the 16F chips do not support USB. The programmer unit: This is the device that will write the program to the chip. This will interface with a computer`s serial port. On newer computers, you may need an additional USB to Serial Converter. I am able to use this programmer for the 18 pin PIC16F and the 40 pin PIC18F chips. Compiler, Assembler and IDE. The kit comes with a copy of the MPLAB IDE. This provides a development environment for many different chips and supports C and Assembler programming languages. The IDE contains a simulator and a debugger. While you wait for the kit to be delivered, I would recommend reading the PIC16F84A data sheet. You will need to review the pin configuration on page 3. Make special note of the following: In addition to the above, you will also need some basic electronics components.

You will need an oscillator circuit. Section 6. 2 covers the oscillator configurations. The 16F84A chip has four possible oscillator configurations: LP Low Power Crystal, XT Crystal/Resonator, HS High Speed Crystal/Resonator and RC Resistor/Capacitor. A typical oscillator circuit uses a crystal and two capacitors ranging from 15 pF - 33 pF. You can get the crystal and capacitors from The Electronic Goldmine. You will need a breadboard, a IC Extraction Tool, a 5 volt regulator (7805), some LEDs and resistors.

I used low power 15mA 3volt LEDs. Doing the math, you find R=(5volt-3volt)/(15mA)=133kOhm. So, I used 150 kOhm resistors with these LEDs. You can find these at a local RadioShack. list p=16F84A #include ; processor specific variable definitions radix hex _CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC udata Delay1 res 1 ; reserve a byte for a delay counter Delay2 res 1 ; reserve another byte for a delay counter led_counter res 1 ; reserve one byte for our led counter org 0x005 start movlw b`00001111` ; load W with b`00001111` ; we will reserve RB7, RB6, RB5, RB4 for output tris PORTB ; enable the selected pins for output clrf PORTB ; clear PORT B movlw b`00010000` ; move b`00001111` to register w movwf led_counter ; move register w to led_counter my_loop call change_leds ; changed the leds call pause ; wait a few cycles goto my_loop ; repeat ; - ; pause ; - pause my_delay: DECFSZ Delay1, 1 ;Decrement Delay1 by 1, skip next instruction if Delay1 is 0 GOTO my_delay DECFSZ Delay2, 1 GOTO my_delay return ; - ; change_lights ; - change_leds decf led_counter, 1 ; led_counter = led_counter - 1 swapf led_counter, 0 ; we need to shift the value of led_counter ; so that the lower half of the byte ; displays on pins 4-7 ; This new value will be in register w movwf PORTB ; move w to PORTB movfw led_counter bz reset_counter ; if led_counter = 0, then jump to `reset_counter` return reset_counter ; reset led_counter to b`00010000` movlw b`00010000` ; move b`00001111` to register w movwf led_counter ; move register w to led_counter return end 🔗 External reference