Вы находитесь на странице: 1из 5

- AL Azhar University-Gaza FACULTY OF ENGINEERING AND INFORMATION TECHNOLOGY

DEPARTMENT OF MECHATRONICS ENGINEERING

Embedded System design


Lab Report Experment No.One Prepared by : MOHAMMED RIYAD AL- NAJJAR ALI HAMZA MUKAT
Presented to :

Eng. Mohammed Aqel

November 8, 2007
First semester, 2007/2008

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

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

__CONFIG _XT_OSC & _PWRTE_ON & _CP_OFF & _WDT_OFF ; TO DETERMINE TYPES OF OSCILLATOR.AND WATCHDOG IS OFF COUNT1 COUNT2 COUNT3 RESET_VECTOR EQU 0XOC EQU 0XOD EQU 0XOE ;variables

CODE 0X000 GOTO START ;JUMP TO THE START LABEL

INTERRUPT_VECTOR CODE 0X004 GOTO INTERRUPT MAIN CODE INTERRUPT RETFIE START BSF STATUS,PR0 CLRF TRISB BCF STATUS,RP0 LOOP BSF PORTB,0 CALL DELAY_1S BCF PORTB,0 CALL DELLAY_1S GOTO LOOP MOVLW .4 MOVWF COUNT3 CALL DELAY_250ms DECFSZ COUNT3,F GOTO NEXT3 RETURN DELAY_250ms MOVLW .250 MOVWF COUNT2 NEXT2 CALL DELAY_1ms ;CALL SUBROYTINE ;BANK1 ;PORTB AS OUTPUT ;BANK0 ;LED ON ;DELAY 1s ;LED OFF ;DELAY 1s

DELAY_1s COUNT1 NEXT3

;MOVE CONSTANT 4 TO ;CALL SUBROYTINE ;DECREMENT COUNT 3 BY 1 AND JUMP IF ZERO

DECFSZ COUNT2,F GOTO NEXT2 RETURN DELAY_1ms

;DECREMENT COUNT 2 BY 1 AND JUMP IF ZERO

MOVLW .250 MOVWF COUNT1 ;MOVE CONSTANT 250 TO COUNT1 NEXT1 NOP DECFSZ COUNT1,F AND JUMP IF ZERO GOTO NEXT1 RETURN END ;no operation ;DECREMENT COUNT1 BY 1

PBPro code : Symbol LED = PORTB.0 'Rename pin 0 of port B to LED TRISB = %11111110 main: High LED Pause 1000 LOW LED Pause 1000 GOTO main 'Set pin 0 of port B high(5 volts) which turns the LED on 'Pause 1000 milliseconds with LED on 'Set pin 0 of port B low(0 volts) which turns the LED off 'Pause 1000 milliseconds with LED off 'Jump to the main label and do it again 'Setup RB0 as output

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

Вам также может понравиться