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
Related projects
Exploring the World of PIC Microcontrollers: An Architectural Overview
A Peripheral Interface Microcontroller (PIC), developed by General Instruments Microcontrollers in 1993, operates under software control and is programmed to execute various...
LCD & Display Projects · PIC16C842-Wire LCD Interface using PIC16C84
Alphanumeric LCD displays have become very popular for microcontroller applications because they can add a lot to a project in a variety...
LCD & Display Projects · PIC16C84Using an LCD’s for Graphics Animation using PIC16C84
This project uses Myke's 2-Wire LCD Interface from last week and will help teach you "Graphics Animation" using LCD's. Last week, I...
LED ProjectsAn Application-Driven Microcontroller Curriculum
Understanding how to apply microcontrollers lies at the core of modern embedded systems education. This student project takes an experiential approach to...
LED ProjectsBuild this microcontroller controlled rainbow flying disc – and then throw it!
Hello all and welcome to this super simple and inexpensive instructable. If you like throwing frisbees AND you like flashing lights AND...
LED ProjectsLED Scrolling Display Project Working With Circuit Diagram
We normally use a simple static LED display screen to convey a message. Earlier, when we want to display large data, we...
