stc8a8k--74hc595--spi

#include <stc8a8k.h>
#include <intrins.h>

sbit LED=P1^7;
	
sbit HC595_LATCH = P1^0;//latch pin or rck pin  STCP  ss 595pin12
sbit HC595_OE   = P1^1;//oe blank pin  595pin13

// 0data of 74hc595 pin14  ---->mosi P13
//clk of 595 shcp 595pin11        ---->sclk P15

void SendTo595(	unsigned char byteData);
void Delay10us();		//@22.1184MHz


void Delay500ms()		//@22.1184MHz
{
	unsigned char i, j, k;

	i = 57;
	j = 27;
	k = 112;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void portmode()
{
	P0M0=0x00;P0M1=0x00;
	P1M0=0x00;P1M1=0x00;
	P2M0=0x00;P2M1=0x00;
	P3M0=0x00;P3M1=0x00;
	P4M0=0x00;P4M1=0x00;
	P5M0=0x00;P5M1=0x00;
	P6M0=0x00;P6M1=0x00;
	P7M0=0x00;P7M1=0x00;
}


void Delay30us()		//@22.1184MHz
{
	unsigned char i;
	i = 219;
	while (--i);
}

void main()
{
	  portmode();

	  LED=0;
		Delay500ms();
		LED=1;
		Delay500ms();
		
		LED=0;
		Delay500ms();
		LED=1;
		Delay500ms();
	
  LED=0;
		Delay500ms();
		LED=1;
		Delay500ms();
		
		LED=0;
		Delay500ms();
		LED=1;
		Delay500ms();
	

    SPCTL = 0x50;                               //??SPI????
    SPSTAT = 0xc0;                              //?????

	HC595_LATCH =1;
  HC595_OE =0;	
	

	while(1)
	{
	//低电平亮
		
        HC595_LATCH = 0;                                 //????SS??
        SPDAT = 0x10;                           //??????
        while (!(SPSTAT & 0x80));               //??????
        SPSTAT = 0xc0;                          //?????
        HC595_LATCH = 1;   
	}
	
}

void Delay10us()		//@22.1184MHz
{
	unsigned char i;

	i = 71;
	while (--i);
}

void SendTo595(	unsigned char byteData)
{
//   char i=0;
//   for(;i<8;i++)
//   {
//        P13 = byteData>>7;
0000 0001 >>1  0000 0000
0000 0001 <<1  0000 0010		 
//        byteData= byteData<<1;      
//        P10 = 0;         
//        Delay10us();   
//        P10 = 1;        
//   }  
//   HC595_LATCH = 0;    //p10    
//	

//   Delay10us();
//   HC595_LATCH =1; 
//   HC595_OE=0;
 }
//        HC595_LATCH = 0;                                 //????SS??
//        SPDAT = 0x5a;                           //??????
//        while (!(SPSTAT & 0x80));               //??????
//        SPSTAT = 0xc0;                          //?????
//        HC595_LATCH = 0;   


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
用的是P1口的SPI。
接线
595DS,数据口----------P13 mosi
OE---------------------P11
RCK,上升沿输出,–latch,,,,----P10
SCK------- P15 sclk

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值