C51 COMPILER V6.00 BUTTON 05/31/2000 19:32:58 PAGE 1 C51 COMPILER 6.00, COMPILATION OF MODULE BUTTON OBJECT MODULE PLACED IN .\button.OBJ COMPILER INVOKED BY: d:\keileval\C51\BIN\C51.EXE .\button.c OBJECTEXTEND DEBUG stmt level source 1 #include "xbus.h" 2 #include 3 #include 4 5 // constant 6 unsigned long bits_32; 7 unsigned int bits_16; 8 9 // send data 10 unsigned long send1; 11 unsigned int send2; 12 13 int counter; // using for testing only -- timer 1 14 int temp; // time out between packets 15 char i; // bit count 16 bit rise_edge; // rise_edge -- trigger new bit sending 17 18 //sbit clk = P1 ^ 1; // pin 8 19 //sbit data_out = P1 ^ 2; // pin 9 20 21 sbit clk = P3 ^ 4; // pin 68 22 sbit data_out = P3 ^ 1; // pin 69 23 24 //sbit mouse_click = P3 ^ 3; //external interrupt 1 //pin 15 (not connected to FPGA) 25 26 // --- shared variables 27 bit Done; // send back to tell it's ok to put new data in 28 bit En; // enable new sending 29 //--------------- Anita's code 30 int Diamond; 31 32 unsigned char CameraX; //Bright Pixel Row data from Camera 33 unsigned char CameraY; //Bright Pixel Column data from Camera 34 unsigned char Status; 35 36 unsigned char NewX; //New Bright Pixel Row in Monitor pixels 37 unsigned char NewY; //New Bright Pixel Column in Monitor pixels 38 39 unsigned char OldX; //Last Bright Pixel Row in Monitor pixels 40 unsigned char OldY; //Last Bright Pixel Column in Monitor pixels 41 42 unsigned int StatusAddress; //Address of Status register in FPGA 43 unsigned int RowAddress; //Address of Row Data Register in FPGA 44 unsigned int ColumnAddress; //Address of Column Data Register in FPGA 45 46 //Data before sign change 47 int PreXData; 48 int PreYData; 49 50 51 //Data to PS/2 52 char x,y; // XData,YData 53 char sign; // Sign 54 // --------------------------- 55 C51 COMPILER V6.00 BUTTON 05/31/2000 19:32:58 PAGE 2 56 57 58 // -------------- clock input into PS/2 mouse port 59 void generate_clk (void) interrupt 1 using 1 { // timer 0 60 1 temp++; 61 1 if (temp < 22) clk = ~clk; 62 1 if (clk) rise_edge = 1; 63 1 if (temp == 22) { 64 2 clk = 0; 65 2 rise_edge = 0; 66 2 } 67 1 else if (temp == 26) { 68 2 temp = 0; 69 2 clk = 1; 70 2 rise_edge = 1; 71 2 } 72 1 } 73 74 //------------------------- for testing only 75 void Newframe ( void ) interrupt 3 using 2 { 76 1 if (counter++ == 32000) { 77 2 counter = 0; 78 2 Done = 1; // ready to get new data in 79 2 ET1 = 0; 80 2 } 81 1 } 82 83 // load new_frame 84 void new_load(void) { 85 1 86 1 char j; 87 1 unsigned int temp_x,temp_y; 88 1 char my_x,my_y; 89 1 bit Yparity,Xparity; 90 1 unsigned long temp1; 91 1 Yparity = Xparity = 1; 92 1 temp1 = 0; 93 1 temp_x = temp_y = my_x = my_y = 0; 94 1 95 1 switch(sign) { 96 2 case 1: // Up - right 97 2 my_x = x; 98 2 my_y = y; 99 2 bits_32 = 0x00200410; 100 2 break; 101 2 case 2: // Down - right 102 2 my_x = x; 103 2 my_y = 0 - y; 104 2 bits_32 = 0x00200650; 105 2 break; 106 2 case 3: // Down - left 107 2 my_x = 0 - x; 108 2 my_y = 0 - y; 109 2 bits_32 = 0x00200470; 110 2 break; 111 2 case 4: // Up - left 112 2 my_x = 0 - x; 113 2 my_y = y; 114 2 bits_32 = 0x00200630; 115 2 break; 116 2 } 117 1 // temp_x = my_x & 0x00FF doesn't work -- need to break down like below C51 COMPILER V6.00 BUTTON 05/31/2000 19:32:58 PAGE 3 118 1 temp_x = my_x; 119 1 temp_y = my_y; 120 1 temp_x = temp_x & 0x00FF; 121 1 temp_y = temp_y & 0x00FF; 122 1 123 1 for (j = 0; j < 8; j++) { 124 2 Xparity = Xparity ^ (my_x & 0x01); 125 2 Yparity = Yparity ^ (my_y & 0x01); 126 2 my_x = my_x >> 1; 127 2 my_y = my_y >> 1; 128 2 } 129 1 // encode the packets 130 1 temp1 = ((temp1 | Yparity) << 8) | temp_y; // take cares parity & y 131 1 temp1 = ((((temp1 << 3) | Xparity) << 8) | temp_x ) << 12; 132 1 send1 = bits_32 | temp1; 133 1 send2 = bits_16; 134 1 } 135 136 void init () { 137 1 138 1 TMOD = 0x22; 139 1 TCON = 0x50; 140 1 TH0 = 169; 141 1 TH1 = 6; 142 1 data_out = 1; 143 1 rise_edge = 0; 144 1 clk = 1; 145 1 En = 1; 146 1 EA = 1; 147 1 148 1 counter = 0; // for timer 1 149 1 i = 0; // sending counter 150 1 temp = -1; 151 1 bits_16 = 0x0C01; // 12 bit 2nd packet 152 1 153 1 // ----- Anita's code 154 1 Done = 1; 155 1 sign = 0; 156 1 Diamond = 1; 157 1 En = 0; 158 1 159 1 StatusAddress = 2; //Address of Status Register in FPGA 160 1 RowAddress = 0; //Address of Row Data Register in FPGA 161 1 ColumnAddress = 1; //Address of Column Data Register in FPGA 162 1 163 1 ALE = 0; 164 1 165 1 // ------------------------ 166 1 } 167 168 // Anita's code 169 char FindSign ( int X, int Y ) 170 { 171 1 char tempSign; 172 1 tempSign = 0; 173 1 174 1 if (X > 0 && Y > 0 ) // X > 0 and Y > 0 //abs(X) == X && abs(Y) == Y 175 1 tempSign = 1; // Quadrant 1 176 1 177 1 else if (X < 0 && Y > 0) // Quadrant 4 178 1 tempSign = 4; 179 1 C51 COMPILER V6.00 BUTTON 05/31/2000 19:32:58 PAGE 4 180 1 else if (X < 0 && Y < 0) // Quadrant 3 181 1 tempSign = 3; 182 1 183 1 else if (X > 0 && Y < 0) // Quadrant 2 184 1 tempSign = 2; 185 1 186 1 else // ERROR CONDITION!! 187 1 tempSign = 0; 188 1 189 1 return (tempSign); 190 1 } 191 // ------------------------------------ 192 193 void main() { 194 1 195 1 init(); 196 1 while (1) { // all programs run foreve 197 2 198 2 //----------- Anita's code 199 2 Status = XRead(StatusAddress); //Read data from FPGA at Address 2 200 2 //********* DEBUG *************** 201 2 202 2 // Status = 1; 203 2 204 2 if (Status == 1) //There is data for me to read from FPGA 205 2 { 206 3 CameraX = XRead(RowAddress); //Read data from the FPGA at Address 0 207 3 CameraY = XRead(ColumnAddress); //Read data from the FPGA at Address 1 208 3 209 3 //******** DEBUG *************** 210 3 // CameraX = 100; 211 3 // CameraY = 100; 212 3 213 3 214 3 215 3 216 3 //insert function to translate between pixels 217 3 // ********** FOR TESTING PURPOSES ********************* 218 3 // Monitor Resolution: 1280 X 1024 Camera Resolution: 256 X 256 219 3 // Ratio: 6 X 5 220 3 221 3 NewX = CameraX * 6; 222 3 NewY = CameraY * 5; 223 3 224 3 //insert function to determine relative movement 225 3 226 3 PreXData = OldX - NewX; // Relative movement 227 3 PreYData = OldY - NewY; 228 3 229 3 OldX = NewX; // Keep the current data as 'old' data 230 3 OldY = NewY; 231 3 232 3 233 3 234 3 235 3 if (Done && !En) // I can put new data in the variables to send to the PS/2 port 236 3 { 237 4 /* switch(Diamond) 238 4 { 239 4 case 1: 240 4 Done = 0; // reset done 241 4 PreXData = 150; C51 COMPILER V6.00 BUTTON 05/31/2000 19:32:58 PAGE 5 242 4 PreYData = 150; 243 4 Diamond = 2; 244 4 break; 245 4 case 2: 246 4 Done = 0; // reset done 247 4 PreXData = 150; 248 4 PreYData = -150; 249 4 Diamond = 3; 250 4 break; 251 4 case 3: 252 4 Done = 0; // reset done 253 4 PreXData = -150; 254 4 PreYData = -150; 255 4 Diamond = 4; 256 4 break; 257 4 case 4: 258 4 Done = 0; // reset done 259 4 PreXData = -150; 260 4 PreYData = 150; 261 4 Diamond = 1; 262 4 break; 263 4 } */ 264 4 265 4 x = abs(PreXData); 266 4 y = abs(PreYData); 267 4 sign = FindSign(PreXData, PreYData); 268 4 En = 1; // Set En high to let PS/2 port know that we have data in the variables 269 4 270 4 } 271 3 272 3 } 273 2 // ----------------------------------------------------------------------- 274 2 if (En) { // if something to send 275 3 new_load(); 276 3 En = 0; // reset it 277 3 data_out = 0; // 1st bit - force to low to start transmitt data 278 3 send1 = send1 >> 1; 279 3 i++; 280 3 ET0 = 1; // make sure that the clock egde go down after data_out = first bit of sending data. 281 3 } 282 2 if (( i < 32) && rise_edge) { // 32 bit of data 283 3 data_out = send1 & 0x00000001; 284 3 rise_edge = 0; 285 3 send1 = send1 >> 1; 286 3 i++; 287 3 } 288 2 else if (( 31 < i) && (i < 43) && rise_edge) { // 12 bit of data - total is 44 bit of data 289 3 data_out = send2 & 0x00000001; 290 3 rise_edge = 0; 291 3 send2 = send2 >> 1; 292 3 i++; 293 3 } 294 2 else if ((temp == 0) && (i == 43)) { 295 3 ET0 = 0; 296 3 temp = -1; 297 3 data_out = 1; 298 3 rise_edge = 0; 299 3 i = 0; 300 3 clk = 1; 301 3 ET1 = 1; 302 3 } 303 2 } C51 COMPILER V6.00 BUTTON 05/31/2000 19:32:58 PAGE 6 304 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 901 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = 39 8 IDATA SIZE = ---- ---- BIT SIZE = 3 2 END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)