void send_data_CAN(void)
{
    // --- Init Reply data
    sensor_message.pt_data = &sensor_buffer[0];

    while(1)
    {   
        
		sensor_buffer[0] = (U8)(dummy_counter);
        sensor_buffer[1] = (U8)(dummy_counter+10);
        sensor_buffer[2] = (U8)(dummy_counter+20);
        sensor_buffer[3] = (U8)(dummy_counter+30);
		sensor_buffer[4] = (U8)(dummy_counter+40);
		sensor_buffer[5] = (U8)(dummy_counter+50);
		sensor_buffer[6] = (U8)(dummy_counter+60);
		sensor_buffer[7] = (U8)(convertanalog(1));
		
        // --- Auto-reply Command
        sensor_message.ctrl.ide = 0;            //- CAN 2.0A
        sensor_message.dlc = 8;                 //- Message with x-byte data
        sensor_message.id.std = MY_ID_TAG;
        sensor_message.cmd = CMD_RX;

        // --- Enable reply
        while(can_cmd(&sensor_message) != CAN_CMD_ACCEPTED);
        // --- Wait for Reply completed
        while(can_get_status(&sensor_message) == CAN_STATUS_NOT_COMPLETED);

        PORTA ^=_BV(PORTA7);
		
		dummy_counter++;
        
    }
}
Ejemplo n.º 2
0
int main(void)
{
        unsigned char lc=0; // loop counter
        unsigned int voltage=0;
        unsigned int adc=0;
        init7segment();

        while (1) {
                lc++;
                // 
                if (lc==1){
                        // once in a while:
                        adc=analog2v(convertanalog(0));
                        // build an average unless too far away.
                        // This is to update the display fast but not
                        // to toggle all the time:
                        if (adc > voltage && adc -voltage > 20){
                                voltage=adc + adc;
                        }else if (adc < voltage && voltage -adc > 20){
                                voltage=adc + adc;
                        }else{
                                // just build average (avoid toggle):
                                voltage=voltage + adc;
                        }
                        voltage=voltage/2;
                        #if (DP_DIG == 1)    // by RWCooper 2007/11/25
                          voltage = (voltage + 5) / 10;
                        #endif
                }
                // step loop counter up to 0x1f (=00011111, we can use binary AND):
                lc=lc& 0x1f;
                upd7segment(voltage);
        }
        return(0);
}