📄 f06x_spi0_master.lst
字号:
524 //
525 //-----------------------------------------------------------------------------
526 void SPI_LED_On (void)
527 {
528 1 unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
529 1
530 1 SFRPAGE = SPI0_PAGE; // Switch to the necessary SFRPAGE
531 1
532 1 while (!NSSMD0); // Wait until the SPI is free, in case
533 1 // it's already busy
534 1
535 1 NSSMD0 = 0;
536 1
537 1 Command = SLAVE_LED_ON;
538 1
539 1 SPI0DAT = Command;
540 1
541 1 // The rest of this command will be handled by the SPI ISR, which will
542 1 // trigger when SPIF is set from sending the Command
543 1
544 1 SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
545 1 }
546
547 //-----------------------------------------------------------------------------
548 // SPI_LED_Off
549 //-----------------------------------------------------------------------------
550 //
551 // Return Value : None
C51 COMPILER V8.08 F06X_SPI0_MASTER 02/16/2008 14:38:53 PAGE 10
552 // Parameters : None
553 //
554 // Turns the LED on the SPI Slave off. The slave does not respond to this
555 // command, so the command consists of:
556 //
557 // Command = SLAVE_LED_OFF
558 // Length = 1 byte (the command itself)
559 //
560 //-----------------------------------------------------------------------------
561 void SPI_LED_Off (void)
562 {
563 1 unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
564 1
565 1 SFRPAGE = SPI0_PAGE; // Switch to the necessary SFRPAGE
566 1
567 1 while (!NSSMD0); // Wait until the SPI is free, in case
568 1 // it's already busy
569 1
570 1 NSSMD0 = 0;
571 1
572 1 Command = SLAVE_LED_OFF;
573 1
574 1 SPI0DAT = Command;
575 1
576 1 // The rest of this command will be handled by the SPI ISR, which will
577 1 // trigger when SPIF is set from sending the Command
578 1
579 1 SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
580 1 }
581
582 //-----------------------------------------------------------------------------
583 // SPI_Byte_Write
584 //-----------------------------------------------------------------------------
585 //
586 // Return Value : None
587 // Parameters : None
588 //
589 // Note: SPI_Data must contain the data to be sent before calling this
590 // function.
591 //
592 // Writes a single byte to the SPI Slave. The slave does not respond to this
593 // command, so the command consists of:
594 //
595 // Command = SPI_WRITE
596 // Length = 1 byte of command, 1 byte of data
597 //
598 //-----------------------------------------------------------------------------
599 void SPI_Byte_Write (void)
600 {
601 1 unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
602 1
603 1 SFRPAGE = SPI0_PAGE; // Switch to the necessary SFRPAGE
604 1
605 1 while (!NSSMD0); // Wait until the SPI is free, in case
606 1 // it's already busy
607 1
608 1 NSSMD0 = 0;
609 1
610 1 Command = SPI_WRITE;
611 1
612 1 SPI0DAT = Command;
613 1
C51 COMPILER V8.08 F06X_SPI0_MASTER 02/16/2008 14:38:53 PAGE 11
614 1 // The rest of this command will be handled by the SPI ISR, which will
615 1 // trigger when SPIF is set from sending the Command
616 1
617 1 SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
618 1 }
619
620 //-----------------------------------------------------------------------------
621 // SPI_Byte_Read
622 //-----------------------------------------------------------------------------
623 //
624 // Return Value : None
625 // Parameters : None
626 //
627 // Note: SPI_Data will contain the data received after calling this function.
628 //
629 // Reads a single byte from the SPI Slave. The command consists of:
630 //
631 // Command = SPI_READ
632 // Length = 1 byte of command, 1 byte of data
633 //
634 //-----------------------------------------------------------------------------
635 void SPI_Byte_Read (void)
636 {
637 1 unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
638 1
639 1 SFRPAGE = SPI0_PAGE; // Switch to the necessary SFRPAGE
640 1
641 1 while (!NSSMD0); // Wait until the SPI is free, in case
642 1 // it's already busy
643 1
644 1 NSSMD0 = 0;
645 1
646 1 Command = SPI_READ;
647 1
648 1 SPI0DAT = Command;
649 1
650 1 // The rest of this command will be handled by the SPI ISR, which will
651 1 // trigger when SPIF is set from sending the Command
652 1
653 1 SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
654 1 }
655
656 //-----------------------------------------------------------------------------
657 // SPI_Array_Write
658 //-----------------------------------------------------------------------------
659 //
660 // Return Value : None
661 // Parameters : None
662 //
663 // Note: SPI_Data_Array must contain the data to be sent before calling this
664 // function.
665 //
666 // Writes an array of values of size MAX_BUFFER_SIZE to the SPI Slave. The
667 // command consists of:
668 //
669 // Command = SPI_WRITE_BUFFER
670 // Length = 1 byte of command, MAX_BUFFER_SIZE bytes of data
671 //
672 // Note: Polled mode is used for this function in order to buffer the data
673 // being sent using the TXBMT flag.
674 //
675 //-----------------------------------------------------------------------------
C51 COMPILER V8.08 F06X_SPI0_MASTER 02/16/2008 14:38:53 PAGE 12
676 void SPI_Array_Write (void)
677 {
678 1 unsigned char array_index;
679 1 unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
680 1
681 1 SFRPAGE = SPI0_PAGE; // Switch to the necessary SFRPAGE
682 1
683 1 while (!NSSMD0); // Wait until the SPI is free, in case
684 1 // it's already busy
685 1
686 1 EIE1 &= ~0x01; // Disable SPI interrupts
687 1
688 1 NSSMD0 = 0;
689 1
690 1 SPI0DAT = SPI_WRITE_BUFFER; // Load the XMIT register
691 1
692 1 while (TXBMT != 1) // Wait until the command is moved into
693 1 { // the XMIT buffer
694 2 }
695 1
696 1 for (array_index = 0; array_index < MAX_BUFFER_SIZE; array_index++)
697 1 {
698 2 SPI0DAT = SPI_Data_Array[array_index]; // Load the data into the buffer
699 2 while (TXBMT != 1) // Wait until the data is moved into
700 2 { // the XMIT buffer
701 3 }
702 2 }
703 1 SPIF = 0;
704 1 while (SPIF != 1) // Wait until the last byte of the
705 1 { // data reaches the Slave
706 2 }
707 1 SPIF = 0;
708 1
709 1 NSSMD0 = 1; // Diable the Slave
710 1
711 1 EIE1 |= 0x01; // Re-enable SPI interrupts
712 1
713 1 SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
714 1 }
715
716 //-----------------------------------------------------------------------------
717 // SPI_Array_Read
718 //-----------------------------------------------------------------------------
719 //
720 // Return Value : None
721 // Parameters : None
722 //
723 // Note: SPI_Data_Array will contain the data received after calling this
724 // function.
725 //
726 // Reads a single byte from the SPI Slave. The command consists of:
727 //
728 // Command = SPI_READ_BUFFER
729 // Length = 1 byte of command, MAX_BUFFER_SIZE bytes of data
730 //
731 //-----------------------------------------------------------------------------
732 void SPI_Array_Read (void)
733 {
734 1 unsigned char SFRPAGE_save = SFRPAGE; // Save the current SFRPAGE
735 1
736 1 SFRPAGE = SPI0_PAGE; // Switch to the necessary SFRPAGE
737 1
C51 COMPILER V8.08 F06X_SPI0_MASTER 02/16/2008 14:38:53 PAGE 13
738 1 while (!NSSMD0); // Wait until the SPI is free, in case
739 1 // it's already busy
740 1
741 1 NSSMD0 = 0;
742 1
743 1 Command = SPI_READ_BUFFER;
744 1
745 1 SPI0DAT = Command;
746 1
747 1 // The rest of this command will be handled by the SPI ISR, which will
748 1 // trigger when SPIF is set from sending the Command
749 1
750 1 SFRPAGE = SFRPAGE_save; // Restore the SFRPAGE
751 1 }
752
753 //-----------------------------------------------------------------------------
754 // Delay
755 //-----------------------------------------------------------------------------
756 //
757 // Return Value : None
758 // Parameters : None
759 //
760 // Delay for little while (used for blinking the LEDs)
761 //
762 //-----------------------------------------------------------------------------
763 void Delay (void)
764 {
765 1 unsigned long count;
766 1
767 1 for (count = 200000; count > 0; count--);
768 1 }
769
770 //-----------------------------------------------------------------------------
771 // End Of File
772 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 602 ----
CONSTANT SIZE = 8 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 12 14
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -