Beispiel #1
0
void main(void) {
    
    //byte b;
    
    DDRS_DDRS2 = 1; DDRS_DDRS3 = 1; // Enable LEDs
    DDRJ_DDRJ6 = 0; DDRJ_DDRJ7 = 0; // Enable switches
    
    timer_init();
    CANinit(MSCAN_NODE_ID);
    
    // Clear all MSCAN receiver flags (by setting bits)
    CANRFLG = (CANRFLG_RXF_MASK | CANRFLG_OVRIF_MASK | CANRFLG_CSCIF_MASK | CANRFLG_WUPIF_MASK);
    
    sci_init();
    
#ifdef USE_LCD
    msleep(16); // wait 16ms before init LCD
    LCDinit();  // initialize LCD, cursor should be visible with blink after
#endif
    
#ifdef USE_LCD2
    lcd_init();
#endif
    
#ifdef USE_LED7
    led7_init();
    led7_write(LED7_HBARS);
#endif
    
    EnableInterrupts;
    
    sci_sendBytes((byte*)"Ready", 6);   // Send ready message indicator via serial
    
    for(;;) {
        /*
        while ( sci_bytesAvailable() ) {
            sci_readByte(&b);
            lcd_putc(b);  
        }*/
        RUN();
    }
}
Beispiel #2
0
void main(void) {
    
    DDRS_DDRS2 = 1; DDRS_DDRS3 = 1; // Enable LEDs
    DDRJ_DDRJ6 = 0; DDRJ_DDRJ7 = 0; // Enable switches
    
    timer_init();
    CANinit(MSCAN_NODE_ID);
    
    // Clear all MSCAN receiver flags (by setting bits)
    CANRFLG = (CANRFLG_RXF_MASK | CANRFLG_OVRIF_MASK | CANRFLG_CSCIF_MASK | CANRFLG_WUPIF_MASK);
    
    msleep(16); // wait 16ms before init LCD
    LCDinit();  // initialize LCD, cursor should be visible with blink after
    
    EnableInterrupts;
    
    for(;;) {
        RUN();
    }
}
Beispiel #3
0
int main(void)
{
	// Declaration and initialization of message-related data
	unsigned int txMsgSID = 0;
	unsigned char txMsgData[12] = {'1', '2', '3', '4', '5', 'S', 'X', 'U', 'C', 'L', 'D', 'R'};

	unsigned char buffer[32];
	unsigned int lenght = 0;
	unsigned int cursorPosition = 0;

	// Initialize keyboard, CAN and LCD
	KeybInit();
	CANinit(LOOPBACK_MODE, 0x0000, 0x0000);
	LCDInit();

	// Clear LCD
	LCDClear();

	// Char to save key pressed
	unsigned char c;

	while(1)
	{
		if(CANtransmissionCompleted())
		{
			// Get key pressed
			c = getKeyBlocking();

			if(lenght < 32 && cursorPosition < 32)
			{
				buffer[lenght] = txMsgData[c];
				lenght++;

				if(c == 0 || c == 1 || c == 2 || c == 3 || c == 4 || c == 11)
				{
					switch(c)
					{
						case 0:		LCDPrint("1");	break;
						case 1:		LCDPrint("2");	break;
						case 2:		LCDPrint("3");	break;
						case 3:		LCDPrint("4");	break;
						case 4:		LCDPrint("5");	break;
						case 11:	LCDMoveRight(); break;
					}

					// Cursor managment - Update position
					if(cursorPosition == 15)
					{
						// Cursor is at the end of the first line
						// Move to second line
						LCDMoveSecondLine();
					}
					// Increase cursor position
					cursorPosition++;
				}
				else if(c == 6 || c == 9)
				{
					// Pressed erase and go back key ( <- )
					if(cursorPosition == 0)
					{
						// Cursor is at the begining of the first line
						// Do nothing
					}
					else if(cursorPosition == 16)
					{
						// Cursor is at the begining of the second line
						// Move cursor to the last position of the first line
						LCDSetCursor(15);
						if(c == 6)
						{
							// Erase content (print a white space)
							LCDPrint(" ");
							// Move cursor back and decrease cursor position
							LCDMoveLeft();
						}
						cursorPosition--;
					}
					else
					{
						// Cursor is between extreme positions or at position 32
						// Move cursor back
						LCDMoveLeft();
						if(c == 6)
						{
							// Erase content (print a white space)
							LCDPrint(" ");
							// Move cursor back and decrease cursor position
							LCDMoveLeft();
						}
						cursorPosition--;
					}
				}
				else if(c == 7)
				{
					// Move to first line
					LCDMoveFirstLine();
					cursorPosition = 0;
				}
				else if(c == 10)
				{
					// Move to second line
					LCDMoveSecondLine();
					cursorPosition = 16;
				}
				else
				{
					// Pressed clear (C) or send (S)
					if(c == 8)
					{
						// Clear LCD
						LCDClear();
						// Move to home
						LCDMoveHome();
						// Set counter of cursor position to 0 (zero)
						cursorPosition = 0;
					}
					else
					{
						// Clear LCD and show message
						////////////////////
						//    SENDING!    //
						//                //
						////////////////////
						LCDClear();
						LCDMoveHome();
						LCDPrint("    SENDING!");

						// Wait 1s before start send
						for(i = 0; i < 200; i++) Delay5ms();
						// Clear LCD
						LCDClear();

						// Send message according keys pressed
						for(i = 0; i < lenght; i++)
						{
							CANsendMessage(txMsgSID, buffer[i]);
							// Wait until transmission complete
							while(CANtransmissionCompleted() == 0);
							// Wait 0,5s before send the next
							for(j = 0; j < 100; j++) Delay5ms();
						}

						lenght = 0;
						cursorPosition = 0;
						LCDMoveHome();
					}
				}
			}
			else
			{
				// Clear LCD and show message in two lines
				////////////////////
				//    WARNING!    //
				//  Full memory   //
				////////////////////
				LCDClear();
				LCDMoveHome();
				LCDPrint("    WARNING!");
				LCDMoveSecondLine();
				LCDPrint("  Full memory");

				// Pressed key send (S)
				if(c == 5)
				{
					// Clear LCD and show message
					////////////////////
					//    SENDING!    //
					//                //
					////////////////////
					LCDClear();
					LCDMoveHome();
					LCDPrint("    SENDING!");

					// Wait 1s before start send
					for(i = 0; i < 200; i++) Delay5ms();
					// Clear LCD
					LCDClear();

					// Send message according keys pressed
					for(i = 0; i < lenght; i++)
					{
						CANsendMessage(txMsgSID, buffer[i]);
						// Wait until transmission complete
						while(CANtransmissionCompleted() == 0);
						// Wait 0,5s before send the next
						for(j = 0; j < 100; j++) Delay5ms();
					}
				
					lenght = 0;
					cursorPosition = 0;
					LCDMoveHome();
				}
			}
		}
		// Wait 0,25s before to detect another time the key pressed
		for(i = 0; i < 50; i++) Delay5ms();
	}
}
Beispiel #4
0
void main(void) 
{
  /* put your own code here */
  
  SET_TCNT_PRESCALE( TCNT_PRESCALE_8);
	TSCR1 = TSCR1_INIT;
  
	seg_init();
	CANinit(THE_FLOOR);
	SET_BITS(LED_DDR, LED1_MASK|LED2_MASK);

	node_id = PORTB & 3; //get hardware specified node id
	
	while (!(CANCTL0&0x10));

	CANRFLG = 0xC3;
	CANRIER = 0x01;

	InitializeQueue(&rec);	// Create the Recieve Queue
	
	
	
     clear_seg();

	EnableInterrupts;

  for(;;) 
  {

	if(IsQueueEmpty(rec) != 0)
	{		
		DeQueue(&rec);
		Parse_Floor();
	}
  
  // button 1 press
    if((PTJ & (SWITCH1_MASK |SWITCH2_MASK) )== SWITCH1_MASK) 
    {
        if(THE_FLOOR == F1 || THE_FLOOR == F2)
        {
            if (last != SWITCH1_MASK) 
            {   // check if button already pressed 

            	data[0] = THE_FLOOR;
            	data[1] = CALL_SWITCH1;
            	data[2] = UP;
            	
            	(void)CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
            	last =  SWITCH1_MASK;        
            }  
        }
        else if(THE_FLOOR == F3)
        {
            if (last != SWITCH1_MASK) 
            {   // check if button already pressed 

                data[0] = THE_FLOOR;
                data[1] = CALL_SWITCH1;
                data[2] = DOWN;

                (void)CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
                last =  SWITCH1_MASK;        
            }  
        }

    }                
  
  //button 2 press
    else if((PTJ & (SWITCH1_MASK |SWITCH2_MASK) )== SWITCH2_MASK)
    {
        if(THE_FLOOR == F2)
        {
            if (last != SWITCH2_MASK) 
            { // check if button already pressed    
                data[0] = THE_FLOOR;
                data[1] = CALL_SWITCH2;
                data[2] = DOWN;

                CANSend(CONTROLLER, 0x00, 0x00, DATA_LENGTH, data); 
                last =  SWITCH2_MASK;
            } 
        }
 
    }
  
  else
  last = 0;
  
  
  // Updates the LED
  FORCE_BITS(PTS,0b00001100 , led) ;


  

  } /* loop forever */
  /* please make sure that you never leave main */
}