// //////////////////////////////////////////////
// ESP (CS 33301-001)
// Project 1.1: Input - Polling --> LED ON OFF w/ SW
// Kent State University
// Dept. of Computer Science
// Jungyoon Kim, Ph.D.
// //////////////////////////////////////////////
#define BIT0_MASK 0x01 // 0000 0001 --> Pin 0
#define BIT5_MASK 0x20 // 0010 0000 --> Pin 5
#define PORTB_MASK 0x25
#define DDRB_MASK 0x24
#define PINB_MASK 0x23
unsigned char *portDDRB;
unsigned char *portPinB;
unsigned char *portB;
// 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;
*portDDRB &= ~BIT0_MASK; // Configure bit 3 as an input
*portDDRB |= BIT5_MASK; // Configure bit 5 as an output
portPinB = (unsigned char *) PINB_MASK;
portB = (unsigned char *) PORTB_MASK;
*portB &= ~BIT5_MASK;
}
// the loop function
void loop() {
// Check the Input Status:
if ((*portPinB) & BIT0_MASK == 0x01)
{
*portB |= BIT5_MASK; // LED On:
MyDelay(1000);
*portB &= ~BIT5_MASK; // LED OFF:
MyDelay(1000);
}
}
// Define MyDelay function
void MyDelay(unsigned long mSec)
{
volatile unsigned long i;
unsigned long endT = 1000 * mSec;
for (i = 0; i < endT; i++);
}