⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 电子摇摇棒.c

📁 摇摇棒源程序 摇摇棒源程序
💻 C
字号:
//================================================//
// 文件名:电子摇摇棒.c                           //
// 描  述:电子摇摇棒                             //
// 设 计:yiya                                   //
// 时 间:2007.10.27                             // 
//================================================//

#include <at892051.h>
#include "hz.h"

//引脚定义//
#define LEDH P1
#define LED9 P3_7
#define LED10 P3_4
#define LED11 P3_5
#define LED12 P3_0
#define LED13 P3_1

//变量定义//
unsigned int timecount,time;	//时间计数,一帧时间
unsigned char rank,frame,word;	//列,帧,字
unsigned char flag;	            //状态标志
unsigned char temp;

//函数声明//
//void Display(unsigned char h,unsigned char l);

//主函数//
main()
{
	TMOD=0x12;	//定时器0设为8位自重装定时模式
	TH0=6;	    //定时器0赋初值(0.5ms)
	TL0=6;
	ET0=1;	    //定时器0中断允许
	TR0=1;	    //定时器0开始计时
	ET1=0;
	IT0=1;	    //外部中断0为下降沿触发
	PX0=1;	    //外部中断0高优先级
	EX0=1;	    //外部中断0允许
	IT1=1;	    //外部中断1为下降沿触发
	PX1=1;	    //外部中断1高优先级
	EX1=1;	    //外部中断1允许
	EA=1;	    //总中断允许

    while(1)
	{
		switch(flag)
		{
		case 1:	rank=timecount*72/time;	break;  //24
//		case 2:	rank=24-timecount*24/time; break;
		case 2: rank=0; break;
		default: rank=0; frame=0; word=0; break;
		}
		if(rank>=(11+9+9) & rank<=(22+9+9))//if(rank>=11 & rank<=22)
		{
			LEDH=~GB_12[word].Msk[rank-(11+9+9)];
			temp=GB_12[word].Msk[rank+1-9-9];
	//		LEDH=~GB_12[word].Msk[rank-1];
	//		temp=GB_12[word].Msk[rank+11];
		//	LEDH=~GB_12[word].Msk[22-rank];
		//	temp=GB_12[word].Msk[35-(rank+1)];
			LED9=!(temp&0x80);
			LED10=!(temp&0x40);
			LED11=!(temp&0x20);
			LED12=!(temp&0x10);
		//	LED13=!(temp&0x08);
		}
        else if(rank>=(33+9) & rank<=(44+9))
		{
			LEDH=~GB_12[word+1].Msk[rank-33-9];
			temp=GB_12[word+1].Msk[rank+1-22-9];
		//	LEDH=~GB_12[word].Msk[22-rank];
		//	temp=GB_12[word].Msk[35-(rank+1)];
			LED9=!(temp&0x80);
			LED10=!(temp&0x40);
			LED11=!(temp&0x20);
			LED12=!(temp&0x10);
		//	LED13=!(temp&0x08);
		} 
        else if(rank>=55 & rank<=66)
		{
			LEDH=~GB_12[word+2].Msk[rank-55];
			temp=GB_12[word+2].Msk[rank+1-44];
		//	LEDH=~GB_12[word].Msk[22-rank];
		//	temp=GB_12[word].Msk[35-(rank+1)];
			LED9=!(temp&0x80);
			LED10=!(temp&0x40);
			LED11=!(temp&0x20);
			LED12=!(temp&0x10);
		//	LED13=!(temp&0x08);
		} 
		else
		{
			LEDH=0xff;
			LED9=1;
			LED10=1;
			LED11=1;
			LED12=1;
		//	LED13=1;
		}
//		LED13=rank!=frame;
//		if(rank>=4 & rank<=15) Display(GB_12[word].Msk[rank-4],GB_12[word].Msk[rank+8]);
//		else Display(0x00,0x00);
	}
}
/*
//显示函数
void Display(unsigned char h,unsigned char l)
{
	LEDH=~h;
	LED9=!(l&0x80);
	LED10=!(l&0x40);
	LED11=!(l&0x20);
	LED12=!(l&0x10);
//	LED13=!(l&0x08);
}
*/
//***** 外部中断0入口 *****//

void int0(void) interrupt 0 using 1
{
	EX0=0;	        //外部中断0禁止
	IE1=0;	        //清外部中断1触发标志
	EX1=1;	        //外部中断1允许
	time=timecount;	//读取时间
	timecount=0;	//时间计数器清零
	TL0=6;
	if(frame<23) frame++;	//帧计数 
	else
	{
		frame=0;
		if(word<11) word+=3;	//字计数
		else word=0;
	}
    if(time<2500) flag=2;	//从右至左摆动状态
	else flag=0;	//超时状态
}

//***** 外部中断1入口 *****//
void int1(void) interrupt 2 using 3
{
	EX1=0;	//外部中断1禁止
	IE0=0;	//清外部中断0触发标志
	EX0=1;	//外部中断0允许

//	time=timecount;	//读取时间
	timecount=0;	//时间计数器清零
	TL0=6;
	if(frame<23) frame++;	//帧计数
	else
	{
		frame=0;
		if(word<11) word+=3;	//字计数
		else word=0;
	}
    if(time<2500) flag=1;	//从左至右摆动状态
	else flag=0;	//超时状态
}

//***** 定时器0 *****入口//

void t0(void) interrupt 1 using 2
{
	if(timecount<2500) timecount++;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -