Пример #1
0
void super_event(rcs_Event event) {
        if (event.type == EVENT_BUTTON_RELEASE) {
          pressed='N'; 
          if (inPressed=='Y') {
            inPressed='N';
            }
          }
        if (event.type == EVENT_BUTTON_PRESS && pressed=='N') {
          if (event.d1==3) printf("%d %d\n",event.d2,event.d3);
    /* power switch */
          else if (event.d2>=462 && event.d2<=482 &&
              event.d3>=44 && event.d3<=61) {
            toggleSetState(&power,(toggleGetState(&power))?0:1);
            togglePaint(&power,display,window);
            control = OFF;
            }
    /* Load Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=234 && event.d3<=259) {
            if (cpu.mode != 'L') showAddr(0); 
            lastMode2 = cpu.mode;
            cdp1802SetClear(&cpu,0);
            cdp1802SetWait(&cpu,0);
            if (lastMode2 == 'R' && cpu.mode != 'R') showClock();
            }
    /* Reset Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=265 && event.d3<=291) {
            lastMode2 = cpu.mode;
            cdp1802SetClear(&cpu,0);
            cdp1802SetWait(&cpu,1);
            if (cpu.mode == 'I') showAddr(0);
            if (lastMode2 == 'R' && cpu.mode != 'R') showClock();
            singleStep = 0;
            toggleSetState(&mp,0);
            monitor = 'N';
            state = 'F';
            vt100Reset();
            }
    /* Go Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=298 && event.d3<=324) {
            cdp1802SetClear(&cpu,1);
            cdp1802SetWait(&cpu,1);
            }
    /* Pause Button */
          else if (event.d2>=435 && event.d2<=462 &&
              event.d3>=329 && event.d3<=355) {
            cdp1802SetClear(&cpu,1);
            cdp1802SetWait(&cpu,0);
            toggleSetState(&mp,0);
            singleStep = 0;
            }
    /* Single Step Button */
          else if (event.d2>=467 && event.d2<=492 &&
              event.d3>=267 && event.d3<=290) {
/*
            cdp1802SetClear(&cpu,1);
            cdp1802SetWait(&cpu,1);
*/
            singleStep = 1;
            }
    /* Monitor Button */
          else if (event.d2>=467 && event.d2<=492 &&
              event.d3>=234 && event.d3<=259) {
            if (superBoard == 'Y') {
              cdp1802SetClear(&cpu,1);
              cdp1802SetWait(&cpu,1);
              cpu.r[0] = 0x8000;
              } else monitor = 'Y';
            }
    /* 0 Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 0;
            }
    /* 1 Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 1;
            }
    /* 2 Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 2;
            }
    /* 3 Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=233 && event.d3<=259) {
            switches = ((switches << 4) & 0xf0) | 3;
            }
    /* 4 Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 4;
            }
    /* 5 Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 5;
            }
    /* 6 Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 6;
            }
    /* 7 Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=265 && event.d3<=291) {
            switches = ((switches << 4) & 0xf0) | 7;
            }
    /* 8 Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 8;
            }
    /* 9 Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 9;
            }
    /* A Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 10;
            }
    /* B Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=297 && event.d3<=324) {
            switches = ((switches << 4) & 0xf0) | 11;
            }
    /* C Button */
          else if (event.d2>=306 && event.d2<=333 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 12;
            }
    /* D Button */
          else if (event.d2>=338 && event.d2<=363 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 13;
            }
    /* E Button */
          else if (event.d2>=370 && event.d2<=396 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 14;
            }
    /* F Button */
          else if (event.d2>=402 && event.d2<=428 &&
              event.d3>=329 && event.d3<=355) {
            switches = ((switches << 4) & 0xf0) | 15;
            }
    /* P Button */
          else if (event.d2>=467 && event.d2<=493 &&
              event.d3>=297 && event.d3<=323) {
            toggleSetState(&mp,1);
            }
    /* in button */
          else if (event.d2>=467 && event.d2<=492 &&
              event.d3>=329 && event.d3<=355) {
            inPressed='Y';
            if (cpu.mode == 'L') {
              cdp1802DmaIn(&cpu,getData());
              showData(getData());
              } else {
              toggleSetState(&ef[3],0);
              }
            }
          }
  }
