//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
//-------------------------
// Initialize
//-------------------------
// Called when a DEV_CONFIGURED interrupt is received.
// - Enables all peripherals needed for the application
//
void Initialize(void)
{
Port_Init();
Timer_Init();
Adc_Init();
}
//-------------------------
// Timer2_ISR
//-------------------------
// Called when timer 2 overflows, check to see if switch is pressed,
// then watch for release.
//
INTERRUPT(Timer2_ISR, INTERRUPT_TIMER2)
{
if (!(P2 & Sw1)) // Check for switch #1 pressed
{
if (Toggle1 == 0) // Toggle is used to debounce switch
{ // so that one press and release will
Switch1State = ~Switch1State; // toggle the state of the switch sent
Toggle1 = 1; // to the host
}
}
else Toggle1 = 0; // Reset toggle variable
if (!(P2 & Sw2)) // This is the same as above, but for Switch2
{
if (Toggle2 == 0)
{
Switch2State = ~Switch2State;
Toggle2 = 1;
}
}
else Toggle2 = 0;
TF2H = 0; // Clear Timer2 interrupt flag
}
//-------------------------
// Adc_ConvComplete_ISR
//-------------------------
// Called after a conversion of the ADC has finished
// - Updates the appropriate variable for either potentiometer or temperature sensor
// - Switches the Adc multiplexor value to switch between the potentiometer and temp sensor
//
INTERRUPT(Adc_ConvComplete_ISR, INTERRUPT_ADC0_EOC)
{
//U32 flicker;
U8 ADC0_A;
U8 ADC0_N;
U8 flicker_a;
AD0INT = 0; // Clear ADC0 conv. complete flag
if (AMX0P == 0x02) // This switches the AMUX between
{
ADC0_A = ADC0;
Delay(200);
}
else
{
// Potentiometer = ADC0H;
AMX0P = 0x02; //1E; // switch to temperature sensor
ADC0CF = 0xF8; // place ADC0 in right-adjusted mode
}
AD0INT = 1;
Block_Write(In_Packet, 8);
}
// Example ISR for USB_API
INTERRUPT(USB_API_TEST_ISR, INTERRUPT_USBXpress)
{
U8 INTVAL = Get_Interrupt_Source(); //得到中斷類型
if (INTVAL & RX_COMPLETE) //數據發送完成
{
Block_Read(Out_Packet, 8);
}
if (INTVAL & DEV_SUSPEND) //設備掛起
{
Suspend_Device();
}
if (INTVAL & DEV_CONFIGURED) //設備初始化
{
Initialize();
}
}
void Delay(unsigned int x)
{
unsigned int a,b;
for(a=x;a>0;a--)
for(b=100;b>0;b--);
}
// Startup code for SDCC to disablt WDT before initializing variables so that
// a reset does not occur
#if defined SDCC
void _sdcc_external_startup (void)
{
PCA0MD &= ~0x40; // Disable Watchdog timer
}
#endif
// ============================================================================
// *** END OF FILE ***
// ============================================================================ 作者: mike 時間: 2012-8-29 14:15
小弟的版子沒有外掛osc當input, 那想在請教一下C8051F340的CLOCK要調多少才可以呢?要怎麼調呢?
還是很感謝板主的回覆。 作者: mike 時間: 2012-8-31 11:43
1. 你這份code是使用USBXPRESS 來完成的,
請參考 an169:USBXPRESS® PROGRAMMER’S GUIDE 中的 APPENDIX A — SFRS THAT SHOULD NOT BE MODIFIED AFTER CALLING USB_CLOCK_START AND USB_INIT.