Arizona Picdem 17 User Manual

Page of 92
 2001 Microchip Technology Inc.
DS39024B-page 67
SWITCH.C
 Description
8.6
 
SWITCH.C
 Source Code Listing
//****************************************************
//*   SWITCH.C
//****************************************************
//*   Rodger Richey
//*   Principal Applications Engineer
//*   Microchip Technology Incorporated
//****************************************************
//*   2 December 1998
//*   Compiled using MPLAB C17 C Compiler V2.20
//****************************************************
//*   This program toggles the state of the memory
//*   mapped LEDs when the corresponding memory mapped
//*   switch is pressed.
//****************************************************
//*   Uses an oscillator of 16MHz
//****************************************************
#include <p17c756.h>
#include <delays.h>
void main(void)
{
unsigned int LEDbuf;
unsigned int SWTbuf;
unsigned int TEMPbuf;
unsigned int Temp;
rom int *LEDptr;
rom int *SWTptr;
// Initialize pointers to the memory mapped device
LEDptr = (rom int *)0xfffd;
SWTptr = (rom int *)0xfffc;
// Initialize the LEDs and other variables
*LEDptr = 0x00ff;
LEDbuf = 0x00ff;
SWTbuf = 0x00ff;
while(1)
{
// Read the state of the switches
TEMPbuf = *SWTptr & 0x00ff;
// Determine what switch states have changed
Temp = TEMPbuf ^ SWTbuf;
// If a switch state has changed and the change
// was a switch press
if(Temp && TEMPbuf != 0x00ff)
{
// If need to toggle LED low
if(Temp&LEDbuf)
// Mask off desired 
LED
LEDbuf &= ~Temp;
// Else need to toggle LED high