Uploaded by Hamza Arshad

Embedded System Design lab 1

advertisement
CEN-4120 Embedded System Design
Lab Report: 1
Department of Computer Engineering
National University of Technology Islamabad
Department
CEN
Date
Name/Registration Number
Muhammad Hamza Arshad
Instructor Name
June 17,2022
Engr. Aqib
Semester/Section
8th/CEN
Instructor Signature
Experiment # 01
INTRODUCTION TO PIC32MX370F512L Microcontroller
Objective:
1. To understand basics of PIC32MX370F512L Microcontroller
2. Implementing codes of inputs outputs and playing with leds .
Software
 MPLAB
Tasks
1.
Generate the config.h header file by configuration pins
#ifndef _CONFIDG_BITS_H /* Guard against multiple inclusion */
#define _CONFIDG_BITS_H
// PIC32MX370F512L Configuration Bit Settings
// 'C' source line config statements
// DEVCFG3
#pragma config USERID = 0xFFFF
// Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config FSRSSEL = PRIORITY_7 // Shadow Register Set Priority Select (SRS Priority 7)
#pragma config PMDL1WAY = OFF
// Peripheral Module Disable Configuration (Allow multiple
reconfigurations)
#pragma config IOL1WAY = OFF
// Peripheral Pin Select Configuration (Allow multiple
reconfigurations)
// DEVCFG2
#pragma config FPLLIDIV = DIV_2
#pragma config FPLLMUL = MUL_20
#pragma config FPLLODIV = DIV_1
// PLL Input Divider (2x Divider)
// PLL Multiplier (20x Multiplier)
// System PLL Output Clock Divider (PLL Divide by 1)
// DEVCFG1
#pragma config FNOSC = PRIPLL
// Oscillator Selection Bits (Primary Osc w/PLL
(XT+,HS+,EC+PLL))
#pragma config FSOSCEN = OFF
// Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF
// Internal/External Switch Over (Disabled)
#pragma config POSCMOD = XT
// Primary Oscillator Configuration (XT osc mode)
#pragma config OSCIOFNC = OFF
// CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8
// Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8)
#pragma config FCKSM = CSDCMD
// Clock Switching and Monitor Selection (Clock Switch
Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576
// Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF
// Watchdog Timer Window Enable (Watchdog Timer is in NonWindow Mode)
#pragma config FWDTEN = OFF
// Watchdog Timer Enable (WDT Disabled (SWDTEN Bit
Controls))
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window Size is 25%)
// DEVCFG0
#pragma config DEBUG = OFF
// Background Debugger Enable (Debugger is Disabled)
#pragma config JTAGEN = OFF
// JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx1
// ICE/ICD Comm Channel Select (Communicate on
PGEC1/PGED1)
#pragma config PWP = OFF
// Program Flash Write Protect (Disable)
#pragma config BWP = OFF
// Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF
// Code Protect (Protection Disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#endif /* _EXAMPLE_FILE_NAME_H */
/* *****************************************************************************
End of File
*/
2.
Toggle the 3 led’s with switches to port
#include "config_bits.h"
int main(void)
{
DDPCONbits.JTAGEN =0;
TRISFbits.TRISF3 = 1; // RF3 (SW0) configured as input
TRISFbits.TRISF5 = 1; // RF5 (SW1) configured as input
TRISFbits.TRISF4 = 1; // RF4 (SW2) configured as input
TRISAbits.TRISA0 = 0; // LED<0-7> configured as output
TRISAbits.TRISA1 = 0; // LED<0-7> configured as output
TRISAbits.TRISA2 = 0; // LED<0-7> configured as output
int value_0,value_1,value_2;
while(1)
{
value_0 = PORTFbits.RF3;
value_1 = PORTFbits.RF5;
value_2 = PORTFbits.RF4 ;
LATAbits.LATA0 = value_0; // turn led on
LATAbits.LATA1 = value_1; // turn led on
LATAbits.LATA2 = value_2; // turn led on
}
return(EXIT_FAILURE);
}
3.
#include "config_bits.h"
int main(void)
{
DDPCONbits.JTAGEN =0;
TRISFbits.TRISF3 = 1; // RF3 (SW0) configured as input
TRISFbits.TRISF4 = 1; // RF4 (SW2) configured as input
TRISDbits.TRISD15 = 1; // RD15 (SW3) configured as input
TRISBbits.TRISB11 = 1; // RB11 (SW5) configured as input
ANSELBbits.ANSB11 = 0; // RB11 (SW5) disabled analog
TRISBbits.TRISB9 = 1; // RB9 (SW7) configured as input
ANSELBbits.ANSB9 = 0; // RB9 (SW7) disabled analog
TRISAbits.TRISA1 = 0; // LED<0-7> configured as output
TRISAbits.TRISA2 = 0; // LED<0-7> configured as output
TRISAbits.TRISA6 = 0; // LED<0-7> configured as output
TRISAbits.TRISA4 = 0; // LED<0-7> configured as output
int value_0,value_1,value_2,value_3,value_4,L1,L2;
while(1)
{
value_0 = PORTFbits.RF3;
value_1 = PORTFbits.RF4;
value_2 = PORTDbits.RD15 ;
value_3 = PORTBbits.RB11;
value_4 = PORTBbits.RB9 ;
L1= value_0 && value_1;
L2= value_1 || value_2;
LATAbits.LATA1 = L1; // turn led on
LATAbits.LATA2 = L2; // turn led on
LATAbits.LATA6 = value_3; // turn led on
LATAbits.LATA4 = value_4; // turn led on
}
return(EXIT_FAILURE);
}
By switch 7, LD4 turns on
By switch 5, LD6 turns on
By switch 2,3 OR GATE LD2
By switch 0,2 AND GATE LD1
Overall output :
Conclusion:
Done all task in the with the help of manuals pins assignment on PIC32MX370F512L
Microcontroller and experimented tasks like generating header file and running with switching buttons
and implementing OR and AND gate on PIC32MX370F512L.
Download