Beispiel #1
0
void main(void) {
    TRISA = 0xff;
    TRISC = 0X00;
    TRISD = 0X00;
    InitLCD(); // Initialize LCD	
    InitI2C(); // Initialize i2c pins
    state = 1;
    // Khoi tao gia mac dinh
    //__delay_ms(10000) // Tre 1s  
    Set_DS1307_RTC_Time(PM_Time, 2, 30, 30);
    // kh?i t?o ngày tháng m?c ??nh
    Set_DS1307_RTC_Date(04, 04, 16, Tuesday);
    DisplayFirstTimeToLCD(Get_DS1307_RTC_Time());
    while (1) {
        switch (state) {
            case 1:
                displayState1();
                break;
            case 2:
                displayState2();
                break;
            case 3:
                displayState3();
                break;
            case 4:
                displayState4();
                break;
        }
    }
}
Beispiel #2
0
int main ()
{	struct intvector mag;	// integer vector of magnetometer measurements
	#define magx mag.x.i16	// x axis
	#define magy mag.y.i16	// y axis
	#define magz mag.z.i16	// z axis

	microcontroller_init();

	uart1_open(38400);		// open UART1
	printf ("Starting test...\n\r");

	InitI2C();				// Initialise the I2C(1) module
	init_HMC5843();			// initialize the HMC5843 chip
	test_HMC5843();			// display configuration and ID registers

	while(1)
	{
		HMC5843(&mag);		// update magnetometer data

		printf( "%5d %5d %5d\r",magx,magy,magz);

		microcontroller_delay_ms(100);
		
	}	// end while
}		// end main
int main (void)
{
	unsigned int n;		

	InitPorts();		
	InitI2C();			

	ControlByte = 0xA0;
	LowAdd = 0x0C;	
	HighAdd = 0x5A;
	Data = 0xAB;
	Length = 0x05;

	for(n = 0; n < PAGESIZE; n++)
	{
		PageString[n] = n;
	}

	while(1)
	{
		LATAbits.LATA0 = 1;
		LDByteWriteI2C(ControlByte, LowAdd, Data);	
		HDByteWriteI2C(ControlByte, HighAdd, LowAdd, Data);
		HDPageWriteI2C(ControlByte, HighAdd, LowAdd, PageString);
		LDByteReadI2C(ControlByte, LowAdd, &Data, 1);
		HDByteReadI2C(ControlByte, HighAdd, LowAdd, &Data, 1);
		HDSequentialReadI2C(ControlByte, HighAdd, LowAdd, PageString, PAGESIZE);

		Nop();
		LATAbits.LATA0 = 0;
		
	}	
}
Beispiel #4
0
Datei: user.c Projekt: dsky7/PIC
void InitApp(void)
{
    /*PORT*/
	TRISA = 0x0000;
	TRISB = 0x0F80;
	LATA = 0;
	LATB = 0;
        CNPUBbits.CNPUB7 = 1;
        CNPUBbits.CNPUB8 = 1;
        

    /* Setup analog functionality and port direction */
        ANSELA = 0;
	ANSELB = 0;

    /* Initialize peripherals */
        InitQEI();
        InitPWM();
        InitI2C();
       	I2C2ADD = 20;
//        InitT2T3();
//        InitT1();
        InitT2();
        POS1CNTH = 0x4000;		//32bit mode

	nRESOLUTION = 26880;		//4*64*105
        nTARGET = 0x40000000;
}
Beispiel #5
0
// Main function
void main(void)
{

	InitLCD();	// Initialize LCD	
	InitI2C();	// Initialize i2c pins											

	// Set initial time
	Set_DS1307_RTC_Time(TwentyFourHoursMode, 12, 59, 50);	// Set time 08:32:59 AM

	// Set initial date
	Set_DS1307_RTC_Date(15, 12, 12, Saturday); 	// Set 15-12-2012 @ Saturday

	while(1)
	{
	
		SetTime();
		// Display RTC time on first line of LCD
		DisplayTimeToLCD(Get_DS1307_RTC_Time());

		// Display RTC date on second line of LCD
		DisplayDateOnLCD(Get_DS1307_RTC_Date());

		__delay_ms(100);	// 1 second delay
	}
}
void InitHardware(void)
{
	Chip_SetupXtalClocking();
	Chip_SYSCTL_SetFLASHAccess(FLASHTIM_100MHZ_CPU);
	SystemCoreClockUpdate();
	InitI2C();
	SysTick_Config(SystemCoreClock/1000);
}
int32_t wm8737_init(void) {
  InitI2C();

  if (PingI2C() > 0) {
    WriteI2C(WM_RESET); /* Completely reset the ADC */
    wm8737_spi_off(); /* Stop the ADC clogging up the SPI bus */
  } else {
    debug_puts("Can't initialise the WM8737 data bus!");
    return -1;
  }

  /* ---- ADC Setup ---- */

  /**
   * Bypass the 3D enhancement filter so we can hit 96kHz sample rate.
   * See Page 21 of the datasheet for reference.
   */
  WriteI2C(WM_ALC1);
  WriteI2C(WM_ALC3);
  WriteI2C(WM_3D_ENHANCE);
  /* More magic to support 96kHz */
  WriteI2C(WM_ALC2 | 0x1C0); /* 1_110x_xxxx */
  /* Totally unsupported register here. I wonder what other magical things are up there.. */
  WriteI2C((0x1C << 9) | 0x4);

  /* fs = 96kHz from MCLK = 12MHz */
  WriteI2C(WM_CLOCKING | CLOCKING_USB | CLOCKING_SR_USB_96000HZ);

  /* Set our inputs to be LINPUT1 and RINPUT1, MICBOOST enabled */
  WriteI2C(WM_LEFT_PATH | PATH_INPUT1 | PATH_MICBOOST_ENABLE | get_left_micboost());
  WriteI2C(WM_RIGHT_PATH | PATH_INPUT1 | PATH_MICBOOST_ENABLE | get_right_micboost());

  /**
   * Preamplifer Bias. Lower values reduce current consumption,
   * PREAMP_BIAS25 uses about 1-2mA less than PREAMP_BIAS100.
   *
   * However, noise increases significantly, so it's best to use
   * PREAMP_BIAS100.
   */
  WriteI2C(WM_PREAMP_CTRL | PREAMP_BIAS100);

  /* Set the PGA Gain */
  WriteI2C(WM_LEFT_PGA | get_left_pga_gain() | PGA_UPDATE);
  WriteI2C(WM_RIGHT_PGA | get_left_pga_gain() | PGA_UPDATE);

  /* High impedance VMID: Slow Charging time, low power usage */
  WriteI2C(WM_BIAS_CTRL | VMID_300000_OMHS | BIAS_LEFT_ENABLE | BIAS_RIGHT_ENABLE);

  WaitForI2C();

  VMID_INIT();
  VMID_ON();

  /* Put the interface on standby */
  wm8737_power_standby();

  return 1;
}
Beispiel #8
0
void initRobit() {
  //Initialize POB-EYE (lib), POB-LCD (lib), POB-PROTO(file Functions.c) and Servomotors
  InitPobeye2();
  InitI2C(I2C_100_KHZ);
  InitCameraPobeye2();
  InitLCD();      
  // Even though this project doesn't directly use the joystick, still set up
  // the ports to allow reading/writing of values to the DC motors
  SetupJoystick();
  SwitchOnAllServo();
  initCameraAndLCD();  
}
Beispiel #9
0
static void Init()
{
    InitI2C();
    
    memset(&OpState, 0, sizeof(OpState));
    memset(&OdomState, 0, sizeof(OdomState));
    memset(&SensorState, 0, sizeof(SensorState));
    memset(&ImuState, 0, sizeof(ImuState));
    memset(&SafetyState, 0, sizeof(SafetyState));
    
    OpState.max_forward_speed = DEFAULT_MAX_SPEED;
    OpState.max_reverse_speed = DEFAULT_MAX_SPEED;
}
Beispiel #10
0
int ReleaseDecoder7114(int nWhichDecoder)
{
    InitI2C();

    if(DetectI2C(I2CPort[nWhichDecoder])==0) {
        return -1;
    }

    if(SendOneByte(I2CPort[nWhichDecoder], 0x83, 0x00))
    	if(SendOneByte(I2CPort[nWhichDecoder], 0x87, 0x00))
        	return 0;

    return -1;
}
Beispiel #11
0
 int main( void )
  {
   InitVFD();
   InitISD();
   InitI2C();
   InitADC();
   InitRTC();
   InitDS75();
   InitKeys();
   InitUART();
   InitRFM();
   InitAlarm();

   sei();
   wdt_enable(WDT_DEFAULT);

   UI();   

   return 0;
 }
