资源预览内容
第1页 / 共23页
第2页 / 共23页
第3页 / 共23页
第4页 / 共23页
第5页 / 共23页
第6页 / 共23页
第7页 / 共23页
第8页 / 共23页
第9页 / 共23页
第10页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
嵌入式简易电子琴系统设计 作者: 日期:1 个人收集整理 勿做商业用途嵌入式开发试验嵌入式简易电子琴系统设计ARM2110实验开发板,外接矩阵键盘、蜂鸣器、LED显示屏、LED灯模块(带4.7K电阻)主程序include ”systemInit.hinclude buzzer.h”#include ”music。h”#include systemInit.h#define lcden GPIO_PIN_0 /PB0;define lcdrs GPIO_PIN_2 /PB2;/ 定义LED#define LED1_PERIPH SYSCTL_PERIPH_GPIOA#define LED1_PORT GPIO_PORTA_BASEdefine LED1_PIN GPIO_PIN_4#define LED2_PERIPH SYSCTL_PERIPH_GPIOA#define LED2_PORT GPIO_PORTA_BASE#define LED2_PIN GPIO_PIN_5define LED3_PERIPH SYSCTL_PERIPH_GPIOA#define LED3_PORT GPIO_PORTA_BASE#define LED3_PIN GPIO_PIN_6define LED4_PERIPH SYSCTL_PERIPH_GPIOG#define LED4_PORT GPIO_PORTG_BASE#define LED4_PIN GPIO_PIN_0define LED5_PERIPH SYSCTL_PERIPH_GPIOF#define LED5_PORT GPIO_PORTF_BASE#define LED5_PIN GPIO_PIN_2define LED6_PERIPH SYSCTL_PERIPH_GPIOGdefine LED6_PORT GPIO_PORTG_BASEdefine LED6_PIN GPIO_PIN_1#define LED7_PERIPH SYSCTL_PERIPH_GPIOE#define LED7_PORT GPIO_PORTE_BASE#define LED7_PIN GPIO_PIN_0#define LED8_PERIPH SYSCTL_PERIPH_GPIOE#define LED8_PORT GPIO_PORTE_BASE#define LED8_PIN GPIO_PIN_1/ 定义KEY#define KEY_PERIPH2 SYSCTL_PERIPH_GPIOB#define KEY_PORT2 GPIO_PORTB_BASEdefine KEY_PIN2 GPIO_PIN_6GPIO_PIN_5|GPIO_PIN_4/连接方式 矩阵键盘的行线接PC47 列线接PA03unsigned char data; /PD0PD7;unsigned char num;int guan;int jian;int numm;/lcd显示模块技术/lcd模块void write_com(unsigned char com) /写命令 GPIOPinWrite(GPIO_PORTB_BASE,lcdrs,0x00); / lcdrs=0; GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1GPIO_PIN_2 GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5GPIO_PIN_6GPIO_PIN_7,com);/PD=com;SysCtlDelay(5 (TheSysClock / 4000); / 延时 5msGPIOPinWrite(GPIO_PORTB_BASE,lcden,0xFF); / lcden=1; SysCtlDelay(5 (TheSysClock / 4000)); GPIOPinWrite(GPIO_PORTB_BASE,lcden,0x00); / lcden=0; void write_data(unsigned char date)GPIOPinWrite(GPIO_PORTB_BASE,lcdrs,0xFF); / lcdrs=1;GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0GPIO_PIN_1|GPIO_PIN_2 GPIO_PIN_3GPIO_PIN_4GPIO_PIN_5|GPIO_PIN_6GPIO_PIN_7,date);/PD=date; SysCtlDelay(5 (TheSysClock / 4000)); GPIOPinWrite(GPIO_PORTB_BASE,lcden,0xFF); / lcden=1; SysCtlDelay(5 * (TheSysClock / 4000); GPIOPinWrite(GPIO_PORTB_BASE,lcden,0x00); / lcden=0;void init()SysCtlPeriEnable(SYSCTL_PERIPH_GPIOD); /使能A端口 GPIOPinTypeOut(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1GPIO_PIN_2 GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5GPIO_PIN_6|GPIO_PIN_7); SysCtlPeriEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeOut(GPIO_PORTB_BASE, GPIO_PIN_0GPIO_PIN_2); GPIOPinWrite(GPIO_PORTB_BASE,lcden,0x00); / lcden=0; write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01); / 在开始清屏write_com(0x80+0x10); /数据指针地址/lcd模块结束,矩阵键盘模块开始 unsigned char KeyScan(void) if (GPIOPinRead(KEY_PORT2, KEY_PIN2) = 0x30) / 如果按下KEY2 num=17; return num; else if (GPIOPinRead(KEY_PORT2, KEY_PIN2) = 0x50) / 如果按下KEY3 num=18; return num; else if (GPIOPinRead(KEY_PORT2, KEY_PIN2) = 0x60) / 如果按下KEY4 num=16; return num; GPIOPinTypeOut(GPIO_PORTC_BASE,GPIO_PIN_4 GPIO_PIN_5| GPIO_PIN_6 GPIO_PIN_7); GPIOPinTypeOut(GPIO_PORTA_BASE,GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3); GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_4| GPIO_PIN_5 GPIO_PIN_6| GPIO_PIN_7,0Xf0); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_0 GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3,0X00); GPIOPinTypeIn(GPIO_PORTC_BASE,GPIO_PIN_4 GPIO_PIN_5 GPIO_PIN_6| GPIO_PIN_7); guan=GPIOPinRead(GPIO_PORTC_BASE, 0xff)&0xf0; jian=GPIOPinRead(GPIO_PORTA_BASE,0xff)0x0f; guan=jian|guan; if(guan!=0xf0) SysCtlDelay(5 * (TheSysClock / 4000)); if(guan!=0xf0) GPIOPinTypeOut(GPIO_PORTC_BASE,GPIO_PIN_4 GPIO_PIN_5 GPIO_PIN_6 GPIO_PIN_7); GPIOPinTypeOut(GPIO_PORTA_BASE,GPIO_PIN_0| GPIO_PIN_1 GPIO_PIN_2| GPIO_PIN_3); GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6 GPIO_PIN_7,0Xf0);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号