C51 COMPILER V7.05 STATUSLOOP 03/09/2005 12:06:59 PAGE 1 C51 COMPILER V7.05, COMPILATION OF MODULE STATUSLOOP OBJECT MODULE PLACED IN statusloop.OBJ COMPILER INVOKED BY: C:\Disk2\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe statusloop.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 11 // Command codes. 12 // NB: The same codes are used between USB host and MCU and between SPISlave and MCU 13 14 enum { 15 Data = 0x1, 16 DataAcknowledge = 0x2, 17 Status = 0x3, 18 StatusRequest = 0x4, 19 FlushRequest = 0x5, 20 PacketRequest = 0x6, 21 GenerateLHCbEvent = 0x7, 22 P12Write = 0x8, 23 P12Read = 0x9, 24 GenerateALICEEvent = 0xa, 25 ResetRequest = 0xb, 26 ConfigurationData = 0xc, 27 Idle = 0xa5, 28 Idle2 = 0x25 29 }; 30 31 typedef struct devicePacket_t 32 { 33 unsigned char cmd; 34 unsigned char dummy; 35 unsigned short length; 36 unsigned char cdata[64]; 37 } devicePacket_t; 38 39 //----------------------------------------------------------------------------- 40 // Global CONSTANTS 41 //----------------------------------------------------------------------------- 42 43 sbit Led1 = P2^2; // LED='1' means OFF 44 sbit Led2 = P2^3; 45 sbit SPISlaveResetIn_b = P0^3; // ='1' when slave is ready 46 sbit SPISlaveResetOut = P0^6; // Assert to reset slave 47 48 unsigned short nByte; 49 devicePacket_t packet; 50 51 void SPI0_Init(void); 52 53 //----------------------------------------------------------------------------- 54 // Main Routine 55 //----------------------------------------------------------------------------- C51 COMPILER V7.05 STATUSLOOP 03/09/2005 12:06:59 PAGE 2 56 void main(void) 57 { 58 1 unsigned short status_cnt; 59 1 unsigned rc; 60 1 BYTE sdata; 61 1 62 1 PCA0MD &= ~0x40; // Disable Watchdog timer 63 1 64 1 65 1 OSCICN |= 0x3; // System clock divide. Set for fastest system clock speed. 66 1 67 1 SPI0_Init(); 68 1 69 1 IT01CF = 0x0c; // P0.4 INT0, active high 70 1 IT0 = 0; 71 1 // INT0 type: 0=level 1=edge sensitive 72 1 P0MDIN = 0xFF; // P0.0-7 set digital input 73 1 P0MDOUT = 0x45; // P0.0,2,6 set push-pull (SCK,MOSI,ResetOut) 74 1 P0 = ~0x45; // Open-drain outputs set high impedance 75 1 P1MDIN = 0xFF; // P1.0-7 set digital input 76 1 P1MDOUT = 0xFF; // P1.0-7 set push-pull 77 1 P1 = 0x00; // P1.0-7 set low 78 1 P2MDIN = 0xFF; // P2.0-7 set digital input 79 1 P2MDOUT = 0x0C; // P2.2,3 set push-pull (LEDs) 80 1 P2 = ~0x0C; // Open-drain outputs set high impedance 81 1 82 1 XBR0 = 0x02; // Enable SPI IO 83 1 XBR1 = 0x40; // Enable Crossbar 84 1 85 1 Led1 = 1; 86 1 Led2 = 1; 87 1 SPISlaveResetOut = 0; 88 1 89 1 // Continuous transaction loop 90 1 91 1 while ( 1 ) 92 1 { 93 2 94 2 SPISlaveResetOut = 1; 95 2 while ( SPISlaveResetIn_b == 1 ) ; // Wait until the slave is reset 96 2 SPISlaveResetOut = 0; 97 2 while ( SPISlaveResetIn_b == 0 ) ; // Wait until the slave is ready 98 2 99 2 Led1 = 0; 100 2 101 2 while ( 1 ) 102 2 { 103 3 104 3 // Send status request 105 3 SPI0DAT = StatusRequest; while ( SPIF == 0 ); sdata = SPI0DAT; SPIF = 0; 106 3 107 3 // Two header words 108 3 while (sdata != Status ) 109 3 { 110 4 SPI0DAT = Idle; while ( SPIF == 0 ); sdata = SPI0DAT; SPIF = 0; 111 4 } 112 3 // SPI0DAT = Idle; while ( SPIF == 0 ); sdata = SPI0DAT; SPIF = 0; 113 3 114 3 // Data 115 3 116 3 for (status_cnt=0;status_cnt<16;status_cnt++) 117 3 { C51 COMPILER V7.05 STATUSLOOP 03/09/2005 12:06:59 PAGE 3 118 4 SPI0DAT = Idle; 119 4 while ( SPIF == 0 ); // Wait for status byte 120 4 packet.cdata[status_cnt+4] = SPI0DAT; // Read the byte from slave 121 4 SPIF = 0; 122 4 } 123 3 124 3 P1 = packet.cdata[19]; 125 3 if (packet.cdata[19] != 0xde ) Led2 = 0; 126 3 if (packet.cdata[18] != 0xad ) Led2 = 0; 127 3 if (packet.cdata[17] != 0xfa ) Led2 = 0; 128 3 if (packet.cdata[16] != 0xce ) Led2 = 0; 129 3 130 3 } 131 2 } 132 1 133 1 } *** WARNING C280 IN LINE 59 OF STATUSLOOP.C: 'rc': unreferenced local variable 134 135 // SPI0_Init 136 137 void SPI0_Init(void) 138 { 139 1 SPI0CFG = 0x40; // MSTEN=1, CKPHA=0, CKPOL=0 140 1 SPI0CKR = 0x1; // SPI clock rate 141 1 ESPI0 = 0; // Disable SPI0 interrupt (we do not use it) 142 1 SPI0CN = 0x1; // Enable 143 1 } 144 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 167 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 70 2 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)