Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <io.h>
- #include <stdbool.h>
- #include <system.h>
- #include "alt_types.h"
- #include <sys/alt_alarm.h>
- #define SEGA 0x00001
- #define SEGB 0x00002
- #define SEGC 0x00004
- #define SEGD 0x00008
- #define SEGE 0x00010
- #define SEGF 0x00020
- #define SEGG 0x00040
- #define ZERO SEGA | SEGB | SEGC | SEGD | SEGE | SEGF
- #define ONE SEGB | SEGC
- #define TWO SEGA | SEGB | SEGG| SEGE | SEGD
- #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
- #define FOUR SEGB | SEGC | SEGF | SEGG
- #define FIVE SEGG | SEGC | SEGA | SEGD | SEGF
- #define CHE SEGA | SEGD | SEGE | SEGF | SEGG
- #define CHR SEGE | SEGG
- void hexOff(){
- IOWR(HEX_BASE, 0, 0);
- IOWR(HEX_BASE, 1, 0);
- IOWR(HEX_BASE, 2, 0);
- IOWR(HEX_BASE, 3, 0);
- IOWR(HEX_BASE, 4, 0);
- IOWR(HEX_BASE, 5, 0);
- }
- int main()
- {
- int sw;
- int s1on, s2on, s3on, s4on, s5on, seof;
- bool io1 = false, io2 = false, io3 = false, io4 = false, io5 = false, ioe = false;
- bool swOn = false;
- int switches;
- int x = alt_ticks_per_second();
- while(1){
- //printf("t1 %d t2 %d \n", alt_nticks(), alt_ticks_per_second());
- switches = IORD(SW_SLIDERS_BASE,0) & 0b00111111;
- switch(switches) {
- case 0:
- IOWR(HEX_7_BASE, 0, ZERO);
- if(io1){
- if(alt_nticks() - s1on >= x*1){
- io1 = false;
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- else if(io2){
- if(alt_nticks() - s2on >= x*2){
- io2 = false;
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- else if(io3){
- if(alt_nticks() - s3on >= x*3){
- io3 = false;
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- else if(io4){
- if(alt_nticks() - s4on >= x*4){
- io4 = false;
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- else if(io5){
- if(alt_nticks() - s5on >= x*5){
- io5 = false;
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- break;
- case 1 :
- IOWR(HEX_7_BASE, 0, ONE);
- if (!io1){
- s1on=alt_nticks();
- io1=true;
- }
- if(alt_nticks()-s1on >= x*1){
- IOWR(LEDS_RED_BASE, 0, 4);
- IOWR(LEDS_RED_BASE, 0, 8);
- IOWR(LEDS_RED_BASE, 0, 64);
- IOWR(LEDS_RED_BASE, 0, 2048);
- }
- }
- break;
- case 2 :
- IOWR(HEX_7_BASE, 0, TWO);
- if (!io2){
- s2on=alt_nticks();
- io2=true;
- }
- if (alt_nticks()- s2on >= x*2){
- IOWR(LEDS_RED_BASE, 0, 2);
- IOWR(LEDS_RED_BASE, 0, 8);
- IOWR(LEDS_RED_BASE, 0, 16);
- IOWR(LEDS_RED_BASE, 0, 64);
- IOWR(LEDS_RED_BASE, 0, 128);
- IOWR(LEDS_RED_BASE, 0, 1024);
- }
- }
- break;
- case 4 :
- IOWR(HEX_7_BASE, 0, THREE);
- if (!io3){
- s3on=alt_nticks();
- io3=true;
- }
- if(alt_nticks()-s3on >= x*3){
- IOWR(LEDS_RED_BASE, 0, 1);
- IOWR(LEDS_RED_BASE, 0, 32);
- IOWR(LEDS_RED_BASE, 0, 256);
- IOWR(LEDS_RED_BASE, 0, 512);
- }
- }
- break;
- case 8 :
- IOWR(HEX_7_BASE,0 ,FOUR);
- if (!io4){
- s4on=alt_nticks();
- io4=true;
- }
- if(alt_nticks()-s4on >= x*4){
- IOWR(LEDS_RED_BASE, 0, 1);
- IOWR(LEDS_RED_BASE, 0, 2);
- IOWR(LEDS_RED_BASE, 0, 16);
- IOWR(LEDS_RED_BASE, 0, 128);
- IOWR(LEDS_RED_BASE, 0, 512);
- IOWR(LEDS_RED_BASE, 0, 1024);
- }
- }
- break;
- case 16 :
- IOWR(HEX_7_BASE,0 ,FIVE);
- if (!io5){
- s5on=alt_nticks();
- io5=true;
- }
- if(alt_nticks()-s4on >= x*5){
- IOWR(LEDS_RED_BASE, 0, 2);
- IOWR(LEDS_RED_BASE, 0, 16);
- IOWR(LEDS_RED_BASE, 0, 128);
- IOWR(LEDS_RED_BASE, 0, 1024);
- }
- }
- break;
- default:
- IOWR(HEX_7_BASE,2, CHE);
- IOWR(HEX_7_BASE,1, CHR);
- IOWR(HEX_7_BASE,0, CHR);
- /*
- if(ssw==2){
- printf("%d", (alt_nticks()-sw1));
- if(alt_nticks()-sw1 >= x*2){
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- if(ssw==3){
- if(alt_nticks()-sw1 >= x*3){
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- if(ssw==4){
- if(alt_nticks()-sw1 >= x*4){
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- if(ssw==5){
- if(alt_nticks()-sw1 >= x*5){
- IOWR(LEDS_RED_BASE, 0, 0);
- }
- }
- */
- sw1=0;
- ssw=0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement