MIT-Curricular/ES/Lab/Lab8/7SegUpCounter.c

34 lines
685 B
C

#include <LPC17xx.h>
int main(){
unsigned long int i,j,n,number=0,count=0;
unsigned char seven_seg[16] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
LPC_PINCON -> PINSEL0 = 0;
LPC_GPIO0 -> FIODIR = 0xFF<<4;
LPC_PINCON -> PINSEL3 = 0;
LPC_GPIO1 -> FIODIR = 0x0F<<23;
while(1){
n = number;
for(i = 0; i < 4; i++){
LPC_GPIO1 -> FIOPIN = i << 23;
LPC_GPIO0 -> FIOPIN = seven_seg[n%10] << 4;
n = n/10;
for(j=0;j<1000;j++); // value refresh delay
LPC_GPIO0 -> FIOPIN = 0; // clears
}
count++;
if(count == 1000){ // change delay
count = 0;
number = (number+1)%10000;
}
}
}