单片机实验:兰花草

具体笔记参考我的Notion:
Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.

 

这里贴一个代码,详细笔记见我的Notion

具体实现代码:

#include "reg51.h"
sbit P2_0=P2^0;
unsigned char code TABLE[]={0x42,0x82,0x82,0x82,0x84,0x02,0x72,
 						  	  0x62,0x72,0x62,0x52,0x48,
      0x0B2,0x0B2,0x0B2,0x0B2,0x0B4,0x02,0x0A2,
      0x12,0x0A2,0x0D2,0x92,0x88,
      0x82,0x0B2,0x0B2,0x0A2,0x84,0x02,0x72,
      0x62,0x72,0x62,0x52,0x44,0x02,0x12,
      0x12,0x62,0x62,0x52,0x44,0x02,0x82,
      0x72,0x62,0x52,0x32,0x48,
      0x72,0x62,0x52,0x32,0x48,0x00};
unsigned int code TABLE1[]={64021,64103,64260,64400, 64524,64580,64684,64777, 			 64820,64898,64968,65030, 64934} ;     
unsigned char th0_temp,tl0_temp;
void SING(unsigned char hi);
void DELAY(unsigned char lo);
main()
{
unsigned char i,hi,lo,coute;
TMOD=0X01;
ET0=1;
    EA=1;
    TR0=1;
	while(1)
	{
		P2_0=1;
		coute=0;
		while(TABLE[coute]!=0)
		{
			i=TABLE[coute];
			coute++;
			lo=i&0x0f;
			hi=(i&0xf0)>>4;
			if(hi>0)
				SING(hi);
			else 
				TR0=0;
			DELAY(lo);
		}
	}

}
void SING(unsigned char hi)
{
	th0_temp=(TABLE1[hi-1]/256);
	TH0=th0_temp;
	tl0_temp=(TABLE1[hi-1]%256);
	TL0=tl0_temp;
	TR0=1;
}
void DELAY(unsigned char lo)
{
	unsigned char temp1,temp2;
	do
	{
		for(temp1=0;temp1<150;temp1++)
			for(temp2=0;temp2<200;temp2++);
	}while(lo--);
}
void INTT0() interrupt 1					//定时器0中断函数
{
	TH0=th0_temp;
	TL0=tl0_temp;
	P2_0=~P2_0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值