Skip to main content

Simple flashing LED



Project description:   
An LED is connected to one of the port pins of a PIC microcontroller. The

LED is flashed continuously with 1-s interval.
 

This project is so simple that any type of PIC microcontroller can be used.

As shown in Figure 5.1, a PIC16F84 type microcontroller is chosen for this project. Bit 0 of PORTB (RB0) is connected to a small LED through a current-limiting resistor. The voltage drop across an LED is approxi- mately 2 V. Assuming an LED current of 10 mA, the value of the resistor can be calculated as



R      V I

   5     2       0.3 K
10 mA


the nearest value is 330  




 ‘*************************************************************

‘                         LED FLASHING PROGRAM
‘                         ======================

‘ This program flashes an LED connected to port RB0 of PORTB. The
‘ Led is flashed with 1 second intervals.

‘ Author:            Dogan Ibrahim
‘ Date:               October, 2005
‘ Compiler:        PicBasic
‘ File:                 LED1.BAS

‘ Modifications
‘ ==========

‘*************************************************************

‘ SYMBOLS

Symbol LED     0                                                               ‘ Define RB0 as LED Symbol TRISB     $86                                                        ‘ TRISB address Symbol PORTB     $06                                                      ‘ PORTB address

‘ START OF MAIN PROGRAM

POKE TRISB, 0                                                    ‘ Set PORTB pins as outputs

AGAIN:
HIGH LED                                                            ‘ Turn ON LED PAUSE 1000                                                         ‘ Wait 1 second

LOW LED                                                             ‘ Turn OFF LED PAUSE 1000                                                         ‘ Wait 1 second

GOTO AGAIN                                                      ‘ Repeat

END                                                                      ‘ End of program






‘************************************************************

‘                           LED FLASHING PROGRAM
‘                           ======================

‘ This program flashes an LED connected to port RB0 of PORTB. The
‘ LED is flashed with 1 second intervals.

‘ Author:           Dogan Ibrahim
‘ Date:               October, 2005
‘ Compiler:       PicBasic Pro
‘ File:                LED2.BAS

‘ Modifications
‘ ==========

‘*************************************************************

‘ DEFINITIONS

LED VAR PORTB.0                                                          ‘ Define RB0 as LED

‘ START OF MAIN PROGRAM

TRISB     0                                                                ‘ Set PORTB pins as outputs

AGAIN:
LED     1                                                                    ‘ Turn ON LED PAUSE 1000                                                              ‘ Wait 1 second

LED     0                                                                    ‘ Turn OFF LED PAUSE 1000                                                              ‘ Wait 1 second

GOTO AGAIN                                                     ‘ Repeat

END                                                                           ‘ End of program



Comments

Popular posts from this blog

ANALOGUE to DIGITAL (A/D) Converter in PIC16F87X Series

ANALOGUE to DIGITAL (A/D) Converter What is a Sample & Sample rate? A "sample" is a single measurement of amplitude. Sample rate is simply the number of samples (or measurements of amplitude) taken per second. Sampling Intervals Quantization The samples are assigned a binary number approximating their sampled value. Quantizing divides up the sampled voltage range into 2n-1 quantizing intervals, where “n” is the number of bits per sample (the sampling resolution). For example, an 8-bit system can identify 28 (256) discrete sampled signal values (255 quantizing intervals). The amplitude of such a signal can occupy the entire quantizing range. A/D Reference Voltages Successive Approximation A/D Example 1 Example 2  Example 3 A/D Converter Modules in PIC16F87X series 28-pin devices has 5 modules. (AN0-AN4)         PIC16F873        PIC16F876 4...

another knight Rider

Code Breakdown: 1. Preprocessor Directives: #include <pic.h> : Includes the header file pic.h , which contains definitions and declarations specific to PIC microcontrollers. #define _XTAL_FREQ 4000000 : Defines a preprocessor constant _XTAL_FREQ with the value 4000000, representing the crystal frequency in Hertz. This value is used by the compiler to calculate delay times and other timing-related calculations. 2. main() Function: Initialization: PORTC = 0xff; : Sets all bits of PORTC to 1. TRISC = 0x00; : Configures all pins of PORTC as outputs. Main Loop: First For Loop: Iterates from 0 to 1 (effectively executing once). Sets individual bits of PORTC to 1, one at a time, and delays for 100ms between each bit setting. This creates a sequential lighting effect from left to right. Second For Loop: Iterates from 0 to 1 (effectively executing once). Sets individual bits of PORTC to 1, starting from the rightmost bit and moving left, and delays for 100ms bet...

Voltmeter

This code to read an analog temperature sensor, convert the reading to a digital value using the ADC, and display the temperature on a 4-digit 7-segment display. The display is updated periodically based on a timer interrupt. 1.Initialization: Setting up ports, configuring ADC, and Timer0. 2.Infinite Loop: Continuously reads analog input and updates the display. 3.ADC Conversion: Reads analog voltage from a sensor. 4.Voltage Calculation: Converts ADC value to voltage. 5.Digit Extraction: Extracts individual digits from the temperature/voltage value. 6.Display Function: Displays the digits on a 4-digit 7-segment display with slight delays. --------------------------------------------- #include <pic.h> // Include the header file for PIC microcontroller family. unsigned char PORTB_value[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; // Array containing values for 7-segment display. unsigned int a2d_value,temp; // Variables for analog to digital conversion and temporary sto...