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

An embedded system is used to control the access to a room. People need to swap

ID: 2081238 • Letter: A

Question

An embedded system is used to control the access to a room. People need to swap their ID cards in order to unlock the door. The Id number is read through PORTD of the PIC18F452 chip. The magnetic system that is used to lock or unlock the door is connected to pin 0 of PORTC through a relay. If the voltage of this pin is 5V (high) then the door opens. We assume only five people are allowed to access the room. Write a C program to read the ID number, and to unlock the door for 20sec if the ld is valid.

Explanation / Answer

Code:

/*
* File: main.c
* Author: Chegg Expert
*
* Created on 3/26/2017
*/

#define XTAL_FREQ 10000000 // 10 Mhz Osc Frequency Asumed

#include <xc.h>

#define ID_CARD LATD

#define DOOR PORTC

#define Max_Allowed_Persons 5

const unsigned char allowed_person_ids [Max_Allowed_Persons] = {0x11,0x12,0x13,0x14,0x15};

void main(void)
{
int i;
  
DOOR = 0;
  
TRISC = TRISC & 0xFE; // Make Door control realy pin as output
  
TRISD = TRISD | 0xFF; // Make ID read POrt as Input   
  
while(1)
{
for(i = 0; i < Max_Allowed_Persons; i++)
{
if(ID_CARD == allowed_person_ids[i])
           {
               DOOR = 1;
               __delay_ms(20*1000); // 20 second delay
               DOOR = 0;              
           }
           else
           {
               DOOR = 0;
           }
}
}
return;
}

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