Beispiel #12
0
// Main function
void main()
{	
	InitLCD();	// Initialize LCD	
	InitI2C();	// Initialize i2c pins											

	// Set initial time
	Set_DS1307_RTC_Time(AM_Time, 8, 32, 59);	// Set time 08:32:59 AM

	// Set initial date
	Set_DS1307_RTC_Date(2, 11, 12, Friday); 	// Set 02-11-2012 @ Friday

	while(1)
	{
		// Display RTC time on first line of LCD
		DisplayTimeToLCD(Get_DS1307_RTC_Time());

		// Display RTC date on second line of LCD
		DisplayDateOnLCD(Get_DS1307_RTC_Date());

		delay(65000);	// Roughly about 1 second delay
	}
}
Beispiel #13
0
/*
** Main function. The application starts here.
*/
int main(void)
{
    unsigned int index;
    unsigned int j;

    int result = 0;

    /*
    ** Sets up Section page tables. This is only first level
    ** page table, each page is of size 1MB
    */
    for(index = 0; index < (4*1024); index++)
    {
         /* Set the cacheable memory attributes */
         if((index >= 0x800 && index < 0x880) || (index == 0x403))
         {
              pageTable[index] = (index << 20) | CACHEABLE_TLB_ATTR;
         }

         /* Set the non-cacheable memory attributes */
         else
         {
              pageTable[index] = (index << 20) | NORM_TLB_ATTR;
         }
    }


    /* Invalidate the TLB, pipeline */
    CP15TlbInvalidate();
    CP15BranchPredictorInvalidate();

    CP15BranchPredictionEnable();

    CP15DomainAccessClientSet();

    /* Set TTB0 value. We use only TTB0 here (N = 0) */
    CP15Ttb0Set(((unsigned int )pageTable) | RGN_L2_WBWA);

    /* Enables MMU */
    CP15MMUEnable();

    /* Flush and enable Instruction Cache */
    CP15ICacheFlush();
    CP15ICacheEnable();

    PeripheralsSetUp();

    /* Initialize the ARM Interrupt Controller */
    IntAINTCInit();

    /* Register the ISRs */  
    Timer2IntRegister();
    Timer4IntRegister();
    EnetIntRegister();
    RtcIntRegister();
    HSMMCSDIntRegister();
    IntRegister(127, dummyIsr);

    IntMasterIRQEnable();

    /* Enable system interrupts */
    IntSystemEnable(SYS_INT_RTCINT);
    IntPrioritySet(SYS_INT_RTCINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWTXINT0);
    IntPrioritySet(SYS_INT_3PGSWTXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWRXINT0);
    IntPrioritySet(SYS_INT_3PGSWRXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT2);
    IntPrioritySet(SYS_INT_TINT2, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT4);
    IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_MMCSD0INT);
    IntPrioritySet(SYS_INT_MMCSD0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_EDMACOMPINT);
    IntPrioritySet(SYS_INT_EDMACOMPINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(127);
    IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ);

    RtcInit();
    UARTStdioInit();
    HSMMCSDContolInit();
    DelayTimerSetup();

    Timer2Config();
    Timer4Config();
    LedIfConfig();

    Timer2IntEnable();
    Timer4IntEnable();
    RtcSecIntEnable();

    InitI2C();

    Timer4Start(); 

    // Read config from files
    HSMMCSDCardAccessSetup();

    configRead();

    LedOn( USER_LED_1 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_1 );
    LedOn( USER_LED_2 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_2 );
    LedOn( USER_LED_3 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_3 );
    LedOn( USER_LED_4 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_4 );

    // TEMP
    //i2cTest();

    /*
    ** Loop for ever. Necessary actions shall be taken
    ** after detecting the click.
    */
    while( 1 )
    {
        EnetStatusCheckNUpdate();

        if( runCommand )
        {
            // Command blink
            LedOn( USER_LED_1 );

            if( runData[ runIndex + 1 ] == 'D' )
            {
                if( runData[ runIndex + 2 ] == 'S' )
                {
                    UARTPuts( "** DAC SET\n\r", -1 );

                    if( runData[ runIndex + 3 ] == 'A' )
                    {
                        i2cDAC_Set( 0,
                          runData[ runIndex + 4 ], runData[ runIndex + 5 ] );
                    }
                    if( runData[ runIndex + 6 ] == 'B' )
                    {
                        i2cDAC_Set( 1,
                          runData[ runIndex + 7 ], runData[ runIndex + 8 ] );
                    }
                    if( runData[ runIndex + 9 ] == 'C' )
                    {
                        i2cDAC_Set( 2,
                          runData[ runIndex + 10 ], runData[ runIndex + 11 ] );
                    }
                    if( runData[ runIndex + 12 ] == 'D' )
                    {
                        i2cDAC_Set( 3,
                          runData[ runIndex + 13 ], runData[ runIndex + 14 ] );
                    }
                }
                else if( runData[ runIndex + 2 ] == 'G' )
                {
                    UARTPuts( "** DAC GET\n\r", -1 );

                    uartData[ 0 ] = 15;
                    uartData[ 1 ] = 'D';
                    uartData[ 2 ] = 'G';

                    uartData[ 3 ] = 'A';
                    i2cDAC_Get( 0, &uartData[ 4 ] );

                    uartData[ 6 ] = 'B';
                    i2cDAC_Get( 1, &uartData[ 7 ] );

                    uartData[ 9 ] = 'C';
                    i2cDAC_Get( 2, &uartData[ 10 ] );

                    uartData[ 12 ] = 'D';
                    i2cDAC_Get( 3, &uartData[ 13 ] );

                    net_ext_send( uartData, 15 );
                }
            }
            else if( runData[ runIndex + 1 ] == 'G' )
            {
                if( runData[ runIndex + 2 ] == 'S' )
                {
                    if( runData[ runIndex + 3 ] == 0 ) // Off
                    {
                        UARTPuts( "** GPIO OFF\n\r", -1 );
                        i2cGPIO_Off( 0, 1 << runData[ runIndex + 4 ] );
                    }
                    else if( runData[ runIndex + 3 ] == 1 ) // On
                    {
                        UARTPuts( "** GPIO ON\n\r", -1 );
                        i2cGPIO_On( 0, 1 << runData[ runIndex + 4 ] );
                    }
                }
                else if( runData[ runIndex + 2 ] == 'G' )
                {
                    UARTPuts( "** GPIO GET\n\r", -1 );

                    uartData[ 0 ] = 5;
                    uartData[ 1 ] = 'G';
                    uartData[ 2 ] = 'G';

                    i2cGPIO_Get( &uartData[ 3 ] );

                    net_ext_send( uartData, 5 );
                }
            }
            else if( runData[ runIndex + 1 ] == 'U' )
            {
                UARTPuts( "** UART\n\r", -1 );
                i2cUART_Send( &(runData[ runIndex + 2 ]), 6 );
            }

            runCommand -= runData[ runIndex + 0 ];

            if( runCommand > 0 )
            {
                runIndex += runData[ runIndex + 0 ];
            }
            else
            {
                runIndex = 0;
            }

            LedOff( USER_LED_1 );
        }

        result = i2cUART_Recv( &( uartData[ 2 ] ), 30 );

        if( result > 0 )
        {
            UARTPuts( "** UART Recv: ", -1 );

            for( index = 0; index < result; ++index )
            {
                UARTPutHexNum( uartData[ index + 2 ] );
                UARTPutc( ' ' );
            }

            UARTPutc( '\n' );
            UARTPutc( '\r' );

            // Return the stage position info to the GUI
            if( uartData[ 3 ] == 0x0A ||
                uartData[ 3 ] == 0x3C )
            {
                uartData[ 0 ] = result + 2;
                uartData[ 1 ] = 'U';

                net_ext_send( uartData, result + 2 );
            }
        }
    }
}
boolean MP3Player::Init(byte CS_uSD,byte ASD)
{
	PLAY = false;
	isPlayAll = false;
	name.reserve(80);
	name = "";
	vol = 0;
	counter=0;
	currentDir.reserve(20);
	currentDir = "";
	_isPause = false;
	_isMute = false;
	ls_flag = false;
	
	CS_SD=CS_uSD;
	AMP=ASD;	
	
	pinMode(CS,OUTPUT); //STA013CS
	digitalWrite(CS,LOW);   //deactivate sta013 spi input

	pinMode(DATREQ,INPUT);  //DATREQ

	pinMode(RESET,OUTPUT);  //reset
	digitalWrite(RESET,HIGH); 

	pinMode(AMP,INPUT); //shutdown the amp

	pinMode(CS_SD, OUTPUT);  //SPI uSD CS
	
	InitI2C();
	Reset_STA013(); 
	
		
#if DEBUG
	Serial.begin(9600);
	while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only
#endif
	
	if (!sd.begin(CS_SD, SPI_FULL_SPEED)) 
	{
		#if DEBUG
		sd.initErrorHalt();
		#endif
		return false;
	}

	SPI.begin(); 

	boolean stat=Verify_STA013();
	if (stat==false) 
	{
		#if DEBUG
		Serial.println("STA013 not exist!");
		#endif
		return false;		
	}
	else
	{	
		#if DEBUG
		Serial.println("STA013 verified.."); 
		#endif
		if(!Setup_STA013())
		{
			return false;
		}
		else
		{
			delayMicroseconds(100000);
			setVolume(220); // set volume by default in case user forgets to set it.
			AMPON();
			return true;
		}
	}

}
Beispiel #15
0
int16_t main(void)
{

    unsigned int buttonCounter = 20000;
    int i;

    /* Configure the oscillator for the device */
    ConfigureOscillator();
    /* Initialize IO ports and peripherals */
    InitApp();
    //initSerial();
    initSPI1();
    initSPI2();
    InitI2C();
    __delay32(1600000); // allow for POR for all devices
    initnRF();
    ControlByte = 0x00D0; // mpu6050 address
    InitMPU6050(ControlByte);
//    InitHMC5883L();
    __delay_ms(500);
    /** Init control loop *****************************************************/
    readSensorData();
    accXangle = (atan2(accel[0], accel[2])*RAD_TO_DEG);
    accYangle = (atan2(accel[1], accel[2])*RAD_TO_DEG);
    gyroXangle = accXangle;
    gyroYangle = accYangle;
    compAngleX = accXangle;
    compAngleY = accYangle;
    AngleOffset[0] = accXangle;
    AngleOffset[1] = accYangle;

    CalibrateGyro();    // Finding the gyro zero-offset
    SetupInterrupts();
   
//////    int serStringN = 14;
//////    char nRFstatus = 0;
////////    int i;
//////    delaytime = 1;
//////    bool mode = 0;
    while(1)
    {
        /** Read Button RB7 for enable steppers *******************************/
        if (buttonState == 0 && PORTBbits.RB7 && !buttonCounter)
        {
            buttonState = 1;
            buttonCounter = 20000;
            enableSteppers = 0;
        }
        if (buttonState == 1 && !PORTBbits.RB7 && !buttonCounter)
        {
            enableSteppers = 2;
            __delay32(40000000);
            buttonState = 2;
            buttonCounter = 20000;
            enableSteppers = 1;
        }
        if (buttonState == 2 && PORTBbits.RB7 && !buttonCounter)
        {
            buttonState = 3;
            buttonCounter = 20000;
            enableSteppers = 0;
        }
        if (buttonState == 3 && !PORTBbits.RB7 && !buttonCounter)
        {
            buttonState = 0;
            buttonCounter = 20000;
            enableSteppers = 0;
        }
        if (buttonCounter)
        {
            buttonCounter--;
        }
        for (i=0;i<100;i++)
        {
            i=i;
        }
//        __delay32(100);
    }

}
Beispiel #16
0
void PCA9548A_Init(uint8_t slave_address)
{
	PCA9548A_Reset();
	 _EINT();
	InitI2C(slave_address);
}
Beispiel #17
0
///////////////////////////////////////////////////////////////////////////////////////
// Routine 	: CheckExpBoardPresence()
// Inputs	: None
// Outputs	: None
// Process  : global var byte STATUS_Z8_EXP is updated to true/false (1 bit per expansion found)
//			  This function is performed only during the boot
///////////////////////////////////////////////////////////////////////////////////////
void CheckExpBoardPresence(void)
{
	//uchar i;
	uchar Mask = 1;
	uchar data_read_from_i2c[3];
	uchar exp_found_nb = 0;
	uchar total_ana_ctrl = 0;
	uchar total_dig_ctrl = 0;

	// Clear expansion presence register before searching
	STATUS_Z8_EXP = 0;

	// Search up to 8 expansions on the I2C bus (i represents A2,A1,A0 similar to dipswitches)
	for(current_i2c_exp=0; current_i2c_exp < EXPANSION_MAX_NB; current_i2c_exp++)
	{
		// set I2C command to execute
		I2cCommand = EXP_I2C_SLAVE_ADR_RAM + (current_i2c_exp<<1);
		EE_Address = EXP_ID_REG_ADR;

		// in the table of I2C IDs found, 0xFF means no I2C module found
		expansion[current_i2c_exp].exp_id_found = 0xFF;
		data_read_from_i2c[0] = ReadByteI2c();
		if(!(Z8_STATUS_10 & i2c_timout_z10))
		//if(ReadBytesFromExpansion(EXP_I2C_SLAVE_ADR_RAM + (i<<1), EXP_ID_REG_ADR, 1, (far uchar *) &data_read_from_i2c[0]) == I2C_NO_TIMEOUT)
		{
			// Acknoledge received - the expansion at address i is connected
			STATUS_Z8_EXP |= Mask;
			// Store the I2C address found in a table
			expansion[current_i2c_exp].exp_id_found = data_read_from_i2c[0];
			// update total expansion found
			exp_found_nb++;
			// read the nb of analog and digital controls available in the expansion connected
			// ReadBytesFromExpansion(EXP_I2C_SLAVE_ADR_RAM + (i<<1), EXP_STATUS_REG_ADR, 2, (far uchar *) &data_read_from_i2c[0]);	
			EE_Address = EXP_STATUS_REG_ADR;
			ReadMultiByteI2c((far uchar *) &data_read_from_i2c[0], 2);
			// Update nb of analog control presents
			total_ana_ctrl += data_read_from_i2c[0];
			// Update nb of digital control presents
			total_dig_ctrl += data_read_from_i2c[1];
			// Fill the expansion structures
			expansion[current_i2c_exp].nb_an_ctrl  = data_read_from_i2c[0];
			expansion[current_i2c_exp].nb_dig_ctrl = data_read_from_i2c[1];
	
		}
		Mask = Mask << 1;
	} // end for all expansions

	// if at least one expansion was found, configure it
	ConfigureAllExpansions();
	
	// reset I2C controller
	I2CCTL &= ~I2C_ENABLE;
	InitI2C();

	// Display expansions found
	// V1.6 : nb of expansion found are displayed directly on the home screen
	// Display small expansion text + clear zone where was written fw version
	DisplayBmp(LCD_ZONE_FW_VERSION_HOME_X-17, LCD_ZONE_FW_VERSION_HOME_Y, LCD_INVERT, exp_small_txt_bmp);
	FillLcdZone(LCD_ZONE_FW_VERSION_HOME_X-3, LCD_ZONE_FW_VERSION_HOME_Y, 21, 1, FILL_BLANK);
	DisplayLcdInt(LCD_ZONE_FW_VERSION_HOME_X+3, LCD_ZONE_FW_VERSION_HOME_Y, DIGITS_2|LCD_INVERT|FONT_5x8_FLG/* V1.66 , font_5x8 */, exp_found_nb ); 

	// CHECK THAT ALL CONNECTED MODULES ARE FITTING THE BS3X MEMORY
	if( (total_dig_ctrl >= (EXP_DIG_MAX_PER_MODULE * EXPANSION_MAX_NB)) || 
	 	(total_ana_ctrl >= (EXP_ANA_MAX_PER_MODULE * EXPANSION_MAX_NB)))
	{
		rom_to_lcd_text_copy(expansion_txt);
		DisplayEmptyIncrust();
		rom_to_lcd_text_copy(remove_txt);
		DisplayLcdText(LCD_ZONE_INCRUST_X+1, LCD_ZONE_INCRUST_Y+3, LCD_INVERT|FONT_5x8_FLG/* V1.66 , font_5x8 */ );	
		rom_to_lcd_text_copy(expansion_txt);
		DisplayLcdText(LCD_ZONE_INCRUST_X+39, LCD_ZONE_INCRUST_Y+3, LCD_INVERT|FONT_5x8_FLG/* V1.66 , font_5x8 */ );	
		// Z8_STATUS_7 &= ~must_reinit_all_lcd_z7;
		//asm ("STOP");
		while(1);
	}
}
Beispiel #18
0
void EEPROM_Init(uint8_t slave_address)
{
	 _EINT();
	InitI2C(slave_address);
}
Beispiel #19
0
int InitDecoder7114(int nWhichDecoder, int nVideoSys, int nTuner, int nVBI)
{
    u8 bSubAddr = 0x02;
    //    u8 bData;
    int nCounter;

    DEBUG0("InitDecoder7114");
    InitI2C();

    if(DetectI2C(I2CPort[nWhichDecoder])==0) {
    	DEBUG0("DetectI2C failed");
        return -1;
    }

    if(nVideoSys==NTSC) {
		if(nWhichDecoder==Philips7114) {
            for(nCounter=0; nCounter<P7114_Count; nCounter++) {
                if(nVBI==0) {  
                    if(SendOneByte(I2CPort[nWhichDecoder], 
                        Phil7114_NTSC[0][nCounter * 2], 
                        Phil7114_NTSC[0][nCounter * 2+1]) == 0) {
                        DEBUG0("Failed to initialize Philips 7114(1) decoder");
                        return -1;
                    }
                }
                else {
                    if(SendOneByte(I2CPort[nWhichDecoder], 
                        Phil7114_NTSC[1][nCounter * 2], 
                        Phil7114_NTSC[1][nCounter * 2+1])==0) {
                        DEBUG0("Failed to initialize Philips 7114(1) decoder");
                        return -1;
                    }
                }
            }
            if(nTuner==1) SendOneByte(I2CPort[nWhichDecoder], bSubAddr, 0xC0);
            DEBUG0("Initialized Philips 7114(1) to NTSC mode successfully!");
        }
        else if(nWhichDecoder==Philips7114_40) {
            for(nCounter=0; nCounter<P7114_Count; nCounter++) {
                if(nVBI==0) {
                    if(SendOneByte(I2CPort[nWhichDecoder], 
                        Phil7114_NTSC[0][nCounter * 2], 
                        Phil7114_NTSC[0][nCounter * 2+1])==0) {
                        DEBUG0("Failed to initialize Philips 7114(2) decoder!");
                        return -1;
                    }
                 
                }
                else {
                    if(SendOneByte(I2CPort[nWhichDecoder], 
                        Phil7114_NTSC[1][nCounter * 2], 
                        Phil7114_NTSC[1][nCounter * 2+1]) == 0) {
                        DEBUG0("Failed to initialize Philips 7114(2) decoder!");
                        return -1;
                    }
                }
            }
			WriteReg(0x3d4, 0xe1, ReadReg(0x3d4, 0xe1) | 0x0c);
            DEBUG0("Initialized Philips 7114(2) to NTSC mode successfully!");
        }
    }
    else {
        if(nWhichDecoder==Philips7114) {

          DEBUG0("Initializing Philips 7114(1) to PAL mode ...");
			
				for(nCounter=0; nCounter<P7114_Count; nCounter++) {
                if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], 
                    Phil7114_PAL[nCounter * 2+1])==0) {
                    DEBUG0("Failed to initialize Philips 7114(1) decoder!");
                    return -1;
                }
					//
					// Read back registers to verify (R.Recalcati)
					//
					{ u8 tmp;
			  	  if (ReadOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], &tmp)){
							if (tmp!=Phil7114_PAL[nCounter * 2+1]){
								if (Phil7114_PAL[nCounter * 2]!=0xf) // Is only readable, it doesn't accept modifying and so test fails
									DEBUG0("Problem configuring Philips 7114(1) at byte %x : read %x, correct %x",Phil7114_PAL[nCounter * 2], tmp, Phil7114_PAL[nCounter * 2+1]);
				  		//return -1;
						}
//					else
//					  DEBUG0("\t\t(%x) = %x\t\tOK\n",Phil7114_PAL[nCounter * 2],tmp);
				  }
				  else{
						DEBUG0("Problem configuring Philips 7114(1) at byte %x : not read",Phil7114_PAL[nCounter * 2]);
				  	return -1;
				  }
					}
            }
			
            if(nVBI==1) SendOneByte(I2CPort[nWhichDecoder], 0x87, 0x01);
            if(nTuner==1) SendOneByte(I2CPort[nWhichDecoder], bSubAddr, 0xC0);
            DEBUG0("Initialized Philips 7114(1) to PAL mode successfully!");
        }
        else if(nWhichDecoder==Philips7114_40) {
            for(nCounter=0; nCounter<P7114_Count; nCounter++) {
                if(SendOneByte(I2CPort[nWhichDecoder], Phil7114_PAL[nCounter * 2], 
                    Phil7114_PAL[nCounter * 2+1])==0) {
                    DEBUG0("Failed to initialize Philips 7114(2) decoder!");
                    return -1;
                }
            }
	    WriteReg(0x3d4, 0xe1, ReadReg(0x3d4, 0xe1) | 0x0c); 
            DEBUG0("Initialized Philips 7114(2) to PAL mode successfully!");
        }
    }

	//
	// Alcuni test 
	//
  { u8 tmp;
      if (ReadOneByte(0x42, 0x88, &tmp))
			DEBUG0("SAA7114: Power Save Control (0x88) = %x",tmp);
      else
			DEBUG0("SAA7114: Power Save Control not read");
      tmp |= 0x01;
      SendOneByte(0x42,0x88,tmp);
      if (ReadOneByte(0x42, 0x88, &tmp))
			DEBUG0("SAA7114: Power Save Control (0x88) = %x",tmp);
      else
			DEBUG0("SAA7114: Power Save Control not read");
 
      if (ReadOneByte(0x42, 0x8f, &tmp))
			DEBUG0("SAA7114: Decoder byte test (0x8f) = %x",tmp);
      else
      {
			DEBUG0("SAA7114: Decoder byte test not read");
			DEBUG0("SAA7114: Startup may be failed");
      }

      if (ReadOneByte(0x42, 0x00, &tmp))
			DEBUG0("SAA7114: Chip Version (0x00) = %x",tmp);
      else
			DEBUG0("SAA7114: Chip Version not read");

      if (ReadOneByte(0x42, 0x1f, &tmp))
			DEBUG0("SAA7114: Status Byte (0x1f) = %x",tmp);
      else
			DEBUG0("SAA7114: Decoder Status Byte not read");
    }

  //
  // Necessario per avviare le task del SAA7114
  //
  DEBUG0("SAA7114 Task Reset");
  SendOneByte(0x42,0x88,0x58);
  udelay(100000);           // 0.1 sec 
  udelay(100000);           // 0.1 sec 
  udelay(100000);           // 0.1 sec  
  udelay(100000);           // 0.1 sec  
  udelay(100000);           // 0.1 sec  
  SendOneByte(0x42,0x88,0x78);
  DEBUG0("SAA7114 GOOO!!!");

    return 0;
}
int main (void)
{	
	UInt8 i=0,Nb_Identify=0;
	
	// List of form
	Form ListOfForm[MAX_OF_FORM];

	// Struct of three pointers on the RGB components
	UInt8 * FrameFromCam;

	//The pixels will be stocked in the LCD buffer
	UInt8 LCD_Buffer [LCD_WIDTH*LCD_HEIGHT*BITS] ;
	GraphicBuffer ScreenBuffer ;

	// System and LCD screen initialization
	InitPobeye2();
	InitI2C(I2C_100_KHZ);
	InitCameraPobeye2();
	InitLCD();	


	InitPobProto();
	SwitchOnAllServo();
	
	// Get the pointer of the red,green and blue video buffer
	FrameFromCam = GetRGBFrame();
		
	// Init the Graphic buffer with 128 per 64, one pixel per bit and LCD_Buffer
	InitGraphicBuffer( &ScreenBuffer, LCD_WIDTH,LCD_HEIGHT,ONE_BIT,LCD_Buffer);

	// clear the graphic buffer
	ClearGraphicBuffer(&ScreenBuffer);

	while(1)
	{		
		// grab the RGB components
		GrabRGBFrame();				
		
		// Binary the three RGB Buffer
		BinaryRGBFrame(FrameFromCam); 
		
		// Try to identify the forms and make a list of it
		Nb_Identify=IdentifyForm(FrameFromCam,ListOfForm,pattern);	

		// Parse the list of the form and print result on the Pob-Terminal and the LCD Screen
		for (i=0;i<Nb_Identify;i++)
		{
			switch (ListOfForm[i].id)
			{
			case IDP_0_CROSS:
				// Draw bitmap on the buffer and the LCD screen
				DrawBitmap(0,0,IDB_CROSS,bitmap,&ScreenBuffer);
				DrawLCD(&ScreenBuffer);
				MoveBot(RUN);
			break;
				
//			case IDP_1_BIGA:
//				DrawBitmap(0,0,IDB_BIGA,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;

			case IDP_2_KING:
				DrawBitmap(0,0,IDB_KING,bitmap,&ScreenBuffer);
				DrawLCD(&ScreenBuffer);
				MoveBot(LEFT);
			break;

//			case IDP_3_TOWER:
//				DrawBitmap(0,0,IDB_TOWER,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;
			
//			case IDP_4_TREFLE:
//				DrawBitmap(0,0,IDB_BIGA,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;
			
//			case IDP_5_TRIANGLE:
//				DrawBitmap(0,0,IDB_TRIANGLE,bitmap,&ScreenBuffer);
//				DrawLCD(&ScreenBuffer);
//			break;
			
			default:
				MoveBot(STOP);
			break;
			
			}				
		}		
	if (Nb_Identify == 0)
		{
		DrawBitmap(0,0,IDB_NOFORMS,bitmap,&ScreenBuffer);
		DrawLCD(&ScreenBuffer);
		}
	}
	return 0;
}