I LOVE YOU (单片机)

#include<reg51.h>
#include<intrins.h>

sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;

#define COMMONPORTS		P0

unsigned char code TAB[8]  = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

unsigned char code CHARCODE[4][8]=
{

{0x00,0x00,0xc3,0xff,0xff,0xc3,0x00,0x00},
{0x00,0x18,0x24,0x12,0x12,0x24,0x18,0x00},
{0x38,0x44,0x42,0x21,0x21,0x42,0x44,0x38},
{0x00,0xf0,0xf8,0x1f,0x1f,0xf8,0xf0,0x00}	

};
void delay(unsigned int time)
{
  unsigned int i,j;
  for(i=0;i<time;i++)
    for(j=0;j<121;j++);
}

void Hc595SendByte(unsigned char dat)
{
	unsigned char a;
	SRCLK=0;
	RCLK=0;
	for(a=0;a<8;a++)
	{
		SER=dat>>7;
		dat<<=1;

		SRCLK=1;
		_nop_();
		_nop_();
		SRCLK=0;	
	}

	RCLK=1;
	_nop_();
	_nop_();
	RCLK=0;
}


void main()
{	
 	unsigned char tab, j;
	unsigned int  i;

	while(1)
	{	
		for(i= 0; i<50; i++ ) 
		{
			for(tab=0;tab<8;tab++)
			{	

				Hc595SendByte(0x00);			    																
				COMMONPORTS	= TAB[tab];				 
				Hc595SendByte(CHARCODE[j][tab]);	
				delay(2);		
			}
			 
		}
		j++;
		if(j == 4)
		{
			j = 0;
		}
	}	
}

 

发布者

我乃堂堂SCUT的一条咸鱼!

发表评论

电子邮件地址不会被公开。 必填项已用*标注