You are on page 1of 5

Experiment No.

12

Aim: Toggle bits of PORTB

 Program Statement:
1. Write a C18 program to toggle all the bits of PORTB continuously with a delay of 250ms
.Assume that the system PIC18f458 with XTAL = 10MHz

 Software :
MPLAB IDEv8.89 and MPLABC18v3.48

 Procedure:
2. Choose Configure>select Device. In the device dialog ,select PIC18F8720 from the list.
3. Choose Project>Project Wizard.
From the Welcome dialog, click on Next>to advance.
4. Step 2 of the Project Wizard sets up the language tools that are used with this project.
Select “Microchip C18 Tool suite” in the Active Tool suite list box.
5. Step Three of the wizard allows you to name new project and put it into a folder.
6. Select the template file and add it to project
C:\Progarm Files\Microchip\Mplab18\v3.46\Template\Object\18F8720TMPO.c. Press
Add>to move the file name to the right panel. Click on the “A” at the start of the line
with the file name three times until a “C” appears . this will enable this file to be copied
to our project directory.
7. Open the template file in the project by double clicking on its name in the Project
window.
8. Type the program and variables need to be defined is added in the UDATA_ACS section
for uninitialized data using Access RAM
9. Select Project>Build All to assemble and link the code.
10. Select MPLAB SIM simulator as the debug execution tool. This is done from the
Debugger>Select Tool pull down menu.
11. Select File>Save Workspace to save the Project.
12. Select Debugger>Reset>Processor Reset and a green arrow shows where the program
will begin. This was part of the template file. The first instruction in memory jumps to the
label called Main, where your code was inserted.
13. Press the Step into icon or select Debugger>step Into to single step to the code at Main
or Start.
14. Select View>Watch and add SFRs and SYMBOLs to be watched.
15. Select View> File Registers to watch the locations in the data file.

 Conclusion:

Department of Electrical Engineering, Viva techProf. Ashwini Haryan


Experiment No.12

 Program:

;Program to PORTB continuously after 250ms//


#include <P18F458.h>
void MSDelay(unsigned int);
void main(void)
{
TRISC = 0;
TRISD = 0;
while(1)
{
PORTC = 0x55;
PORTD = 0x55;
MSDelay(250);
PORTC = 0xAA;
PORTD = 0xAA;
MSDelay(250);
}
}
void MSDelay(unsigned int itime)
{
unsigned int i; unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++);
}

 Result:

Department of Electrical Engineering, Viva techProf. Ashwini Haryan


Experiment No.12

Aim: Display Count friom 00H to FFH

 Program Statement:
LEDs are connected to bits in portB and Port C. write program that shows the count from
00H to FFH( 0000 0000 to 1111 1111) in binary on LEDs.

 Software :
MPLAB IDEv8.89 and MPLABC18v3.48

 Procedure:
1. Choose Configure>select Device. In the device dialog ,select PIC18F8720 from the list.
2. Choose Project>Project Wizard.
From the Welcome dialog, click on Next>to advance.
3. Step 2 of the Project Wizard sets up the language tools that are used with this project.
Select “Microchip C18 Tool suite” in the Active Tool suite list box.
4. Step Three of the wizard allows you to name new project and put it into a folder.
5. Select the template file and add it to project
C:\Progarm Files\Microchip\Mplab18\v3.46\Template\Object\18F8720TMPO.c. Press
Add>to move the file name to the right panel. Click on the “A” at the start of the line
with the file name three times until a “C” appears . this will enable this file to be copied
to our project directory.
6. Open the template file in the project by double clicking on its name in the Project
window.
7. Type the program and variables need to be defined is added in the UDATA_ACS section
for uninitialized data using Access RAM
8. Select Project>Build All to assemble and link the code.
9. Select MPLAB SIM simulator as the debug execution tool. This is done from the
Debugger>Select Tool pull down menu.
10. Select File>Save Workspace to save the Project.
11. Select Debugger>Reset>Processor Reset and a green arrow shows where the program
will begin. This was part of the template file. The first instruction in memory jumps to the
label called Main, where your code was inserted.
12. Press the Step into icon or select Debugger>step Into to single step to the code at Main
or Start.
13. Select View>Watch and add SFRs and SYMBOLs to be watched.
14. Select View> File Registers to watch the locations in the data file.

 Conclusion:

Department of Electrical Engineering, Viva techProf. Ashwini Haryan


Experiment No.12

 Program:

;Program to show count from 00H to FFh on LEDs


#include <P18F458.h>
#define LED PORTC
void main(void)
{
TRISB = 0;
TRISC = 0;
PORTB = 00;
LED = 0;
for(;;)
{
PORTB++;
LED++;
}
}

 Result:

Department of Electrical Engineering, Viva techProf. Ashwini Haryan


Experiment No.12

Department of Electrical Engineering, Viva techProf. Ashwini Haryan

You might also like