Пример #2
0
void main(void) 
{
    // initialise the RTC communication line
    I2C_Init() ;
    // initialise the LCD display
    LCDInit(LS_NONE);
    // initialise the actual RTC
    DS1307_Init() ;

    //clear the display
    LCDClear();
    
    // read back our running time
    DS1307_readRam(&runningMinutes,0,2) ;
    DS1307_readRam(&runningHours,2,2) ;
    
    LCDWriteString("Starting counter");
    LCDGotoXY(0,1) ;
    LCDWriteString("at ");
    LCDWriteInt(runningHours,1);
    LCDWriteString(":");
    LCDWriteInt(runningMinutes,1);
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;

    // compensate for our handling on the first run of the readClock routine
    runningMinutes-- ;

    LCDClear();
    // infinite loop, read the clock, display on the LCD, check for the button, and if needed, process the menus
   while(1)
  {       
      readClock();
      
      showClock() ;           
      
      readInputs() ;
      
      if (bButton)
        doMenu();
      else if (state & 0x30)
      {
          // rotate the encoder to select a menu function, well, that was the aim, but encoder reading
          // seems a tad slow or inaccurate.
          //
          // there is a timeout if the button isn't pressed after selecting the menu option
          
          if (state & DIR_CW)
          {
              menuFunction++ ;
              if (menuFunction == MENU_LAST)
                  menuFunction = MENU_NONE ;
          }
          else if (state & DIR_CCW)
          {
              menuFunction-- ;
              if (menuFunction < MENU_NONE)
                  menuFunction = MENU_LAST-1 ;
          }
          
          if (menuFunction != MENU_NONE)
          {
              next_menu_clear = minute * 60 + seconds + 20 ;
              LCDGotoXY(9,0);
              if (menuFunction == MENU_TIME)
                LCDWriteString("Time ?");
              if (menuFunction == MENU_DATE)
                LCDWriteString("Date ?");
          }
          else
              clearPrompt();
      }
      else if (next_menu_clear && ((minute * 60 + seconds) > next_menu_clear))
      {
          clearPrompt();
      }
  }
}
Пример #3
0
int main(void){
	//PORT mapping
	//On PORTD, we have the matrix the lines.
	//On PORTC, we have inputs, 2 buttons and the DCF and Time sensors
	//On PortB we have control over the shift registers and the DEBUG led!
	//		 76543210
	DDRC = 0b00000110;
	DDRD = 0b11111111;
	DDRB = 0b11111111;
	PORTC = 0b00111001;
	PORTD = 0;
	PORTB = 0;
	
	//Initialize Interrupt for timer0
	TCNT0 = 0xFC;
	TCCR0A = (1 << WGM01);
	TCCR0B = (0<<CS02)|(0<<CS01)|(1<<CS00);
	//TIMSK0 |= _BV(TOIE0);
	
	//Initialize Interrupt for timer1
	TCCR1A |= (0 << COM1A1) | (0 << COM1A0);
	TCCR1B |= (1 << WGM12) | (1 << CS11); // Set CTC and prescaler :8
	OCR1A = 0x61A7;
	TIMSK1 |= (1 << OCIE1A);
	sei();

	DEBUG_UIT();
	SPI_MasterInit();
	
	//SETFLAG(FLAG_STARTUP);
	
	uint16_t refreshCounter = 0;
	uint16_t ttCounter = 0;
	uint8_t tempCounter = 0;
	doDisplay(0);
    while(1) {
		if(CHECKFLAG(FLAG_REFRESHDISPLAY)){
			RESETFLAG(FLAG_REFRESHDISPLAY);
			refreshDisplay();
		}
		
		if(CHECKFLAG(FLAG_HANDLEBIT)){
			RESETFLAG(FLAG_HANDLEBIT);
			//DEBUG_AAN();
			//handleBit();
		}
		
		if(CHECKFLAG(FLAG_STARTUP)){
			//Do something nice..
			if(ttCounter == 4000){
				for(uint8_t display = 0;display <= MAX_DISPLAY; display++){
					for(uint8_t row = 0;row<=8;row++){
						if(display == (tempCounter / 5)){
							displays[display][row] = (3 << (tempCounter % 5));
						}else{
							displays[display][row] = 0;
						}
					}					
				}				
				tempCounter++;
				ttCounter=0;
				if(tempCounter == MAX_DISPLAY * 5){
					tempCounter=0;
				}
			}
			ttCounter++;
		}else{
		//if(secondCounter % 10 >= 8){
			/*if(CHECKFLAG(FLAG_READTEMP)){
				temperature = (uint16_t) ds1820_read();
				RESETFLAG(FLAG_READTEMP);
				//doDisplay(temperature);
			}else{*/
				showClock(12,34);
			//}			
		//}else{
			//showClock(currentTime.hours,currentTime.minutes);
		//}
		}
		
		if(refreshCounter == 20){
			SETFLAG(FLAG_REFRESHDISPLAY);
			refreshCounter = 0;
			//doDisplay(refreshCounter);
		}
		refreshCounter++;
		//doDisplay(refreshCounter);
    }
}