EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 600

Default Icon
901 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
STC8A8K64D4 Series Manual
- 584 -
#define ESPI 0x02
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xc9;
sfr P5M0 = 0xca;
sbit SS = P1^0;
sbit LED = P1^1;
sbit KEY = P0^0;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
LED = 1;
KEY = 1;
SS = 1;
SPCTL = 0x40; //Enable SPI slave mode and standby
SPSTAT = 0xc0; //Clear interrupt flag
while (1)
{
if (!KEY) //Wait for the key to trigger
{
SPCTL = 0x50; //Enable SPI master mode
SS = 0; //Pull down the slave SS pin
SPDAT = 0x5a; //Send test data
while (!KEY); //Wait for the keys to be released
}
if (SPSTAT & 0x80)
{
SPSTAT = 0xc0; //Clear interrupt flag
if (SPCTL & 0x10)
{ //Master mode
SS = 1; //Pull up the SS pin of the slave
SPCTL = 0x40; //Reset to slave and standby
}

Table of Contents

Related product manuals