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

PicBasic and PicBasic Pro programming

B ASIC is one of the oldest and one of the easiest pr o g ramming languages to lea r n. Y ou should be a b le to lea r n and pr o g ram in B ASIC in less than an hou r . In this chapte r , w e shall be looking at the principles of pr o g ramming PIC microcontrollers using the PicBasic and PicBasic Pro lan- guages. Both these languages are v e r y similar to the standard B ASIC language but th e y h a v e some modi f ied and some additional inst r uctions speci f ical l y for microcontroller pr o g ramming. Both PicBasic and PicBasic Pro languages h a v e been d e v eloped b y the microEngineering Labs Inc. PicBasic is a l o w e r -cost, simpler language than PicBasic Pro and it is aimed at students and hob b yists. PicBasic Pro is more e xpens i v e, aimed at professionals, and includes additional com- mands for more ad v anced inst r uctions. T a b le g i v es a list of the comparison of PicBasic and PicBasic Pro languages. Before w e pro- ceed to the chapter...

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...

timer_500mS

Code Breakdown: 1. Preprocessor Directives: #include <pic.h> : Includes the header file pic.h , which contains definitions and declarations specific to PIC microcontrollers. 2. Variable Declarations: unsigned char count = 0; : Declares an unsigned character variable count and initializes it to 0. This variable is used to keep track of the number of 50ms intervals that have elapsed. 3. main() Function: Initialization: TRISC = 0; : Configures PORTC as output pins. PORTC = 0; : Clears the output pins on PORTC. T0CS = 0; : Selects the internal clock source (Fosc/4) for TMR0. PSA = 0; : Assigns the prescaler to TMR0. PS2 = 1; PS1 = 1; PS0 = 1; : Sets the prescaler to 256, providing a timer tick every 50 milliseconds. TMR0 = 61; : Initializes TMR0 with the value 61 to generate a 50ms delay. RC0 = 1; : Sets the output on RC0. Main Loop: while (1) { ... } : The main loop continues indefinitely. Interrupt Handling: if (T0IF) { ... } : Checks if the TMR0 interrupt ...