// //////////////////////////////////////////////////
// ESP (CS 33301-001)
// Code 1.1: Input - Polling --> Built-in LED ON OFF
// Kent State University
// Dept. of Computer Science
// Jungyoon Kim, Ph.D.
// //////////////////////////////////////////////////
#define BIT5_MASK 0x20 // Bit map - 0010 0000 --> Pin 5
#define PORTB_MASK 0x25 // Address of Portb
#define DDRB_MASK 0x24 // Address of DDRB
unsigned char *portDDRB; // Pointer for DDRB
unsigned char *portB; // Pointer for 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 |= BIT5_MASK; // Configure bit 5 as an output
portB = (unsigned char *) PORTB_MASK;
*portB &= ~BIT5_MASK;
}
// the loop function
void loop() {
*portB |= BIT5_MASK; // LED On: xx1x xxxx
MyDelay(1000); // about 1 second
*portB &= ~BIT5_MASK; // LED OFF: xx0x xxxx
MyDelay(1000); // about 1 second
}
// Define MyDelay function
void MyDelay(unsigned long mSec)
{
volatile unsigned long i;
unsigned long endT = 500 * mSec;
for (i = 0; i < endT; i++);
}