//**********************************************************************
//ECE331 Lab 2 Flashlight.c demo program
///C-language implementation of flashlight program (KEH, August 2009)
//Hardware interface: SW on input pin PAD6 (HIGH level when not pressed)
//                    LED on output pin PT1 (Turn on with HIGH level)
//**********************************************************************
#define PTAD  (*(unsigned char *) 0x270)  /* Define register addresses */
#define DDRAD  (*(unsigned char *) 0x272)
#define PTT  (*(unsigned char *) 0x240)
#define DDRT  (*(unsigned char *) 0x242)
#define ATDDIEN  (*(unsigned char *) 0x8D)
#pragma LINK_INFO DERIVATIVE "mc9s12c128"		/* Tell linker to allocate the program into the 
										 	                          RAM and (Flash) ROM address spaces										 	              											                          that conform to those available on the 
											                          of the 9S12C128 microcontroller. */
void main(void) 
{ 
  DDRT =    0b00000010;   // LED on PT1 */
  ATDDIEN = 0b01000000;   // Make PAD6 a digital I/O pin
  DDRAD =   0b00000000;   // Make PAD6 an input (Switch on this pin) */
  for(;;) 
  { 
    PTT = PTT & 0b11111101;                     // Turn OFF LED
    while ((PTAD & 0b01000000) == 0b01000000);	// Hang here while SW not pressed (HIGH).
    PTT = PTT | 0b00000010;                     // Turn on LED .
    while ((PTAD & 0b01000000) == 0);           // Hang here while SW pressed (LOW)
  }
}
