ec501lab3

Embed Size (px)

Citation preview

  • 8/11/2019 ec501lab3

    1/4

    Lab Work 3 : Simulating Output Port

    At the end of this lab session, students will:1. Configure I/O ports according to the circuit diagram.2. Use subroutine in writing program.3. Write and simulate the program according to the problem given.

    4. Download and test the program on the Proteus

    Equipment l ist:1. Personal computer (PC)2. MPLAB software3. Proteus software

    TheoryOne of the most important feature of the microcontroller is a number of input/output pins usedfor connection with peripherals. In this case, there are in total of thirty-five general purpose I/Opins available, which is quite enough for the most applications.In order pins operation can match internal 8-bit organization, all of them are, similar to registers,

    grouped into five so called ports denoted by A, B, C, D and E. They all have several features incommon:For practical reasons, many I/O pins have two or three functions. If a pin is used as any otherfunction, it may not be used as a general purpose input/output pin; andEvery port has its satellite, i.e. the corresponding TRIS register: TRISA, TRISB, TRISC etc.which determines performance, but not the contents of the port bits.By clearing some bit of the TRIS register (bit=0), the corresponding port pin is configured asoutput. Similarly, by setting some bit of the TRIS register (bit=1), the corresponding port pin isconfigured as input. This rule is easy to remember 0 = Output, 1 = Input

  • 8/11/2019 ec501lab3

    2/4

    Precedure:

    1. Create a New Project File with following setting:Device: PIC18F4550

    Active Toolsuite: Microchip MPASM ToolsuiteProject Name Lab3

    Project Directory

    2. Open a new file by clicking File> New, and key in the program below. After a few linessave as this program as Lab3.asm

    #include

    D1 EQU 0x20D2 EQU 0x21D3 EQU 0x22

    ORG 00H

    MOVLW 00HMOVWF TRISD

    LOOP:MOVLW B'00000001'MOVWF PORTDCALL DELAYMOVLW B'00000000'MOVWF PORTDCALL DELAYGOTO LOOP

    DELAY:MOVLW D'3'MOVWF D3MOVLW D'2'MOVWF D2MOVLW D'1'MOVWF D1DECFSZ D1GOTO $-1DECFSZ D2GOTO $-5

    DECFSZ D3GOTO $-9RETURN

    END

  • 8/11/2019 ec501lab3

    3/4

    3. Continue entering the code. When complete, go to the Project menu again, click AddFiles to Project... and select the one you have just saved.

    4. Assembler the program by pressing Project>Build All.(If the error occurs, fix it and repeat step 4 again.)

    Simulating the program using Proteus

    1. Simulate your program with Proteus

    2. GoStart Proteus 7 Professional click ISIS 7

    Profesional.

  • 8/11/2019 ec501lab3

    4/4

    3. Simulate your program to the schematic shown below

    Activi ty 1

    Write and assemble a program to toggle all the bits of PORTD continuously by sending55H and AAH to these ports. Put a time delay between the "on" and "off" states.

    Discussion 1Write the code for activity 1

    Activi ty 2Write and assemble a program to make LEDs work as a running light.Question and Discussion

    2. Discussion3. Conclusion

    RA0/AN02

    RA1/AN13

    RA2/AN2/VREF-/CVREF4

    RA3/AN3/VREF+5

    RA4/T0CKI/C1OUT/RCV6

    RA5/AN4/SS/LVDIN/C2OUT7

    RA6/OSC2/CLKO14

    OSC1/CLKI13

    RB0/AN12/INT0/FLT0/SDI/SDA33

    RB1/AN10/INT1/SCK/SCL

    34

    RB2/AN8/INT2/VMO35

    RB3/AN9/CCP2/VPO36

    RB4/AN11/KBI0/CSSPP37

    RB5/KBI1/PGM38

    RB6/KBI2/PGC39

    RB7/KBI3/PGD40

    RC0/T1OSO/T1CKI15

    RC1/T1OSI/CCP2/UOE16

    RC2/CCP1/P1A17

    VUSB18

    RC4/D-/VM23

    RC5/D+/VP24

    RC6/TX/CK25

    RC7/RX/DT/SDO 26

    RD0/SPP019

    RD1/SPP120

    RD2/SPP221

    RD3/SPP3 22

    RD4/SPP427

    RD5/SPP5/P1B28

    RD6/SPP6/P1C29

    RD7/SPP7/P1D30

    RE0/AN5/CK1SPP8

    RE1/AN6/CK2SPP9

    RE2/AN7/OESPP10

    RE3/MCLR/VPP1

    U1

    PIC18F4550R110k

    R2220

    D1LED

    R3220

    D2LED

    R4220

    D3LED

    R5220

    D4LED

    R6220

    D5LED

    R7220

    D6LED

    R8220

    D7LED

    R9220

    D8LED