Created
February 24, 2012 16:49
-
-
Save eggie5/1901973 to your computer and use it in GitHub Desktop.
lab5p2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <hidef.h> /* common defines and macros */ | |
#include <MC9S12C128.h> /* derivative information */ | |
#include <time.h> | |
#include <stdio.h> | |
void delay(int d); | |
int update_delay_time(int last_delay_time); | |
int delay_time=9400; | |
int set_delay= 500; | |
void delay(int d) | |
{ | |
while( d > 0 ) | |
{ | |
d--; | |
} | |
} | |
int update_delay_time(int last_delay_time) | |
{ | |
//read from button | |
if (PTM_PTM4 == 0) { | |
delay(set_delay); | |
//increment delay time | |
last_delay_time = last_delay_time +3000; | |
while(PTM_PTM4==0) { | |
delay(set_delay); | |
} | |
delay(set_delay); | |
} | |
else if (PTM_PTM5 == 0 && last_delay_time >= 0) | |
{ | |
delay(set_delay); | |
last_delay_time = last_delay_time - 3000; | |
while (PTM_PTM5==0) | |
{ | |
delay(set_delay); | |
} | |
delay(set_delay); | |
} | |
return last_delay_time; | |
} | |
int a [9]={0x0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF}; | |
void main(void) | |
{ | |
int i; | |
DDRA = 0xFF; // Active port A | |
PERP = 0x01; // Attach pullups tp PTP<1:0> | |
PERM = 0x30; // PB7,PB8 pullup resistors are enabled | |
PTM = 0xFF; // Clear register initially | |
//turn LEDs off | |
PORTA=0x00; | |
while(1) { | |
for(i=0; i<8; i++) | |
{ | |
delay(delay_time); | |
PORTA=a[i]; | |
} | |
for(i=8; i>0; i--) | |
{ | |
delay(delay_time); | |
PORTA=a[i]; | |
} | |
delay_time = update_delay_time(delay_time); | |
}//end while | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment