This is my first simple PIC program. It will flash an LED continuously at approximately 1Hz. It is a very simple loop that delays for 500 milliseconds (half a second) with the LED on, and then delays for 500ms with the LED off. Thus, the LED flashes at 1 Hz!
The schematic for this circuit shows that the wiring is simple: connect a crystal oscillator across pins 15 and 16 and add the capacitors to ground. Wire a 4k7 resistor to the MCLR reset pin 4 so the PIC will reset itself at startup. Then connect the LED via a resistor to pin 17.
When a 4 Mhz cryztal is used with PIC 16C84, the LED will flash at 1 Hz.
This program is available as:
title "Flash - Flash an LED on an off at 1Hz" ; Mark Crosbie 8/22/98 ; ; The Program simply sets up Bit 0 of Port "A" to Output and then ; loops, setting the value alternatively low and high ; ; Hardware Notes: ; Reset is tied through a 4.7K Resistor to Vcc and PWRT is Enabled ; A 220 Ohm Resistor and LED is attached to PORTA.0 and Vcc ; LIST P=16C84, R=DEC errorlevel 0,-305 INCLUDE "P16C84.inc" ; Registers Temp equ 12 ; 16 Bit Dlay Variable __CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON ; Mainline of Flash org 0 clrf PORTA ; Clear all the Bits in Port "a" clrf STATUS bsf STATUS, RP0 ; Goto Bank 1 to set Port Direction bcf TRISA, 0 ; Set RA0 to Output bcf STATUS, RP0 ; Go back to Bank 0 Loop movlw 1 ; Turn on the LED on Port A movwf PORTA ; call Dlay ; Delay Before Changing Values movlw 0 ; Turn off the LED on Port A movwf PORTA ; call Dlay ; Delay Before Changing Values goto Loop ; Dlay Routine - Delay a Half Second before Returning
For more detail: LED flasher using PIC16C84 Microcontroller