Demo entry 6685570

s

   

Submitted by x on Dec 20, 2017 at 09:49
Language: C. Code size: 1.3 kB.

#include<reg51.h>
#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
uchar code ZZ[4]={0xf3,0xf6,0xfc,0xf9};
uchar code FZ[4]={0xf9,0xfc,0xf6,0xf3};
uchar  OUT[4];
uint i,COUNT,TIME;
sbit	K1	= P2^4;	//°´¼ü1ÕýתZZ
sbit	K2	= P2^5; //°´¼ü2·´×ªFZ
sbit	K3	= P2^6; //°´¼ü3Æô¶¯
sbit	K4	= P2^7; //°´¼ü4Í£Ö¹

//¶ÁÈ¡°´¼ü×Ó³ÌÐò
void keyboard(void)	
{				
	if(K1==0)	//°´¼ü1£¬Æô¶¯¶¨Ê±Æ÷T0£¬¸³ÖµÕýתÓÚOUTÊý×é
		{	
			TR0=1;
			for(i=0;i<=3;i++)
				OUT[i] = ZZ[i];
		}
	else if(K2==0)	//°´¼ü2£¬Æô¶¯¶¨Ê±Æ÷T0£¬¸³Öµ·´×ªÓÚOUTÊý×é
		{
			TR0=1;
			for(i=0;i<=3;i++)
				OUT[i] = FZ[i];
		}
	else if(K3==0)	{EA=1;}		//°´¼ü3£¬¿ªÆô×ÜÖжÏ
	else if(K4==0)
		{TR0=0;EA=0;COUNT=0;TIME=0;} //°´¼ü4£¬¹Ø±ÕT0Óë×ÜÖжϣ¬ÇåÁã¼ÆÊý
}


void main(void)
{
	ET0 = 1;			//¿ªÆôT0ÖжÏÔÊÐí
	TMOD = 0x02; 		//³õʼ»¯T0£¬·½Ê½2
	TH0 = 256-250; 
	TL0 = 256-250;		//¸³Öµ250us
	COUNT = 0;				
	TIME = 0;			//¹éÁã¼ÆÊýCOUNT£¬TIME
	P2 = 0xFF;			//ÉÏÀ­P2¿Ú
	while(1)
		keyboard();		//¶ÁÈ¡°´¼üÇé¿ö
}

//T0ʱÖÓÖжϳÌÐò
void Time0(void) interrupt 1
{
	P2 = OUT[COUNT];		//Êä³öÂö³å
	COUNT++;				
	TIME++;					
	if(COUNT>=4) COUNT=0;	//ËÄÅÄÑ­»·
	if(TIME==4000)			//TIME¼Æʱ£¬Âú1000msºóͣת£¬ÇåÁã
	{
		TIME=0;
		TR0=0;
		P2 = 0xFF;
	}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).