Escolar Documentos
Profissional Documentos
Cultura Documentos
PROCEDURE:
Step 1: Create a new project. Create a folder and workspace (provided by MPLAB) in which all
files will be stored.
To create a new project, open MPLAB IDE by double clicking on its icon and follow the steps
given below:
2. Select Device. Use Pull-down menu to select PIC18F452 (or 4520) or whatever device you
are usingNext
3. Select a Language Tool suite. Use the pull-down menu to select Microchip MPASM Tool
suite for writing MASM programs. The complete path is shown at Location of Select Tool on the
screen. If it is incorrect or empty, use Browse to locate Mpasmwin.exe file Next
4. Name your Project. For Project directory, select Browse and Find Next
Step 2: Select Project Build All. If there are no errors, you will get an output message “Build
Succeeded”. If there are errors you will get an output message “Build Failed” and it will list all
the errors. Double click on one of the errors, the screen will show the Source Code with an arrow
pointing to an Error. After correcting those errors rebuild the project
Step 3. Execute the project using the MPLAB Simulator and examine the output.
2. Select Debugger Settings. Set the clock frequency of the simulator and break points if
needed. Otherwise accept the defaults. Apply OK
3. Select View Watch. The View provides menu options such as Program Memory, File
Registers, and Special Function Registers and Watch. Or type in the names if the registers in the
space provided we want to Observe. The screen shows the Address of a register selected, Symbol
Name and its Value.
AIM:
To write and execute MASM program to perform arithmetic operations using PIC18
Microcontroller
REQUIREMENT:
Step 1: Load WREG with the literal value from the file register at 0x00.
Step 2: Add the number stored at file register 0x01 with the number in the WREG register
and the sum will be stored in the WREG register.
Step 3: Move the contents of the WREG register to the file register at 0x02
ASSEMBLY CODE:
MOVLW 0X03
MOVWF REG0,0
MOVLW 0X08
MOVWF REG1,0
ADDWF REG0,0
MOVWF REG2,0
END
OUTPUT:
RESULT:
Step 1: Load WREG with the literal value from the file register at 0x00.
Step 2: Subtract the number stored at file register 0x01 with the number in the WREG
register and the answer will be stored in the WREG register.
Step 3: Move the contents of the WREG register to the file register at 0x02
ASSEMBLY CODE:
MOVLW 0X02
MOVWF REG0,0
MOVLW 0X08
MOVWF REG1,0
SUBWF REG0,0
MOVWF REG2,0
END
OUTPUT:
RESULT:
Step 1: Load WREG with the literal value from the file register at 0x00.
Step 2: Multiply the number stored at file register 0x02 with the number in the WREG register.
An unsigned multiplication is carried out between the contents of W and the 8-bit literal.
The 16-bit result is placed in PRODH: PRODL register pair.
Step 3: PRODH contains the high byte. PRODL contains the low byte. W is unchanged. None
of the status flags are affected.
ASSEMBLY CODE:
MOVLW 0X02
MULLW 0X08
MOVFF PRODH,0X01
MOVFF PRODL,0X02
END
OUTPUT:
RESULT:
AIM:
To write and execute MASM program to calculate the sum of the series using PIC18
Microcontroller
REQUIREMENT:
ALGORITHM:
Step 4: Calculate the value of sum by adding i. increment i to get the number in sequence
ASSEMBLY CODE:
N SET 0X0B
SUM SET 0X01
I SET 0X02
ORG 0X00
START CLRF SUM
CLRF I
INCF I, F
SUM_LP MOVLW N
CPFSGT I
BRA ADD_LP
BRA EXIT_SUM
ADD_LP MOVF I, W
ADDWFC SUM, F
INCF I, F
BRA SUM_LP
EXIT_SUM NOP
END
OUTPUT:
RESULT:
AIM:
To write and execute MASM program to access I/O port using PIC18 Microcontroller
REQUIREMENT:
ALGORITHM:
ASSEMBLY CODE:
R2 SET 0X20
R1 SET 0X30
PORTB SET 0X10
TRISB MOVLW 0X00
L1
MOVLW 0X55
MOVWF PORTB
MOVFF PORTB, R1
CALL DELAY
MOVLW 0XAA
MOVWF PORTB
MOVFF PORTB, R1
CALL DELAY
GOTO L1
DELAY
MOVLW 0X0A
MOVWF R2
D1
NOP
DECF R2, F
BNZ D1
RETURN
END
OUTPUT:
Flashing LED
Aim:
To execute the program to understand single bit manipulation of PORTB by flashing LED using
MPLAB IDE
Requirements:
1. MPLAB IDE 8.91
2. Hi-Tech C Compiler
3. Proteus Simulator 8
#include<htc.h>
void main ()
{
RB0=0;
TRISB=0;
while (1)
{
RB0=1;
delay_sec (1);
RB0=0;
delay_sec (1);
}
Output
Result :
Aim:
To execute the program to interface the stepper motor with PIC18F Controller using MPLAB
IDE
Requirements:
1. MPLAB IDE 8.91
2. PIC18 Simulator IDE
3. Hi-Tech C Compiler for PIC18 MCUS
Stepper Motors
Stepper motors (or, sometimes, stepping motors), are motors which can turn through
"steps"—well-defined angles—under precise electronic control.
In dual phase mode, the motor operated in both phases get energized at the same time.
This mode provides more torque and high speed performance. But this mode requires twice the
amount of power used in one step mode.
Half Step
In half step mode, the rotor moves through half the basic step angle when compared to full
step mode which results in more precise motion control and smoother motor performance.
Resolution is also increased. But in this mode, motor produces less torque compared to other
modes.
Micro step
In micro step mode, it divides the motor steps up to 256 times which improves the low
speed smoothness and low speed resonance effects. But in this mode, motor produces less torque
compared to other mode.
Applications
The stepper motors are used in applications like motion-controlled positioning system as
it is easy to produce precise position control with the help of computer controlled stepper
motors. They are widely used in biomedical equipment where precise and accurate position
control is needed. They are also present in disc drivers, computer printers and scanners,
intelligent lighting, camera lenses and various other common devices and equipment. Because
of their precision characteristic, stepper motors are preferred in robotics. 3D cameras, X Y
Plotters, CNC and some other camera platforms also impart stepper motors because of its high
reliability and precision.
Project Wizard
• Start MPLAB IDE.
• Click Project menu and open Project wizard. Click Next.
• Select PIC18F4520 as your Device.
• Select HI-TECH Universal Tool Suite in front of Active Tool suite. (Note: Hi-Tech
compiler must be installed in your system.)
• Give a name of project and select the location of project. Project is successfully created.
• Clicking View/ Project to view the project window.
• Add stm.c to source file.
• Build the stm.c by clicking the black square with red spot
• It will create a .HEX file and its name will be same as your project name in the same
directory where the project is saved. This hex file is to be loaded in PIC18F4520.
Simulation:
#include<p18f4520.h>
#include<delays.h>
#define DELAY 10
#define HALF_STEP // change this for the mode of excitation.
#ifdef HALF_STEP
#define SEQ 8
#endif
#ifdef HALF_STEP
unsigned char stepping_seq[8]={0b00001000, 0b00001100, 0b00000100,
0b00000110,0b00000010, 0b00000011, 0b00000001, 0b00001001};
#endif
void main ()
{
unsigned char count = 0;
TRISB = 0x00;
while (1)
{
if (count == SEQ)
count = 0;
LATB = stepping_seq[count];
Delay10KTCYx (DELAY);
count++;
}
}
Output:
Result: