C51 COMPILER V7.05 BOUNCE 03/21/2005 09:16:35 PAGE 1 C51 COMPILER V7.05, COMPILATION OF MODULE BOUNCE OBJECT MODULE PLACED IN bounce.OBJ COMPILER INVOKED BY: C:\Disk2\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe bounce.c DB OE stmt level source 1 //----------------------------------------------------------------------------- 2 // bounce.c 3 //----------------------------------------------------------------------------- 4 //----------------------------------------------------------------------------- 5 // Includes 6 //----------------------------------------------------------------------------- 7 #include 8 #include 9 #include "USB_API.h" 10 #include "chimaera.h" 11 12 //----------------------------------------------------------------------------- 13 // Global CONSTANTS 14 //----------------------------------------------------------------------------- 15 16 sbit P20 = P2^0; 17 sbit P21 = P2^1; 18 sbit Led1 = P2^2; // LED='1' means OFF 19 sbit Led2 = P2^3; 20 21 code const BYTE VendorString[] = {0x2a,0x03,'C',0,'a',0,'v',0,'e',0,'n',0,'d',0,'i',0,'s',0,'h',0,' ',0,'L -',0,'a',0,'b',0,'.',0,' ',0,'(',0,'H',0,'E',0,'P',0,')',0}; 22 code const BYTE ProductString[] = {0xe,0x03,'C',0,'B',0,' ',0,'U',0,'S',0,'B',0}; 23 code const BYTE Serial[] = {0x0A,0x03,'0',0,'0',0,'0',0,'1',0}; 24 code const BYTE MaxPower = 15; // Max current = 16 mA (8 * 2) 25 code const BYTE PwAttributes = 0x80; // Self-powered, remote wakeup not supported 26 code const UINT bcdDevice = 0x100; // Device release number 1.00 27 code const BYTE TEMP_ADD = 112; // This constant is added to Temperature 28 29 unsigned short nByte; 30 devicePacket_t packet; 31 devicePacketISR_t packet_isr; 32 unsigned rxInterrupt = 0; 33 unsigned txInterrupt = 0; 34 unsigned waitUSB = 1; 35 unsigned short cnt = 0; 36 37 //----------------------------------------------------------------------------- 38 // Main Routine 39 //----------------------------------------------------------------------------- 40 void main(void) 41 { 42 1 unsigned rc; 43 1 unsigned char packetsRemaining; 44 1 unsigned char packetPending = 0; 45 1 unsigned char seq = 0; 46 1 unsigned char txSlots = 2; 47 1 48 1 PCA0MD &= ~0x40; // Disable Watchdog timer 49 1 50 1 51 1 USB_Init(0xCBCB,0x0001,VendorString,ProductString,Serial,MaxPower,PwAttributes,bcdDevice); 52 1 OSCICN |= 0x3; // System clock divide. Set for fastest system clock speed. 53 1 Initialize(); 54 1 USB_Int_Enable(); C51 COMPILER V7.05 BOUNCE 03/21/2005 09:16:35 PAGE 2 55 1 56 1 P0MDIN = 0xFF; // P2.0-7 set digital input 57 1 P0MDOUT = 0x00; // P2.2,3 set push-pull (LEDs) 58 1 P0 = ~0x00; // Open-drain outputs set high impedance 59 1 P1MDIN = 0xFF; // P2.0-7 set digital input 60 1 P1MDOUT = 0x00; // P2.2,3 set push-pull (LEDs) 61 1 P1 = ~0x00; // Open-drain outputs set high impedance 62 1 P2MDIN = 0xFF; // P2.0-7 set digital input 63 1 P2MDOUT = 0x0F; // P2.2,3 set push-pull (LEDs) 64 1 P2 = ~0x0F; // Open-drain outputs set high impedance 65 1 66 1 XBR1 = 0x40; // Enable Crossbar 67 1 68 1 // Wait for the USB to be ready 69 1 70 1 Led1 = 1; 71 1 Led2 = 1; 72 1 73 1 while ( waitUSB == 1 ) ; 74 1 75 1 Led1 = 0; 76 1 77 1 // Continuous transaction loop 78 1 79 1 while ( 1 ) 80 1 { 81 2 82 2 if ( txInterrupt == 1 ) 83 2 { 84 3 txInterrupt = 0; 85 3 txSlots++; 86 3 } 87 2 88 2 if ( (packetPending == 1) && (txSlots > 0) ) 89 2 { 90 3 txSlots--; 91 3 rc = Block_Write( (BYTE *)&packet, 68 ); 92 3 packetPending = 0; 93 3 } 94 2 95 2 if ( rxInterrupt == 1 ) 96 2 { 97 3 rxInterrupt = 0; 98 3 packetsRemaining = packet_isr.cdata[0]; 99 3 } 100 2 101 2 102 2 if ( (packetPending == 0) && (packetsRemaining > 0) ) 103 2 { 104 3 105 3 P20 = 1; 106 3 107 3 for ( nByte=0; nByte < 64; nByte++ ) 108 3 { 109 4 packet.cdata[nByte] = (nByte+seq)&0xff; 110 4 } 111 3 112 3 packet.cmd = Data; 113 3 packet.length.uc[0] = 64; 114 3 packet.length.uc[1] = 0; 115 3 116 3 P20 = 0; C51 COMPILER V7.05 BOUNCE 03/21/2005 09:16:35 PAGE 3 117 3 118 3 packetsRemaining--; 119 3 seq++; 120 3 121 3 packetPending = 1; 122 3 123 3 } 124 2 125 2 } 126 1 127 1 } 128 129 //----------------------------------------------------------------------------- 130 // Initialization Subroutines 131 //----------------------------------------------------------------------------- 132 133 void Initialize(void) 134 { 135 1 136 1 return; 137 1 } 138 139 //------------------------- 140 // Suspend_Device 141 //------------------------- 142 // Called when a DEV_SUSPEND interrupt is received. 143 // - Calls USB_Suspend() 144 // 145 void Suspend_Device(void) 146 { 147 1 // Don't disable peripherals. Device is self-powered. 148 1 149 1 USB_Suspend(); // Put the device in suspend state 150 1 } 151 152 153 // USB ISR 154 155 void USB_Device_ISR(void) interrupt 16 156 { 157 1 BYTE INTVAL = Get_Interrupt_Source(); 158 1 159 1 if (INTVAL & RX_COMPLETE) 160 1 { 161 2 Block_Read( (BYTE *)&packet_isr, 8 ); 162 2 switch ( packet_isr.cmd ) 163 2 { 164 3 case PacketRequest: // Request next data packet 165 3 rxInterrupt = 1; 166 3 break; 167 3 default: 168 3 break; 169 3 } 170 2 171 2 } 172 1 173 1 174 1 if (INTVAL & TX_COMPLETE) 175 1 { 176 2 txInterrupt = 1; 177 2 } 178 1 C51 COMPILER V7.05 BOUNCE 03/21/2005 09:16:35 PAGE 4 179 1 if (INTVAL & DEV_SUSPEND) 180 1 { 181 2 Suspend_Device(); 182 2 } 183 1 184 1 if (INTVAL & DEV_CONFIGURED) 185 1 { 186 2 waitUSB = 0; 187 2 } 188 1 189 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 391 ---- CONSTANT SIZE = 71 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 90 7 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)