Esempio n. 1
0
int main(void) {  
    uint8_t t1, t2;	
    uint32_t temp;
    sint32_t i;
    
    //Enable I2C controller
    set_clk();	
    
    // 'Clear' 7_Seg display
    DE0_7SEG_DISP = 0xFFFFFFFF;
    
    // configure the I2C temperature sensor with 12-bit resolution
    write_with_start(I2C_TEMP_SENSE_Slave_Addr);
    write_byte(I2C_TEMP_SENSE_Conf_Reg);
    write_with_stop(I2C_TEMP_SENSE_12bitRes);
    
    while (1) {	
        DE0_LEDs = DE0_LEDs|(1<<8);    // blink LED8 to indicate program execution status	
        for (i=0;i<0x300000;i++);      // delay		
	
        // get the temperature sensor value
        write_with_start(I2C_TEMP_SENSE_Slave_Addr);
        write_with_stop(I2C_TEMP_SENSE_Temp_Reg);
        read_with_start(I2C_TEMP_SENSE_Slave_Addr);
        t1 = read_byte();                //Read the higher byte
        t2 = read_with_stop();           //Reading the lower byte
        
        temp = convert_for_7_seg(t1,t2);    // converted the value into appropriate 7-segment format
        DE0_7SEG_DISP = temp;		    // display it on DE0 board
    }
}
Esempio n. 2
0
int main(void)
{
        /*Disable watchdog*/
        RCONbits.SWDTEN = 0;
	set_clk();
        DataStructInit(&sSensorValues);
        NotusInitIOs();
        NotusInitPeripherals();
        NotusInitDevices();

        /*CAN bus initialization*/
        /*Encoder & decoder*/
	chinookpack_fbuffer_init(&buf,bTxCanBuffer,8);
	chinookpack_packer_init(&pk,&buf,chinookpack_fbuffer_write);
	chinookpack_unpacked_init(&unpacker);

        /*Msg*/
        /*configuration du message pour la direction de l'eolienne */
	config_CAN_filter(0, CAN_MSG_TURBINE_DIRECTION_SID , STANDARD_ID);
	receive_CAN_msg(0, 3, fct_can_turbine_direction);

	/*configuration du message pour le gear */
	config_CAN_filter(1, CAN_MSG_GEAR_SID , STANDARD_ID);
	receive_CAN_msg(1, 3, fct_can_gear);

        /*configuration du message pour l'eeprom ack */
	config_CAN_filter(2, CAN_MSG_EEPROM_CONFIG_ACK_SID , STANDARD_ID);
        receive_CAN_msg(2, 3, fct_can_eeprom_answer);

        /*configuration du message pour l'eeprom ack */
	config_CAN_filter(3, CAN_MSG_PITCH_ACK_CONFIG , STANDARD_ID);
        receive_CAN_msg(3, 3, fct_can_pitch_eeprom);

        /*configuration du message pour le pitch */
	config_CAN_filter(4, CAN_MSG_MANUAL_PITCH_SID , STANDARD_ID);
        receive_CAN_msg(4, 3, fct_can_pitch);

	config_CAN_Tx_msg(&sCanMsgTurbineRPM,CAN_MSG_TURBINE_RPM_SENSOR_SID,STANDARD_ID,3);
	config_CAN_Tx_msg(&sCanMsgWheelRPM,CAN_MSG_WHEEL_RPM_SID,STANDARD_ID,3);
	config_CAN_Tx_msg(&sCanMsgWindSpeed,CAN_MSG_WIND_SPEED_SID,STANDARD_ID,3);
	config_CAN_Tx_msg(&sCanMsgWindDirection,CAN_MSG_WIND_DIRECTION_SID,STANDARD_ID,3);
 	config_CAN_Tx_msg(&sCanMsgTrust,CAN_MSG_TRUST_SID,STANDARD_ID,3);
        config_CAN_Tx_msg(&sCanMsgAccelerometer,CAN_MSG_ACCELERATION_SID,STANDARD_ID,3);
        config_CAN_Tx_msg(&sCanMsgEepromConfigSend,CAN_MSG_EEPROM_CONFIG_SEND_SID,STANDARD_ID,3);
        config_CAN_Tx_msg(&sCanMsgEepromPitchSend,CAN_MSG_PITCH_CONFIG_SEND,STANDARD_ID,3);

        /*UART command decoder initialization*/
        UartSetRXLineEvt(UART_1,uartReceiveLineEvt);
        skadi_init(&skadi, skadiCommandTable,sizeof(skadiCommandTable)/sizeof(SkadiCommand));

	while(TRUE)
	{
                /*Get sensors data*/
                GetTrust(&sSensorValues);
                GetWindDirection(&sSensorValues);
                GetWindSpeed(&sSensorValues);
                GetTurbineRPM(&sSensorValues);
                GetWheelRPM(&sSensorValues);
                Get3V3Sensing(&sSensorValues);
                Get5V0Sensing(&sSensorValues);
                //GetsAccelerometer0(&sSensorValues);

                /*Uart command processing*/
                if(uartline_rcv_new){
                    skadi_process_command(&skadi,uartline_rcv);
                    uartline_rcv_new=0;
                }

		if(print)
		{
                    LED_STAT2^=1;
                    /*Send CAN messages*/

                    /*Initial message to set turbine direction and gear*/
                    if(ubEepromAnswerReceive == 0x55)
                    {
                        ubEepromGearInit = ReadGearEeprom();
                        fEepromTurbineDirectionInit = ReadTurbineDirEeprom();
                        chinookpack_pack_uint8(&pk,ubEepromGearInit);
                        chinookpack_pack_float(&pk,fEepromTurbineDirectionInit);
                        Set_Timeout();
                        send_CAN_msg(&sCanMsgEepromConfigSend,bTxCanBuffer, 7);
                        while(!is_CAN_msg_send(&sCanMsgEepromConfigSend) && !sSystemFlags.CanTimeout);
                        Reset_Timeout();
                        chinookpack_fbuffer_clear(&buf);
                    }

                    /*Initial message to set pitch position*/
                    if(ubPitchEepromAnswerReceive == 0x55)
                    {
                        fEepromPitchInit = ReadPitchEeprom();
                        chinookpack_pack_float(&pk,fEepromPitchInit);
                        Set_Timeout();
                        send_CAN_msg(&sCanMsgEepromPitchSend,bTxCanBuffer, 5);
                        while(!is_CAN_msg_send(&sCanMsgEepromPitchSend) && !sSystemFlags.CanTimeout);
                        Reset_Timeout();
                        chinookpack_fbuffer_clear(&buf);
                    }

                    chinookpack_pack_float(&pk,sSensorValues.fTurbineRPM);
                    Set_Timeout();
                    send_CAN_msg(&sCanMsgTurbineRPM,bTxCanBuffer, 5);
                    while(!is_CAN_msg_send(&sCanMsgTurbineRPM) && !sSystemFlags.CanTimeout);
                    Reset_Timeout();
                    chinookpack_fbuffer_clear(&buf);

                    /*
                    chinookpack_pack_float(&pk,sSensorValues.sAccelerometer0.fGx);
                    Set_Timeout();
                    send_CAN_msg(&sCanMsgAccelerometer,bTxCanBuffer, 5);
                    while(!is_CAN_msg_send(&sCanMsgAccelerometer) && !sSystemFlags.CanTimeout);
                    Reset_Timeout();
                    chinookpack_fbuffer_clear(&buf);
                    */

                    /*EEPROM gear and turbine position*/
                    if(ubEepromAnswerReceiveMem != ubGearCanReceive)
                    {
                        ubEepromAnswerReceiveMem = ubGearCanReceive;
                        WriteGearEeprom(ubGearCanReceive);
                        WriteTurbineDirEeprom(fTubineDirectionReceive);
                    }
                    /*EEPROM pitch position*/
                    if(fLastCanPitchPercent != fCanPitchPercent)
                    {
                        fLastCanPitchPercent = fCanPitchPercent;
                        WritePitchEeprom(fLastCanPitchPercent);
                    }

                    chinookpack_pack_float(&pk,sSensorValues.fWheelRPM);
                    Set_Timeout();
                    send_CAN_msg(&sCanMsgWheelRPM,bTxCanBuffer, 5);
                    while(!is_CAN_msg_send(&sCanMsgWheelRPM) && !sSystemFlags.CanTimeout);
                    Reset_Timeout();
                    chinookpack_fbuffer_clear(&buf);

                    chinookpack_pack_float(&pk,sSensorValues.fWindSpeed);
                    Set_Timeout();
                    send_CAN_msg(&sCanMsgWindSpeed,bTxCanBuffer, 5);
                    while(!is_CAN_msg_send(&sCanMsgWindSpeed) && !sSystemFlags.CanTimeout);
                    Reset_Timeout();
                    chinookpack_fbuffer_clear(&buf);

                    chinookpack_pack_float(&pk,sSensorValues.fWindDir);
                    Set_Timeout();
                    send_CAN_msg(&sCanMsgWindDirection,bTxCanBuffer, 5);
                    while(!is_CAN_msg_send(&sCanMsgWindDirection) && !sSystemFlags.CanTimeout);
                    Reset_Timeout();
                    chinookpack_fbuffer_clear(&buf);

                    chinookpack_pack_float(&pk,sSensorValues.fTrust);
                    Set_Timeout();
                    send_CAN_msg(&sCanMsgTrust,bTxCanBuffer, 5);
                    while(!is_CAN_msg_send(&sCanMsgTrust) && !sSystemFlags.CanTimeout);
                    Reset_Timeout();
                    chinookpack_fbuffer_clear(&buf);

                    print = 0;
		}

                /*Error processing*/
                if(sSystemFlags.CanError)
                {
                    LED_STAT0 = 1;
                }
	}
	return 0;
}
Esempio n. 3
0
void reset(ROM_MODE mode)
{
   comp.pEFF7 &= conf.EFF7_mask;
   comp.pEFF7 |= EFF7_GIGASCREEN; // [vv] disable turbo
   {
        conf.frame = frametime;
        cpu.SetTpi(conf.frame);
//                if ((conf.mem_model == MM_PENTAGON)&&(comp.pEFF7 & EFF7_GIGASCREEN))conf.frame = 71680; //removed 0.37
        apply_sound();
   } //Alone Coder 0.36.4
   comp.t_states = 0; comp.frame_counter = 0;
   comp.p7FFD = comp.pDFFD = comp.pFDFD = comp.p1FFD = 0;
   comp.p7EFD = comp.p78FD = comp.p7AFD = comp.p7CFD = comp.gmx_config = comp.gmx_magic_shift = 0;
   comp.pLSY256 = 0;

   comp.ulaplus_mode=0;
   comp.ulaplus_reg=0;

   tsinit();

   if (conf.mem_model == MM_TSL)
		set_clk();		// turbo 2x (7MHz) for TS-Conf
   else
		turbo(1);		// turbo 1x (3.5MHz) for all other clones
        
   if (conf.mem_model == MM_LSY256)
        mode = RM_SYS;
   
   switch (mode)
   {
	case RM_SYS: {comp.ts.memconf = 4; break;}
	case RM_DOS: {comp.ts.memconf = 0; break;}
	case RM_128: {comp.ts.memconf = 0; break;}
	case RM_SOS: {comp.ts.memconf = 0; break;}
   }

   comp.p00 = comp.p80FD = 0; 	// quorum

   comp.pBF = 0; // ATM3
   comp.pBE = 0; // ATM3

   if (conf.mem_model == MM_ATM710 || conf.mem_model == MM_ATM3)
   {
       switch(mode)
       {
       case RM_DOS:
           // Запрет палитры, запрет cpm, включение диспетчера памяти
           // Включение механической клавиатуры, разрешение кадровых прерываний
           set_atm_FF77(0x4000 | 0x200 | 0x100, 0x80 | 0x40 | 0x20 | 3);
           comp.pFFF7[0] = 0x100 | 1; // trdos
           comp.pFFF7[1] = 0x200 | 5; // ram 5
           comp.pFFF7[2] = 0x200 | 2; // ram 2
           comp.pFFF7[3] = 0x200;     // ram 0

           comp.pFFF7[4] = 0x100 | 1; // trdos
           comp.pFFF7[5] = 0x200 | 5; // ram 5
           comp.pFFF7[6] = 0x200 | 2; // ram 2
           comp.pFFF7[7] = 0x200;     // ram 0
       break;
       default:
           set_atm_FF77(0,0);
       }
   }

   if (conf.mem_model == MM_ATM450)
   {
       switch(mode)
       {
       case RM_DOS:
           set_atm_aFE(0x80|0x60);
           comp.aFB = 0;
       break;
       default:
           set_atm_aFE(0x80);
           comp.aFB = 0x80;
       }
   }

   comp.flags = 0;
   comp.active_ay = 0;

   cpu.reset();
   reset_tape();
   reset_sound();

   #ifdef MOD_VID_VD
   comp.vdbase = 0; comp.pVD = 0;
   #endif

   load_spec_colors();

   comp.ide_hi_byte_r = 0;
   comp.ide_hi_byte_w = 0;
   comp.ide_hi_byte_w1 = 0;
   hdd.reset();
   input.atm51.reset();
   input.buffer.Enable(false);

   if ((!conf.trdos_present && mode == RM_DOS) ||
       (!conf.cache && mode == RM_CACHE))
       mode = RM_SOS;

   set_mode(mode);
}
Esempio n. 4
0
/******************************************************************
                                Main
******************************************************************/
int main(void)
{
        /*Disable watchdog*/
        RCONbits.SWDTEN = 0;
        
	set_clk();

	InitIO();

        //Initialize CAN communication
        initialisation_CAN();
        
	//Initialize PWM (Motor Control)
        Init_PWM();

	//Initialize ADC
	//Init_ADC();
	
	//Initialize QEI (Speed/Position DC motor)
	InitQEI();
        chinookpack_unpacked_init(&unpacker);

        #ifdef memory_init
        /*Retrieve Last gear and mât position*/
        do{
            EEPROM_REQUEST = 0x55;
            envoi_CAN_periodique_init();
            last_gear = datReceive_can_EEPROM_CONFIG_ANSWER_gear;
            last_position_mat = datReceive_can_EEPROM_CONFIG_ANSWER_mat;
        }while(datReceive_can_EEPROM_CONFIG_ANSWER_mat==190.0f);
        gear = last_gear;
        Position_mat = last_position_mat;
        char print[80];
        sprintf(print,"last gear: %d \t last position mat : %f \r",last_gear,last_position_mat);
        char u=0;
        do
        {
                U1TXREG=print[u];

                while(U1STAbits.TRMT!=1);
                u++;

        }while(print[u]!=0);
        int k=0;
        do{
            EEPROM_REQUEST = 0xAA;
            envoi_CAN_periodique_init();
            k++;
        }while(k<5);
        #endif
        
        /*Enable 24V supply switch*/
        ENALIM = 1;
                                                                                                                    //envoi_CAN_periodique();
        //envoi_CAN_periodique();
        //Transmission goes to first gear

        Stepper_Shift_Init(last_gear);
        //Mat goes to origin
        //Init_mat(last_position_mat);

	while(1)
	{

            //Transmission goes to first gear
            if(datReceive_can_conf)
                Stepper_Shift_Init(last_gear);

            Stepper_Shift();

            envoi_CAN_periodique();
            
            #ifdef mat_manuel
            if(!datReceive_can_cmd[0])
            {
                if(last_cmd_mat == 14 || last_cmd_mat == 15){
                    cmd_mat=datReceive_can_cmd[3]|datReceive_can_cmd[2]|datReceive_can_cmd[1]|datReceive_can_cmd[0];
                }
                if(last_cmd_mat == 11){
                    delai_mat++;
                    cmd_mat = 0;
                    if(delai_mat<60000)
                        tower_motor_ctrl(&PDC1,Position_mat);
                    else if(delai_mat>=60000)
                        delai_mat = 0;
                    
                }
            }
            else if(!datReceive_can_cmd[2])
            {
                if(last_cmd_mat == 11  || last_cmd_mat == 15){
                    cmd_mat=datReceive_can_cmd[3]|datReceive_can_cmd[2]|datReceive_can_cmd[1]|datReceive_can_cmd[0];
                }
                if(last_cmd_mat == 14){
                    cmd_mat = 0;
                    delai_mat++;
                    if(delai_mat<60000)
                        tower_motor_ctrl(&PDC1,Position_mat);
                    else if(delai_mat>=60000)
                        delai_mat = 0;

                }
            }
            else //if(datReceive_can_cmd == 15)
            {
                cmd_mat=15;
            }
            if(cmd_mat ==14)
            {
                last_cmd_mat = cmd_mat;
                LED0^=1;
                tower_motor_ctrl(&PDC1,-180.0f);
            }
            else if(cmd_mat == 11)
            {
                last_cmd_mat = cmd_mat;
                tower_motor_ctrl(&PDC1,180.0f);
            }
            else if(cmd_mat == 15)
            {
                last_cmd_mat = cmd_mat;
                tower_motor_ctrl(&PDC1,Position_mat);
            }
            #endif
            #ifdef mat_test
            tower_motor_ctrl(&PDC1,-90.0f);
            #endif
            #ifdef mat_auto
            tower_motor_ctrl(&PDC1,datReceive_can_wind_direction);
            #endif
            
            
	}
}