Modern Microprocessor Systems

Lab Experiment # 4

PIC I/O Programming

Department of Electrical Engineering
School of Engineering
University of Management and Technology

appliances or consumer applications.com/pic-inst. a synchronous serial port that can be configured as either 3-wire Serial Peripheral Interface or the 2-wire Inter-Integrated Circuit (I²C™) bus and an Enhanced Universal Asynchronous Receiver Transmitter (EUSART). 2 Comparators. industrial. For help you can use this http://tutor.html Introduction to pic controller This powerful yet easy-to-program (only 35 single word instructions) CMOS FLASH-based 8-bit microcontroller packs Microchip's powerful PIC® architecture into a 40-pin package.al-williams. The PIC16F877A features 256 bytes of EEPROM data memory. 1 capture/compare/PWM and 1 Enhanced capture/compare/PWM functions. Create hex file after debugging and then burn this file on the microcontroller using Mikro ProgSuite for PIC. Following programs show how to move data to a port or a bit of a port. So write down the programs given below in MikroC. You will be using this microcontroller in this and up-coming lab sessions. Modern Microprocessor LAB Systems 4 I/O Programming using MikroC PIC INTRODUCTION The purpose of this lab session is to familiarize students with MP Lab IDE and PIC Flash – burner software. an ICD. The bits transferred to ports can be verified by the glow of LEDs when you insert the controller on the trainer board after burning. 14 channels of 10-bit Analog-to-Digital (A/D) converter. The students will use these tools to compile and run their codes on hardware development kit as well as in simulation. self-programming. 2 |Page . All of these features make it ideal for more advanced level A/D applications in automotive.

Modern Microprocessor LAB Systems 4 Special Function Registers The Special Function Registers are registers used by the CPU and peripheral functions for controlling the desired operation of the device. The following table shows the Special Function registers of pic16f877A. 3 |Page . These registers are static RAM.

} else{ portd=15. while(1){ if(portc. Open the proteous and then go to the components and search PIC16f877A 3. Open the proteous and then go to the components and search PIC16f877A 2. Now connect the LEDs with PIC as shown In figure below . delay_ms(500). Again search the led yellow and enter 4. } } } Simulation: 1. Example Programs Example Program1: void main() { trisc=0xff.f0==1){ portd=5. trisd=0x00.

5. delay_ms(500). Open the properties of PIC as in figure below and then adjust frequency to 8MHZ and then upload the program file (hex file) from the desired lab3 folder. NOTE: Burn the same code on Hardware and observe.f4==1){ portb=0x49. portc=0x00.C. trisc=0x00. while(1){ if(porta.D when PIN 4 of PORTA is 1. portd=0x00. portc=0x49. trisb=0x00. . } else{ portb=0x00. Example Program2: Display Digit 3 on PortB. portd=0x7f. trisd=0x00. Code: void main() { trisa=0xff.

If second switch is on output should be 2 (In Binary). Verify your result on the trainer. If second switch is on RB0 and RB1 should glow. If third switch is on then output should be 3 that is (11) in binary. Task5: Display last three digits of your ID when PIN 4 of PORTA is 1. . When reaching at the mid only two LEDs should glow for some time and the process repeats. Task2: Place 8 switches on PORTD and show the output as if first switch is one the output at PORTB should be 1. If third switch is on then three LSB pins of PORTB should glow. } }} Lab Tasks Note: First verify your result on proteus ad then on trainer board Task 1: Write a program in which LEDs start to glow from LSB port bit and MSB port bit both. Task 4: When pin4 of PORTA is 1 then all LEDs of PORTB ON after small delay PORTC ON without turn off PORTB and at the end PORTD turn on along with previous ports. Task3: Place 8 switches on PORTD and show the output as if first switch is one then RB0 should glow. after that all leds off and then check the status of button.

Observation and Calculations .