Simulation Set 2
Simulation Set 2
Experiment No:- 02
Input Output Programming in C (continued)
Requirements:-
MPLAB and Proteus software
SIMULATION SET- 2
INPUT/OUTPUT PROGRAMMING IN C
1) Write a C18 program to toggle bit RB4 continuously without disturbing the rest of the
bits of port B.
2) Write a C18 program to read the status of switch attached to pin RB4 on port B and
thereby turn on/off the LED on pin RC4. Pull-up resistor configuration has been used for
connecting the switch to pin RB4 of port B. LED on pin RC4 must glow without disturbing
3) Write a C18 program to get the status of bit RB0 and send it to RC7 continuously.
4) Rewrite the above C18 program to get the bit RB0 and send it to RC7 after inverting it.
5) Write a C18 program to toggle all the bits of port B and port C continuously using the
inverting operator. Introduce time delay in between each state for better visibility.
6) Introduce a switch with a pull up resistor configuration to the PIC18 on pin RB0 of port
B. After five operations of the switch, the LED connected to pin RB7 must glow for a
certain time period and then should turn off. Write a C18 program for the same and
Reference:
Question 1.
#include <xc.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "probe1.h"
void time_delay(void);
void main(void)
TRISBbits.RB4 =0;
while(1)
LATBbits.LATB4=0;
time_delay();
LATBbits.LATB4=1;
time_delay();
void time_delay(void)
unsigned int i;
unsigned int j;
for(i=0;i<20;i++)
for(j=0;j<20;j++);
Question 2.