单片机电子琴设计报告Word文档下载推荐.docx
- 文档编号:21522130
- 上传时间:2023-01-30
- 格式:DOCX
- 页数:30
- 大小:174.34KB
单片机电子琴设计报告Word文档下载推荐.docx
《单片机电子琴设计报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《单片机电子琴设计报告Word文档下载推荐.docx(30页珍藏版)》请在冰豆网上搜索。
键盘扫描模块:
对十六个按键进行逐次扫描,扫描到前八个按键时,蜂鸣器依次发出1,2,3,4,5,6,7,8的音调声。
其余按键,可以跳转到不同的曲目以及液晶模块显示,保留几个按键做以后的扩展用。
3.2系统设计
3.2.1系统流程图
分析各项设计要求后,可绘制如下程序流程图
3.2.2系统原理图
3.3文件程序代码
(1).液晶模块头文件
sbitLCD_RS=P3^6;
sbitLCD_RW=P3^5;
sbitLCD_EN=P3^3;
sfrLCDData=0x80;
voidLCDWrite(bitcd,unsignedcharinput);
voidLCDWait(unsignedcharCiShu);
voidLCDDelay();
voidLCDInitialize();
voidLCDPrintString(unsignedcharx,unsignedchary,unsignedchar*string);
voidLCDPrintNumber(unsignedcharx,unsignedchary,unsignedcharbits,unsignedintnumber);
unsignedcharReadState();
voidLCDInitialize()
{
LCDDelay();
LCDWrite(0,0x38);
LCDWrite(0,0x08);
LCDWrite(0,0x01);
LCDWrite(0,0x06);
LCDWrite(0,0x0c);
}
voidLCDWrite(bitcd,unsignedcharDATA)
LCDWait(20);
LCD_RS=cd;
LCD_RW=0;
LCD_EN=0;
LCDData=DATA;
LCD_EN=1;
voidLCDPrintString(unsignedcharx,unsignedchary,unsignedchar*string)
unsignedcharaddress;
address=x+(1-y)*0x40+0x80;
LCDWrite(0,address);
while(*string!
='
\0'
)
LCDWrite(1,*string);
string++;
voidLCDPrintNumber(unsignedcharx,unsignedchary,unsignedcharWeiShu,unsignedintnumber)
unsignedcharj,temp[5];
//if(number>
0)
temp[0]=(number%100000)/10000+48;
temp[1]=(number%10000)/1000+48;
temp[2]=(number%1000)/100+48;
temp[3]=(number%100)/10+48;
temp[4]=number%10+48;
for(j=5-WeiShu;
j<
5;
j++)
LCDWrite(1,temp[j]);
voidLCDWait(unsignedcharCiShu)
unsignedchari;
for(i=0;
i<
CiShu;
i++)
if(ReadState()&
0x80)continue;
elsebreak;
}
unsignedcharReadState()
unsignedchartemp;
P0=0xff;
LCD_RS=0;
LCD_RW=1;
temp=LCDData;
returntemp;
voidLCDDelay()
unsignedinta;
for(a=0;
a<
1000;
a++);
(2).时钟芯片模块头文件
voidiicdelay(unsignedinttimes);
voidiicstart()
MDE=1;
MDO=1;
iicdelay
(2);
MCO=1;
MDO=0;
voidiicstop()
voidiicack()
MCO=0;
iicdelay
(1);
voidiicnack()
//MCO=0;
bitiicreadack()
bitack;
MCO=0;
MDE=0;
ack=MDI;
returnack;
voidiicwriteda(unsignedcharda)
unsignedchari;
for(i=0;
8;
{
iicdelay(0);
if((da<
<
i)&
0x80)
else
iicdelay(3);
}
unsignedchariicreadda()
unsignedcharda;
inti;
da=0;
if(MDI==1)
{da=da<
1;
da++;
da=da<
returnda;
voidiicdelay(unsignedintt)
unsignedinti,j;
t;
for(j=5;
j>
0;
j--);
voidReadTime(unsignedcharTIME[7])
bitEATemp;
unsignedchartemp;
EATemp=EA;
iicstart();
iicwriteda(0xd0);
iicreadack();
iicwriteda(0x00);
iicstop();
iicwriteda(0xd1);
TIME[0]=iicreadda();
iicack();
TIME[1]=iicreadda();
TIME[2]=iicreadda();
TIME[3]=iicreadda();
TIME[4]=iicreadda();
TIME[5]=iicreadda();
TIME[6]=iicreadda();
iicnack();
TIME[0]=((TIME[0]&
0x7f)>
>
4)*10+(TIME[0]&
0x0f);
//second
TIME[1]=((TIME[1]&
4)*10+(TIME[1]&
//minute
if(TIME[2]&
0x40)
0x20)temp=0x80;
elsetemp=0x40;
TIME[2]=((TIME[2]&
0x1f)>
4)*10+(TIME[2]&
//hour
TIME[2]|=temp;
}
0x3f)>
TIME[3]=TIME[3]&
0x07;
//week
TIME[4]=((TIME[4]&
4)*10+(TIME[4]&
//date
TIME[5]=((TIME[5]&
4)*10+(TIME[5]&
//month
TIME[6]=(TIME[6]>
4)*10+(TIME[6]&
//year
EA=EATemp;
voidSetTime(unsignedcharTIME[7])
unsignedchartemp=0;
unsignedcharTimeTemp[7];
for(temp=0;
temp<
7;
temp++)TimeTemp[temp]=TIME[temp];
temp=0;
TimeTemp[6]=((TimeTemp[6]/10)<
4)+(TimeTemp[6]%10);
TimeTemp[5]=((TimeTemp[5]/10)<
4)+(TimeTemp[5]%10);
TimeTemp[4]=((TimeTemp[4]/10)<
4)+(TimeTemp[4]%10);
TimeTemp[3]=((TimeTemp[3]/10)<
4)+(TimeTemp[3]%10);
if((TimeTemp[2]&
0xc0)==0x00)
TimeTemp[2]=((TimeTemp[2]/10)<
4)+(TimeTemp[2]%10);
0xc0)==0x01)temp=0x40;
elsetemp=0x60;
TimeTemp[2]&
=0x3f;
TimeTemp[2]|=temp;
TimeTemp[1]=((TimeTemp[1]/10)<
4)+(TimeTemp[1]%10);
TimeTemp[0]=((TimeTemp[0]/10)<
4)+(TimeTemp[0]%10);
TimeTemp[0]&
=0x7f;
iicwriteda(TimeTemp[0]);
iicwriteda(TimeTemp[1]);
iicwriteda(TimeTemp[2]);
iicwriteda(TimeTemp[3]);
iicwriteda(TimeTemp[4]);
iicwriteda(TimeTemp[5]);
iicwriteda(TimeTemp[6]);
voidSwitchRTC(unsignedcharSWITCH)
//iicdelay
(1);
temp=iicreadda();
if(SWITCH)temp&
elsetemp|=0x80;
iicwriteda(temp);
EA=EATemp;
(3)主体程序
#include<
aduc848.h>
#include<
INTRINS.H>
LCD1602.h>
rtc.h>
sbitlie0=P2^3;
sbitlie1=P2^2;
sbitlie2=P2^1;
sbitlie3=P2^0;
sbitPWM1=P2^6;
unsignedcharkey;
unsignedcharSTH0,STL0;
unsignedcharjishi=0;
unsignedcharn=0;
//n为节拍常数变量
unsignedchara[7]={00,59,19,3,4,8,10};
unsignedcharb[7];
voiddelay1s(void)
unsignedchari,k;
for(k=100;
k>
k--)
for(i=100;
i>
i--);
/*定时器0中断*/
voidTIMER0(void)interrupt1
TH0=STH0;
TL0=STL0;
PWM1=~PWM1;
/*定时器1中断*/
voidint0()interrupt3//采用中断3控制节拍节拍延时
{TH1=0xd8;
TL1=0xef;
n--;
/*定时器2中断*/
voidint1()interrupt5//采用中断3控制节拍节拍延时
{TH2=0xd8;
TL2=0xef;
voiddelay(unsignedcharm)//控制频率延时
{
unsignedi=3*m;
while(--i);
voiddelayms(unsignedchara)//豪秒延时子程序
while(--a);
//采用while(--a)不要采用while(a--);
各位可编译一下看看汇编结果就知道了!
unsignedintcodetab[]={0xfc43,0xfd08,0,0,0xfd08,0xfd32,0,0,0xfd81,0xfdc7,0,0,0xfe05,0xfe21,0,0,};
/*unsignedcharcodetable[]={0x03,0x9f,0x25,0x0d,
0x99,0x49,0x41,0x1f,
0x01,0x09,0x11,0xc1,
0x63,0x85,0x61,0x71,0xff};
*/
unsignedcharcodemusic_tab_1[]={
/*1*/
0x20,0x20,0x20,0x10,0x20,0x10,0x20,0x20,0x20,0x20,
0x20,0x20,0x1c,0x20,0x20,0x20,0x24,0x20,
0x26,0x20,0x1c,0x20,0x19,0x20,0x18,0x10,
0x19,0x10,0x20,0x30,0x01,0x20,0x20,0x10,0x20,0x10,
0x1c,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,
0x26,0x20,0x20,0x20,0x01,0x20,0x20,0x20,
0x24,0x20,0x20,0x20,0x26,0x10,0x2b,0x20,0x30,0x10,
0x2b,0x60,
/*2*/
//1176711237755
0x30,0x40,0x18,0x20,0x19,0x20,0x1c,0x20,0x19,0x10,
0x18,0x10,0x18,0x20,0x2b,0x20,0x13,0x20,0x19,0x20,
0x19,0x20,0x20,0x10,0x20,0x10,
//63221117
0x1c,0x20,0x13,0x10,0x15,0x10,0x15,0x20,0x18,0x20,
0x18,0x40,0x18,0x20,0x19,0x20,
//6711237755
0x1c,0x20,0x19,0x10,0x18,0x10,0x18,0x20,0x15,0x20,
0x13,0x20,0x19,0x20,0x19,0x20,0x20,0x10,0x20,0x10,
//632211
0x18,0x60,
//00000
0x01,0x40,0x01,0x40,0x01,0x40,0x01,0x40,0x01,0x60,
//1155555577755
0x18,0x10,0x18,0x10,0x10,0x20,0x10,0x10,0x1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 电子琴 设计 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)