Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

user_application.c

Go to the documentation of this file.
00001 /*C************************************************************************** 00002 * NAME: userapp.c 00003 *---------------------------------------------------------------------------- 00004 * Copyright (c) 2003 Atmel. 00005 *---------------------------------------------------------------------------- 00006 * RELEASE: 00007 * REVISION: 00008 *---------------------------------------------------------------------------- 00009 * PURPOSE: 00010 * This file contains the user application. 00011 *****************************************************************************/ 00012 /*_____ I N C L U D E S ____________________________________________________*/ 00013 #include "config.h" 00014 #include "user_application.h" 00015 #include "\conf\board.h" 00016 #include "modules\usb\usb_task.h" 00017 #include "lib_mcu\usb\usb_drv.h" 00018 #include "modules\usb_hid_generic_api\usb_hid_generic_api.h" 00019 /*_____ M A C R O S ________________________________________________________*/ 00020 /*_____ D E F I N I T I O N ________________________________________________*/ 00021 U8 data_received[LENGTH_OF_REPORT]; 00022 U8 data_to_send[LENGTH_OF_REPORT]; 00023 U8 state = 0; 00024 extern U8 send_free; 00025 extern U8 Continuous_Mode; 00026 extern Union16 idata scan_key; 00027 extern U8 key_hit; 00028 U8 transmit_no_key; 00029 extern U8 usb_configuration_nb; 00030 extern bit reset_to_bootloader; 00031 00032 bit last_INT0_button_state = 1; 00033 00034 00035 /*_____ D E C L A R A T I O N ______________________________________________*/ 00036 /*F************************************************************************** 00037 * NAME: userapp_task_init 00038 *---------------------------------------------------------------------------- 00039 * PARAMS: 00040 * delay: none 00041 * return: none 00042 *---------------------------------------------------------------------------- 00043 * PURPOSE: 00044 * This function initializes the user parameters and the associated variables. 00045 *---------------------------------------------------------------------------- 00046 * EXAMPLE: 00047 *---------------------------------------------------------------------------- 00048 * NOTE: 00049 *---------------------------------------------------------------------------- 00050 * REQUIREMENTS: 00051 *****************************************************************************/ 00052 void user_application_task_init(void) 00053 { 00054 U8 c; 00055 Configure_led(0,LED_PORT_10MA); 00056 Configure_led(1,LED_PORT_10MA); 00057 Configure_led(2,LED_PORT_10MA); 00058 Configure_led(3,LED_PORT_10MA); 00059 Led_all_off(); 00060 for (c=0; c< LENGTH_OF_REPORT; c++) 00061 { 00062 data_to_send[c] = 0; 00063 } 00064 } 00065 /*F************************************************************************** 00066 * NAME: user_application_task 00067 *---------------------------------------------------------------------------- 00068 * PARAMS: 00069 * delay: none 00070 * return: none 00071 *---------------------------------------------------------------------------- 00072 * PURPOSE: 00073 * This function receives data via USB. 00074 *---------------------------------------------------------------------------- 00075 * EXAMPLE: 00076 *---------------------------------------------------------------------------- 00077 * NOTE: 00078 *---------------------------------------------------------------------------- 00079 * REQUIREMENTS: 00080 *****************************************************************************/ 00081 void user_application_task (void) 00082 { 00083 if(Is_new_data_read()) 00084 { 00085 usb_read_continuous(data_received); 00086 00087 if((data_received[0]=='1')&&(data_received[1]=='1')) 00088 Led_0_on(); 00089 00090 if((data_received[0]=='0')&&(data_received[1]=='1')) 00091 Led_0_off(); 00092 00093 if((data_received[0]=='1')&&(data_received[1]=='2')) 00094 Led_1_on(); 00095 00096 if((data_received[0]=='0')&&(data_received[1]=='2')) 00097 Led_1_off(); 00098 00099 if((data_received[0]=='1')&&(data_received[1]=='3')) 00100 Led_2_on(); 00101 00102 if((data_received[0]=='0')&&(data_received[1]=='3')) 00103 Led_2_off(); 00104 00105 if((data_received[0]=='1')&&(data_received[1]=='4')) 00106 Led_3_on(); 00107 00108 if((data_received[0]=='0')&&(data_received[1]=='4')) 00109 Led_3_off(); 00110 } 00111 00112 00113 00114 if (INT0_button != last_INT0_button_state) // INT0 button pressed 00115 { 00116 if (Is_write_data_ready()) 00117 { 00118 data_to_send[0] = !INT0_button; 00119 usb_write_continuous(data_to_send, 1); 00120 last_INT0_button_state = INT0_button; 00121 } 00122 } 00123 00124 00125 if (reset_to_bootloader == TRUE) 00126 { 00127 Usb_detach(); 00128 Led_all_off(); 00129 Enable_ale(); 00130 Configure_led(0,STANDARD_PORT); 00131 Configure_led(1,STANDARD_PORT); 00132 Configure_led(2,STANDARD_PORT); 00133 Configure_led(3,STANDARD_PORT); 00134 for (data_received[0]=0; data_received[0]<250; data_received[0]++); 00135 Usb_disable(); 00136 Pll_stop(); 00137 EA = 0; 00138 MAP_BOOT; 00139 __API_JMP_BOOTLOADER(); 00140 } 00141 } 00142

Generated on Mon Apr 10 17:23:30 2006 for Atmel by doxygen 1.3.7