flashing a led
TRANSCRIPT
-
8/3/2019 Flashing a LED
1/5
- AL Azhar University-Gaza
FACULTY OF ENGINEERINGAND INFORMATION TECHNOLOGY
DEPARTMENT OF MECHATRONICS ENGINEERING
Embedded System design
Lab ReportExperment No.One
Prepared by :
MOHAMMED RIYAD AL- NAJJAR
ALI HAMZA MUKAT
Presented to :
Eng. Mohammed Aqel
November 8, 2007First semester, 2007/2008
-
8/3/2019 Flashing a LED
2/5
Flashing a LED
Objectives: To Understand the Architecture of PIC16F84A
To interface and program the PIC to flash a LED
Introduction:After Studying the architecture of the mid-range microcontroller (PIC16F84A),
we must enhance this knowledge by an experiment, and this experiment is a
simple experiment.
The purpose of this experiment is to make a LED interfaced with PIC16F84A toflash on and off for 1S .
Requirements:Hardware :1) PIC16F84A
2) 4MHz Oscillator
3)2 x 30OF capacitor
4) Resistor 10K
5) Resistor 150
6) LED
Software:1)Proteus
2) PIC Basic compiler
3) MPLAB
4)IC prog
Background :The circuit contains basically the PIC16F84A which won't be run without the
resonator which provides 4MHz frequency and connected to pins OSC1 and
OSC2 with the two 33PF capacitors.
The MCLC pin will be connected to Vdd voltage(+5v) through 10k Pull-up
resistor, this will make the microcontroller to reset and execute the program from
the first instructuion.
The LED will be connected to pin 0 in the port B of the microcontroller thrugh the
150 resistor .As we know, the LED needs a current of 25mA and the PIC can be provide this
current.
All of these will be simulated in the proteus software.
-
8/3/2019 Flashing a LED
3/5
After connection of the hardware, we will make the LED to light for 1S and then
will off for the same period and so on.
The program will be written in two languages one is low-level language
(assembly) and the other is high-level language(pic basic).This program will be compiled to get the Hex file which will be loaded(burning)
to the PIC using the programmer and the IC prog software and run the circuit .
The Circuit Diagram:The circuit was simulated in proteus software .
The code of program:MPLAB code:
PROCESSOR p16F84A ;Select the processor type#INCLUDE
-
8/3/2019 Flashing a LED
4/5
__CONFIG _XT_OSC & _PWRTE_ON & _CP_OFF & _WDT_OFF; TO DETERMINE TYPES OF OSCILLATOR.AND WATCHDOG ISOFF
COUNT1 EQU 0XOC ;variablesCOUNT2 EQU 0XODCOUNT3 EQU 0XOE
RESET_VECTOR CODE 0X000GOTO START ;JUMP TO THE START LABEL
INTERRUPT_VECTOR CODE 0X004GOTO INTERRUPT
MAIN CODEINTERRUPTRETFIE
START
BSF STATUS,PR0 ;BANK1CLRF TRISB ;PORTB AS OUTPUTBCF STATUS,RP0 ;BANK0
LOOP BSF PORTB,0 ;LED ONCALL DELAY_1S ;DELAY 1sBCF PORTB,0 ;LED OFFCALL DELLAY_1S ;DELAY 1sGOTO LOOP
DELAY_1s MOVLW .4MOVWF COUNT3 ;MOVE CONSTANT 4 TO
COUNT1
NEXT3 CALL DELAY_250ms ;CALL SUBROYTINEDECFSZ COUNT3,F ;DECREMENT COUNT 3 BY 1
AND JUMP IF ZEROGOTO NEXT3RETURN
DELAY_250ms
MOVLW .250MOVWF COUNT2
NEXT2 CALL DELAY_1ms ;CALL SUBROYTINE
-
8/3/2019 Flashing a LED
5/5
DECFSZ COUNT2,F ;DECREMENT COUNT 2 BY 1AND JUMP IF ZERO
GOTO NEXT2RETURN
DELAY_1msMOVLW .250MOVWF COUNT1 ;MOVE CONSTANT 250 TO COUNT1
NEXT1NOP ;no operationDECFSZ COUNT1,F ;DECREMENT COUNT1 BY 1
AND
JUMP IF ZEROGOTO NEXT1RETURN
END
PBPro code :Symbol LED = PORTB.0 'Rename pin 0 of port B to LED
TRISB = %11111110 'Setup RB0 as output
main:
High LED 'Set pin 0 of port B high(5 volts) which turns the LED onPause 1000 'Pause 1000 milliseconds with LED on
LOW LED 'Set pin 0 of port B low(0 volts) which turns the LED offPause 1000 'Pause 1000 milliseconds with LED off
GOTO main 'Jump to the main label and do it again
Comments :1)we can make flashing faster or slower simply by changing the pause
or delay.2)The difference is clear between high and low-level language