📄 fm25h20.lst
字号:
278 //
279 //-----------------------------------------------------------------------------
280 /*void UART0_Init (void)
281 {
282 SCON0 = 0x10; // SCON0: 8-bit variable bit rate
283 // level of STOP bit is ignored
284 // RX enabled
285 // ninth bits are zeros
286 // clear RI0 and TI0 bits
287 if (SYSCLK/BAUDRATE/2/256 < 1)
288 {
289 TH1 = -(SYSCLK/BAUDRATE/2);
290 CKCON &= ~0x0B; // T1M = 1; SCA1:0 = xx
291 CKCON |= 0x08;
292 }
293 else if (SYSCLK/BAUDRATE/2/256 < 4)
294 {
295 TH1 = -(SYSCLK/BAUDRATE/2/4);
296 CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 01
297 CKCON |= 0x09;
298 }
299 else if (SYSCLK/BAUDRATE/2/256 < 12)
300 {
301 TH1 = -(SYSCLK/BAUDRATE/2/12);
302 CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 00
303 } else
C51 COMPILER V7.50 FM25H20 11/27/2008 11:07:27 PAGE 6
304 {
305 TH1 = -(SYSCLK/BAUDRATE/2/48);
306 CKCON &= ~0x0B; // T1M = 0; SCA1:0 = 10
307 CKCON |= 0x02;
308 }
309
310 TL1 = TH1; // init Timer1
311 TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
312 TMOD |= 0x20;
313 TR1 = 1; // START Timer1
314 TI0 = 1; // Indicate TX0 ready
315 }
316 */
317 //-----------------------------------------------------------------------------
318 // SPI0_Init
319 //-----------------------------------------------------------------------------
320 //
321 // Return Value : None
322 // Parameters : None
323 //
324 // Configures SPI0 to use 4-wire Single-Master mode. The SPI timing is
325 // configured for Mode 0,0 (data centered on first edge of clock phase and
326 // SCK line low in idle state). The SPI clock is set to 1.75 MHz. The NSS pin
327 // is set to 1.
328 //
329 //-----------------------------------------------------------------------------
330 void SPI0_Init()
331 {
332 1 SPI0CFG = 0x40;
333 1 SPI0CN = 0x0D;
334 1
335 1 // The equation for SPI0CKR is (SYSCLK/(2*F_SCK_MAX))-1, but this yields
336 1 // a SPI frequency that is slightly more than 2 MHz. But, 2 MHz is the max
337 1 // frequency spec of the EEPROM used here. So, the "-1" term is omitted
338 1 // in the following usage:
339 1 SPI0CKR = (SYSCLK/(2*F_SCK_MAX));
340 1 }
341
342 //-----------------------------------------------------------------------------
343 // Init_Device
344 //-----------------------------------------------------------------------------
345 //
346 // Return Value : None
347 // Parameters : None
348 //
349 // Calls all device initialization functions.
350 //
351 //-----------------------------------------------------------------------------
352 void Init_Device (void)
353 {
354 1 PCA0_Init ();
355 1 OSCILLATOR_Init ();
356 1 PORT_Init ();
357 1 TIMER2_Init ();
358 1 //UART0_Init ();
359 1 SPI0_Init ();
360 1 }
361
362
363 void Initiate()
364 {
365 1 PCA0MD &= ~0x40; // 看门狗被禁止
C51 COMPILER V7.50 FM25H20 11/27/2008 11:07:27 PAGE 7
366 1 CLKSEL=0X00;
367 1 OSCICN|=0x03;//内部时钟,24.5MHz
368 1 RSTSRC=0x04;// Enable missing clock detector
369 1 }
370 //-----------------------------------------------------------------------------
371 // Support Subroutines
372 //-----------------------------------------------------------------------------
373
374 //-----------------------------------------------------------------------------
375 // Delay_us
376 //-----------------------------------------------------------------------------
377 //
378 // Return Value : None
379 // Parameters : 1. time_us - time delay in microseconds
380 // range: 1 to 255
381 //
382 // Creates a delay for the specified time (in microseconds) using TIMER2. The
383 // time tolerance is approximately +/-50 ns (1/SYSCLK + function call time).
384 //
385 //-----------------------------------------------------------------------------
386 void Delay_us (BYTE time_us)
387 {
388 1 TR2 = 0; // Stop timer
389 1 TF2H = 0; // Clear timer overflow flag
390 1 TMR2 = -( (UINT)(SYSCLK/1000000) * (UINT)(time_us) );
391 1 TR2 = 1; // Start timer
392 1 while (!TF2H); // Wait till timer overflow occurs
393 1 TR2 = 0; // Stop timer
394 1 }
395
396 //-----------------------------------------------------------------------------
397 // Delay_ms
398 //-----------------------------------------------------------------------------
399 //
400 // Return Value : None
401 // Parameters : 1. time_ms - time delay in milliseconds
402 // range: 1 to 255
403 //
404 // Creates a delay for the specified time (in milliseconds) using TIMER2. The
405 // time tolerance is approximately +/-50 ns (1/SYSCLK + function call time).
406 //
407 //-----------------------------------------------------------------------------
408 void Delay_ms (BYTE time_ms)
409 {
410 1 BYTE i;
411 1
412 1 while(time_ms--)
413 1 for(i = 0; i< 10; i++) // 10 * 100 microsecond delay
414 1 Delay_us (100);
415 1 }
416
417 //-----------------------------------------------------------------------------
418 // EEPROM_Write
419 //-----------------------------------------------------------------------------
420 //
421 // Return Value : None
422 // Parameters : 1. address - the destination EEPROM address.
423 // range: 0 to EEPROM_CAPACITY
424 // 2. value - the value to write.
425 // range: 0x00 to 0xFF
426 //
427 // Writes one byte to the specified address in the EEPROM. This function polls
C51 COMPILER V7.50 FM25H20 11/27/2008 11:07:27 PAGE 8
428 // the EEPROM status register after the write operation, and returns only after
429 // the status register indicates that the write cycle is complete. This is to
430 // prevent from having to check the status register before a read operation.
431 //
432 //-----------------------------------------------------------------------------
433 void EEPROM_Write (UINT address, BYTE value)
434 {
435 1 // Writing a byte to the EEPROM is a five-step operation.
436 1 // Step1: Set the Write Enable Latch to 1
437 1 SLVSEL = 0; // Step1.1: Activate Slave Select
438 1 SPI0DAT = EEPROM_CMD_WREN; // Step1.2: Send the WREN command
439 1 while (!SPIF); // Step1.3: Wait for end of transfer
440 1 SPIF = 0; // Step1.4: Clear the SPI intr. flag
441 1 SLVSEL = 1; // Step1.5: Deactivate Slave Select
442 1 Delay_us (1); // Step1.6: Wait for at least
443 1 // T_NSS_DISABLE_MIN
444 1 // Step2: Send the WRITE command
445 1 SLVSEL = 0;
446 1 SPI0DAT = EEPROM_CMD_WRITE;
447 1 while (!SPIF);
448 1 SPIF = 0;
449 1
450 1
451 1 //ADDR_H=(unsigned char)((address >> 16) & 0x0000FF);
452 1 //ADDR_M=(unsigned char)((address >> 8) & 0x0000FF);
453 1 //ADDR_L=(unsigned char)(address & 0x0000FF);
454 1
455 1
456 1
457 1 // Step3: Send the EEPROM destination address (MSB first)
458 1 SPI0DAT =ADDR_H;// (BYTE)((address >> 16) & 0x0000FF);
459 1 while (!SPIF);
460 1 SPIF = 0;
461 1 SPI0DAT =ADDR_M;// (BYTE)((address >> 8) & 0x0000FF);
462 1 while (!SPIF);
463 1 SPIF = 0;
464 1 SPI0DAT =ADDR_L;// (BYTE)(address & 0x0000FF);
465 1 while (!SPIF);
466 1 SPIF = 0;
467 1
468 1 // Step4: Send the value to write
469 1 SPI0DAT = value;
470 1 while (!SPIF);
471 1 SPIF = 0;
472 1 SLVSEL = 1;
473 1 Delay_us (1);
474 1
475 1 // Step5: Poll on the Write In Progress (WIP) bit in Read Status Register
476 1 do
477 1 {
478 2 SLVSEL = 0; // Activate Slave Select
479 2 SPI0DAT = EEPROM_CMD_RDSR; // Send the Read Status Register command
480 2 while (!SPIF); // Wait for the command to be sent out
481 2 SPIF = 0;
482 2 SPI0DAT = 0; // Dummy write to output serial clock
483 2 while (!SPIF); // Wait for the register to be read
484 2 SPIF = 0;
485 2 SLVSEL = 1; // Deactivate Slave Select after read
486 2 Delay_us (1);
487 2 } while( (SPI0DAT & 0x01) == 0x01 );
488 1 }
*** WARNING C280 IN LINE 433 OF FM25H20.C: 'address': unreferenced local variable
C51 COMPILER V7.50 FM25H20 11/27/2008 11:07:27 PAGE 9
489
490 //-----------------------------------------------------------------------------
491 // EEPROM_Read
492 //-----------------------------------------------------------------------------
493 //
494 // Return Value : The value that was read from the EEPROM
495 // range: 0x00 to 0xFF
496 // Parameters : 1. address - the source EEPROM address.
497 // range: 0 to EEPROM_CAPACITY
498 //
499 // Reads one byte from the specified EEPROM address.
500 //
501 //-----------------------------------------------------------------------------
502 BYTE EEPROM_Read (UINT address)
503 {
504 1 // Reading a byte from the EEPROM is a three-step operation.
505 1
506 1 // Step1: Send the READ command
507 1 SLVSEL = 0; // Activate Slave Select
508 1 SPI0DAT = EEPROM_CMD_READ;
509 1 while (!SPIF);
510 1 SPIF = 0;
511 1
512 1
513 1
514 1 //ADDR_H=(unsigned char)((address >> 16) & 0x0000FF);
515 1 //ADDR_M=(unsigned char)((address >> 8) & 0x0000FF);
516 1 //ADDR_L=(unsigned char)(address & 0x0000FF);
517 1
518 1
519 1 // Step2: Send the EEPROM source address (MSB first)
520 1
521 1 SPI0DAT =ADDR_H; //(BYTE)((address >> 16) & 0x0000FF);
522 1 while (!SPIF);
523 1 SPIF = 0;
524 1 SPI0DAT = ADDR_M;//(BYTE)((address >> 8) & 0x0000FF);
525 1 while (!SPIF);
526 1 SPIF = 0;
527 1 SPI0DAT = ADDR_L;//(BYTE)(address & 0x0000FF);
528 1 while (!SPIF);
529 1 SPIF = 0;
530 1
531 1 // Step3: Read the value returned
532 1 SPI0DAT = 0; // Dummy write to output serial clock
533 1 while (!SPIF); // Wait for the value to be read
534 1 SPIF = 0;
535 1 SLVSEL = 1; // Deactivate Slave Select
536 1 Delay_us (1);
537 1
538 1 return SPI0DAT;
539 1 }
*** WARNING C280 IN LINE 502 OF FM25H20.C: 'address': unreferenced local variable
540
541 //-----------------------------------------------------------------------------
542 // End Of File
543 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 262 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
C51 COMPILER V7.50 FM25H20 11/27/2008 11:07:27 PAGE 10
PDATA SIZE = ---- ----
DATA SIZE = ---- 4
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -