Sie sind auf Seite 1von 5

Lab Notes 1

PIC16F877: PORTS

L1. PIC16F877: PORTS


Objectives 1. Learn ICSP 2. Learn how to use bootloader program 3. Be able to set ports as input and output PART LIST NO 1 2 3 4 5 6 7 8 9 10 11 12 13 14 4. PART NAME PIC16F877 / PIC16F877A Push Button 10K Resistor 330 Resistor LED MAX232 1-micro Farad Polarized Capacitor RS-232 Connector RS-232 Cable 20 MHz Crystal 22-picoFarad Capacitor Copper Wire USB PIC Programmer [Hardware] PIC Downloader Program [Bootloader; Software] QUANTITY 1 1 1 1 1 1 5 1 1 1 2 2 meter 1 1

L1.1 EXPERIMENT I: ICSP How to Construct the ICSP In this experiment you will first construct the ICSP (In Circuit Serial Programming) circuit. In order to construct this circuit you need the circuit elements: 1. 2. 3. 4. MAX232 Polarized 1-microFarad Capacitors RS-232 Connector RS-232 Cable

L1-1

Lab Notes 1
PIC16F877: PORTS

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 the capacitors 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 RS232 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 : PIC16F877 b. Clock Frequency : 20 MHz c. Baudrate : 9600 d. Bootloader program is PIC16F877_9600_20Mhz 3. Upload the bootloader program onto the PIC memory Now you can use the ICSP circuit to program PIC microcontroller. Uploading First Program onto PIC Microcontroller 1. Generate the .hex file of your source code 2. Start PIC Downloader program on the desktop 3. Select the .hex file that you want to upload onto PIC

L1-2

Lab Notes 1
PIC16F877: PORTS

a. Select the right baudrate [Note that this baudrate must be compatible with 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 wiring 6. Click on Write button 7. You will see a message [Searching for bootloader] 8. Press push button that will reset PIC microcontroller 9. Then .hex code will be uploaded onto PIC microcontroller automatically 10. Your code is ready to be used

Figure 1.1. MAX 232 pin diagram and typical operating circuit

L1-3

Lab Notes 1
PIC16F877: PORTS

Figure 1.2. PIC LED circuit and bootloader

L1-4

Lab Notes 1
PIC16F877: PORTS

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 PORTB0 a. PORTB.F0=0 TURN OFF LED b. PORTB.F0=1 TURN ON LED 3. First disable the PORTB Pull-up a. Set register OPTION_REG with appropriate binary number 4. Set PORTB as output a. Set register TRISB with appropriate binary number 5. Set initial value to PORTB with appropriate binary number 6. Start a WHILE loop 7. Do not forget to use DELAY_MS() function to delay the blinking operation otherwise you cannot observe it as it would be very fast

L1-5

Das könnte Ihnen auch gefallen