《北邮PIC32单片机声控音乐播放器代码》由会员分享,可在线阅读,更多相关《北邮PIC32单片机声控音乐播放器代码(13页珍藏版)》请在金锄头文库上搜索。
1、./*系统头文件*/#include#include#include/*管脚,变量,函数定义*/#define uchar unsigned char#define uint unsigned int#define rs PORTAbits.RA7#define rw PORTAbits.RA6#define E PORTGbits.RG0#define DB0 PORTEbits.RE1#define DB1 PORTEbits.RE2#define DB2 PORTGbits.RG14#define DB3 PORTEbits.RE4#define DB4 PORTEbits.RE3#de
2、fine DB5 PORTDbits.RD12#define DB6 PORTGbits.RG1#define DB7 PORTEbits.RE0#define LED PORTGbits.RG13#define LED1 PORTDbits.RD1#define LED2 PORTDbits.RD2#definey4PORTDbits.RD5#definey3PORTDbits.RD4#definey2PORTFbits.RF5#definey1PORTFbits.RF4#definex4PORTBbits.RB14#definex3PORTBbits.RB13#definex2PORTBb
3、its.RB12#definex1PORTBbits.RB9#define SYS_FREQ(80000000) /主频80MHz#define bofang PORTDbits.RD13#define zanting PORTDbits.RD7#define quyi PORTFbits.RF0#define quer PORTFbits.RF1#define LED0_ON() LATDSET=(10;x-) for(y=112;y0;y-); /*分解命令、数值的函数*/void set_port(uchar data) uchar DB=data; DB0=(DB)%2; DB1=(D
4、B/2)%2; DB2=(DB/2)/2)%2; DB3=(DB/2)/2)/2)%2; DB4=(DB/2)/2)/2)/2)%2; DB5=(DB/2)/2)/2)/2)/2)%2; DB6=(DB/2)/2)/2)/2)/2)/2)%2; DB7=(DB/2)/2)/2)/2)/2)/2)/2)%2;/*传命令函数定义*/void write_com(uchar com) /命令函数 PORTClearBits(IOPORT_A, BIT_7); /RS接为0,低电平,写入命令 delay1(20); set_port(com); /将命令传给端口 delay1(200); PORTSe
5、tBits(IOPORT_G, BIT_0); /使能端写入1 delay1(20); PORTClearBits(IOPORT_G, BIT_0); /使能端写入0 delay1(20);/*传送数据函数的定义*/void write_data(uchar data) /数据函数 PORTSetBits(IOPORT_A, BIT_7); /RS接为1,高电平,写入数据 set_port(data); delay1(200); PORTSetBits(IOPORT_G, BIT_0); /使能端写入1 delay1(20); PORTClearBits(IOPORT_G, BIT_0); /使能端写入0delay1(20);/*自定义字符函数*/uchar pic38=0x00,0x00,0x04,0x0A,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x0A,0x04,0x00,0x00,0x00