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