コード例 #1
0
// program entry point
int main()
{   
    int errCode; 
	struct LCD_Geometry *pointCurrent= &Current;
    struct LCD_Properties *pointProperties = &Properties;
    FILE lcd_str = FDEV_SETUP_STREAM(TerminalChar, NULL, _FDEV_SETUP_RW);
    stdout = &lcd_str;
	
	FRESULT rc;				/* Result code */
	DIR dir;				/* Directory object */
	FILINFO fno;			/* File information object */
	UINT bw, br, i;
	
   	USART_init();
   	SPI_MasterInit();
   	
   	SSD1289_Initalize();
	  
   	UTouch_InitTouch(0);
    LCD_Fill_Rectangle(0,0, 320,240,0x000000);
    terminalemulator();
    Terminal_Set_Properties(2, 1, 0xFFFFFF);
	//while(1) 	{ Paint_Program();}
	    
	printf("Serial Default Output");
	/* Init the MMC */
	printf("mmc_init\n");
	 //disk_initialize(0);
	mmc_init();
	
	
	
	/// Drive must be mounted before use  // Drive 0 - signifies SD System 
	/// Halt on anything other than mounting system okay
	errCode = f_mount(0, &filesystem);
	if (errCode != FR_OK)
	{
		printf("Error: f_mount failed, error code: %d\r", errCode);
		printf("Please refer to error list"); 
		while (1); // freeze
	}
	
	printf("\n Mounted File System: Type SD");
	// Draw BMP	
	
	printf("\nCreate a new file (hello.txt).\n");
	rc = f_open(&file, "HELLO.TXT", FA_WRITE | FA_CREATE_ALWAYS);
	
	printf("\nWrite a text data. (Hello world!)\n");
	rc = f_write(&file, "Hello world!\r\n", 14, &bw);
	printf("%u bytes written.\n", bw);

	printf("\nClose the file.\n");
	rc = f_close(&file);

	while(1){
		//printf("\nOpen root directory.\n");
		rc = f_opendir(&dir, "");
		
		//printf("\nDirectory listing...\n");
		for (;;) {
			rc = f_readdir(&dir, &fno);		/* Read a directory item */
			if (rc || !fno.fname[0]) break;	/* Error or end of dir */
		
			if (fno.fattrib & AM_DIR)
				printf("   <dir>  %s\n", fno.fname);
			else
				{
				//printf("%8lu  %s\n", fno.fsize, fno.fname);
				draw_bmp(0,0,fno.fname);
				}
		
		}
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: Connatus/ESE-robot
void RS232_TEST(void){
  struct LCD_Geometry *pointCurrent= &Current;
	struct LCD_Properties *pointProperties= &Properties;
   struct Terminal_Program_Values	*pointTerminal = &TerminalProperties;
 
  unsigned int i =0; 
  unsigned int RS232_LENGTH =0;
  unsigned char Error =0;
  unsigned int Local_Process =0; 
  unsigned int Local_counter =0;
  unsigned int Local_Message_Storage_Counter =0; 
  unsigned char Local_Error_Flag_Number =0;  

   int Encoder_L_Counter =0;
   int Encoder_R_Counter =0; 
   unsigned char Encoder_Watchdog_Flag =0; 


  Error_Flag_Number =0; 
 
 
  RS232_INIT();
//  RS232_ECD(1); 
  
 /* / Accelerometer_INIT(); 
   // fill outline 
   LCD_Fill_Rectangle(0,0,pointTerminal->xResolution,pointProperties->yResolution ,  0x00FFFF); //
     /// Disable any currently running interrupts /// 
   LCD_Fill_Rectangle(20,20,pointTerminal->xResolution-40,pointTerminal->yResolution-40, 0x000000);
  
  pointCurrent->size = 2;
  pointTerminal->previousx = 24; 
  pointTerminal->currentline = 2;
	printf("PROJECT IV - ROBIT V0.%d", 3); 
	
	
  pointTerminal->previousx = 25; 
  pointTerminal->currentline = 4;
	printf("%s", "MOTOR SPEED"); 
	pointTerminal->currentline = 5;
	pointTerminal->previousx = 105;  
	printf("%s", "ENCODER"); */

     
    asm("CLI"); 
    
   while(1){
      
      asm("SEI");
       // RS232
       RS232_LENGTH= RS232_COUNTER_OUTSIDE;   // could kill perhaps 
       Local_Process = RS232_Processed_Data_Flag; 
       Local_Message_Storage_Counter =Message_Storage_Counter; 
       Local_Error_Flag_Number = Error_Flag_Number; 
       /// ENCODER 
        Encoder_L_Counter = L_Counter;
        Encoder_R_Counter = R_Counter; 
        Encoder_Watchdog_Flag =  WATCH_DOG_FLAG;
      asm("CLI");
      
          
        if(Local_Error_Flag_Number != 0x00){
          asm("SEI"); 
           ERROR_PRINT_SCREEN_2("RS232 outside of alloted data storage array size",Local_Error_Flag_Number);
        }
      
        if(Local_Process){
          // KILL INTERRUPTS/// 
          asm("SEI"); 
          Local_Message_Storage_Counter  = (Message_Storage_Counter%RS232_MESSAGE_STORAGE_LENGTH); // used to count the number of chars in message array from RS232 


               /// store data in local array for use !!!! 100% NECESSARY FOR FUNCTION//
         for (i=0; i < (Local_Message_Storage_Counter); i++) 
            Local_Message_Storage_Array_RS232[i] =  MessageStorageArray[i]; 
            
             Message_Storage_Counter = 0;       // set main counter to zero 
             RS232_Processed_Data_Flag = 0;     // tell the interrupt process we, processed the dat
          //   Process_RS232(MessageStorageArray,Local_Message_Storage_Counter);  
           asm("CLI");
           
            for (i=0; i < (Local_Message_Storage_Counter); i++) 
              printf("%c", Local_Message_Storage_Array_RS232[i]);
                /// DATA ARRAY MUST BE PROCESSED EACH RECIEVE !!!
            Process_RS232(Local_Message_Storage_Array_RS232,Local_Message_Storage_Counter);  
         
            printf(" LENGTH: %d",  Local_Message_Storage_Counter); 
          
            printf("\n LOAD BOARD FUNCTION: %c", Board_Function);       
           switch(Board_Function) {
            
              /// RUN RS232 TYPE WRITER
              case '0':
                    printf("\nOPENIGN SERIAL TERMINAL"); 
                    RS232_ECD(RS232_Com_PORT);
                    break;
               /// RUN DC MOTOR
              case '1':
                    printf("\nDC MOTOR SHIT");
                    DC_Motor_ECD( Local_Message_Storage_Counter);
                    break;
               // MOVE CAMERA 
              case '2':
                    // printf("\nCAMERA MOVE");
                    Camera_ECD( Local_Message_Storage_Counter);       //Camera_ECD
                    //DC_Motor_Encoder_ECD(Local_Message_Storage_Array_RS232, Local_Message_Storage_Counter); 
                    break;   
              case '3':
                     printf("\nPING");
                    Ping_ECD(Local_Message_Storage_Counter);      
                     //DC_Motor_Encoder_ECD(Local_Message_Storage_Array_RS232, Local_Message_Storage_Counter);       
           
            break;  
           }
     
     }
     
         
      if(Encoder_Watchdog_Flag ==1){
          
           // printf("R %d \n", Encoder_R_Counter); 
           // printf("L %d \n", Encoder_L_Counter); 
           // RESET COUNTERS AND FLAGS
              
              LCD_Fill_Rectangle(335,100,50,50, 0x000000);

     
             	pointTerminal->previousx = 300; 
              pointTerminal->currentline = 12;
            	printf("%s:  %d", "LEFT", Encoder_L_Counter); 
            	
            	pointTerminal->previousx = 300; 
              pointTerminal->currentline = 13;
              printf("%s: %d ", "RIGHT", Encoder_R_Counter);       
            
           DisableInterrupts;
           WATCH_DOG_FLAG =0; 
           L_Counter =0;
           R_Counter =0; 
           EnableInterrupts;
      }
      
      // PASS VARS TO WATCHDOG
      DisableInterrupts;
      WATCH_L_COUNTER =  Encoder_L_Counter;
      WATCH_R_COUNTER =  Encoder_R_Counter; 
      EnableInterrupts; 
      
    //  Accelerometer_Test(); 
  
   }

}