lab 1 port led

Upload: amitsaini2k9

Post on 06-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Lab 1 Port Led

    1/5

    Lab Notes 1PIC16F877: PORTS

    L1-1

    L1. PIC16F877: PORTS

    Objectives

    1. Learn ICSP2. Learn how to use bootloader program3. Be able to set ports as input and output

    PART LIST

    NO PART NAME QUANTITY

    1 PIC16F877 / PIC16F877A 1

    2 Push Button 1

    3 10K Resistor 1

    4 330 Resistor 1

    5 LED 1

    6 MAX232 1

    7 1-micro Farad Polarized Capacitor 5

    8 RS-232 Connector 1

    9 RS-232 Cable 1

    10 20 MHz Crystal 1

    11 22-picoFarad Capacitor 212 Copper Wire 2 meter

    13 USB PIC Programmer [Hardware] 1

    14 PIC Downloader Program [Bootloader; Software] 1

    4.L1.1 EXPERIMENT I: ICSP

    How to Construct the ICSP

    In this experiment you will first construct the ICSP (In Circuit SerialProgramming) circuit. In order to construct this circuit you need the circuit

    elements:

    1. MAX2322. Polarized 1-microFarad Capacitors3. RS-232 Connector4. RS-232 Cable

  • 8/3/2019 Lab 1 Port Led

    2/5

    Lab Notes 1PIC16F877: PORTS

    L1-2

    First mount the MAX232 on the breadboard. Then, using Figure 1 mount the

    polarized capacitor between the MAX232 ports. Note that the capacitors are

    polarized and they have positive and negative ports. When you connect thecapacitors to the ports of MAX232, analyze the circuit given in Figure 1 and assure

    that right pole (positive / negative) is connected accordingly.

    RS-232 connector must be prepared to interface to MAX232. For this purpose, you

    need to solder three wires to RS-232 connector. Solder three wires having different

    colors to 2, 3, 5 port of the RS-232 connector. Then connect the 5th

    port of the RS-

    232 connector to ground (0 V) and connect 2nd

    pin of RS-232 connector to port 14th

    of MAX232 (T1OUT) and connect 3rd

    pin of RS-232 connector to port 13th

    of

    MAX232 (R1IN).

    Once you construct the ICSP circuit, connect MAX232 to PIC16F877 according to

    the circuit given in Figure 2. Connect port 11th

    of MAX232 (T1IN) to port 25th

    of

    PIC16F877 (TX) and connect port 12th

    of MAX232 (R1OUT) to 26th

    port of

    PIC16F877 (RX). Now the ICSP circuit is ready to program the PIC

    microcontroller on the breadboard.

    Loading Bootloader

    1. Place the PIC16F877 microcontroller on the USB PIC programmer.2. Select the right bootloader source code. For instance

    a. Microcontroller Type : PIC16F877b. Clock Frequency : 20 MHzc. Baudrate : 9600d. Bootloader program is PIC16F877_9600_20Mhz

    3. Upload the bootloader program onto the PIC memoryNow you can use the ICSP circuit to program PIC microcontroller.

    Uploading First Program onto PIC Microcontroller

    1. Generate the .hex file of your source code2. Start PIC Downloader program on the desktop3. Select the .hex file that you want to upload onto PIC

  • 8/3/2019 Lab 1 Port Led

    3/5

    Lab Notes 1PIC16F877: PORTS

    L1-3

    a. Select the right baudrate [Note that this baudrate must be compatiblewith the bootloader program that was written on to PIC

    microcontroller which is Baudrate: 9600]4. Select the right PORT [i.e. COM1]5. Check the wiring of ICSP and PIC microcontroller wiring6. Click on Write button7. You will see a message [Searching for bootloader]8. Press push button that will reset PIC microcontroller9. Then .hex code will be uploaded onto PIC microcontroller automatically10.Your code is ready to be used

    Figure 1.1. MAX 232 pin diagram and typical operating circuit

  • 8/3/2019 Lab 1 Port Led

    4/5

    Lab Notes 1PIC16F877: PORTS

    L1-4

    Figure 1.2. PIC LED circuit and bootloader

  • 8/3/2019 Lab 1 Port Led

    5/5

    Lab Notes 1PIC16F877: PORTS

    L1-5

    1.2 EXPERIMENT II: PORTS Blinking LED

    1.

    Construct the circuit shown in Figure 2.2. Write a C code that turn on and off the LED connected to PORTB0a. PORTB.F0=0 TURN OFF LEDb. PORTB.F0=1 TURN ON LED

    3. First disable the PORTB Pull-upa. Set register OPTION_REG with appropriate binary number

    4. Set PORTB as outputa. Set register TRISB with appropriate binary number

    5. Set initial value to PORTB with appropriate binary number6. Start a WHILE loop7. Do not forget to use DELAY_MS() function to delay the blinking operation

    otherwise you cannot observe it as it would be very fast