Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have project in microprocessor class that I need to turn on and turn off led o

ID: 1300252 • Letter: I

Question

I have project in microprocessor class that I need to turn on and turn off led of tap light by the button I need an explanation of that please How to do it please and I need the code for that .
I will use MBLAB X program to do that project
Thank you I have project in microprocessor class that I need to turn on and turn off led of tap light by the button I need an explanation of that please How to do it please and I need the code for that .
I will use MBLAB X program to do that project
Thank you How to do it please and I need the code for that .
I will use MBLAB X program to do that project
Thank you

Explanation / Answer


#define _XTAL_FREQ 8000000

#include <xc.h>

// BEGIN CONFIG

#pragma config FOSC = HS// Oscillator Selection bits (HS oscillator) #pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)

#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)

#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)

#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)

#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)

#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)

#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)

//END CONFIG

int main()

{

TRISB0 = 0; //RB0 as Output PIN

while(1) {

RB0 = 1; // LED ON

__delay_ms(1000); // 1 Second Delay

RB0 = 0; // LED OFF

__delay_ms(1000); // 1 Second Delay

}

return 0;

}

First statement #define _XTAL_FREQ 8000000defines the clock frequency of the microcontroller which is used to calculate delays in __delay_ms()function. Second statement #include <xc.h>includes the header file xc.h which contains the definition of __delay_ms() function and TRIS, PORT registers.
Next is #pragma config directives, which is used to tell the compiler to set Configuration Bits of PIC Microcontroller. You can generate it using the MPLAB IDE.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote