// //////////////////////////////////////////////
// ESP (CS 33301-001)
// Project 1.1: Input - Polling --> LED ON OFF w/ SW
// Kent State University
// Dept. of Computer Science
// Ean Dodge
// //////////////////////////////////////////////
#define BIT3_MASK 0x08 // 0000 1000 --> Pin 3
#define BIT5_MASK 0x20 // 0010 0000 --> Pin 5
#define PORTB_MASK 0x25 //for input port
#define PORTD_MASK 0x2B //for output port
#define DDRB_MASK 0x24// for the DDRB
#define DDRD_MASK 0x2A //for the DDRD
#define PINB_MASK 0x23 //for input device
unsigned char *portDDRB; //declaring DDRB
unsigned char *portDDRD; //declaring DDRD
unsigned char *portPinB; //decalaaring Pin B to use as input B
unsigned char *portB; //declaring port B to use as output D
unsigned char *portD; //declaing port D to use as output D
// Determine MyDelay function
void MyDelay(unsigned long mSec);
// The setup function runs once when you press reset or power the
//board
void setup() {
// Port B
portDDRB = (unsigned char *) DDRB_MASK; //pointing DDRB to a hardcoded value of 0x24
*portDDRB &= ~(BIT3_MASK); // Configure bit 3 of DDRB as 0, or an input
*portDDRB |= BIT5_MASK; //Configure bit 5 of DDRB as 1, or an output
portPinB = (unsigned char *) PINB_MASK; //pointing PinB to a hardcoded value of 0x23
portB = (unsigned char *) PORTB_MASK; //pointing PortB to a hardcoded value of 0x25
*portB |= BIT5_MASK; //turns on internal LED to initialize it as on
}
// the loop function
void loop() {
// Check the Input Status:
if ((*portPinB & BIT3_MASK) == 0x08) //checking to see if both the input value is 1(00001000)
{ //We are looking at only bit3 here
*portB &= ~(BIT5_MASK); //internal LED Off:
MyDelay(2000); //delay 2 seconds
*portB |= (BIT5_MASK);//internal LED Off
MyDelay(2000); //delay 2 seconds
}
}
// Define MyDelay function
void MyDelay(unsigned long mSec)
{
volatile unsigned long i;
unsigned long endT = 1000 * mSec;
for (i = 0; i < endT; i++); //loop for n seconds
}