1、嵌入式简易电子琴系统设计嵌入式开发试验嵌入式简易电子琴系统设计ARM2110实验开发板,外接矩阵键盘、蜂鸣器、LED显示屏、LED灯模块(带4.7K电阻)主程序#include systemInit.h#include 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_BASE#defin
2、e LED1_PIN GPIO_PIN_4#define LED2_PERIPH SYSCTL_PERIPH_GPIOA#define LED2_PORT GPIO_PORTA_BASE#define LED2_PIN GPIO_PIN_5#define LED3_PERIPH SYSCTL_PERIPH_GPIOA#define LED3_PORT GPIO_PORTA_BASE#define LED3_PIN GPIO_PIN_6#define LED4_PERIPH SYSCTL_PERIPH_GPIOG#define LED4_PORT GPIO_PORTG_BASE#define L
3、ED4_PIN GPIO_PIN_0#define LED5_PERIPH SYSCTL_PERIPH_GPIOF#define LED5_PORT GPIO_PORTF_BASE#define LED5_PIN GPIO_PIN_2#define LED6_PERIPH SYSCTL_PERIPH_GPIOG#define LED6_PORT GPIO_PORTG_BASE#define LED6_PIN GPIO_PIN_1#define LED7_PERIPH SYSCTL_PERIPH_GPIOE#define LED7_PORT GPIO_PORTE_BASE#define LED7
4、_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_BASE#define KEY_PIN2 GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4/连接方式 矩阵键盘的行线接PC47 列线接PA03unsigned char data; /PD0-PD7;uns
5、igned 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_1|GPIO_PIN_2| GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7,com);/PD=com; SysCtlDelay(5 * (T
6、heSysClock / 4000); / 延时 5ms GPIOPinWrite(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_
7、0|GPIO_PIN_1|GPIO_PIN_2| GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_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() SysCtlPeriE
8、nable(SYSCTL_PERIPH_GPIOD); /使能A端口 GPIOPinTypeOut(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2| GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); SysCtlPeriEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeOut(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_2); GPIOPinWrite(GPIO_PORTB_BASE,lcden,0x00); / lcd
9、en=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
10、; 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
11、_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
12、|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|
13、GPIO_PIN_7,0Xf0); GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3,0X07); GPIOPinTypeIn(GPIO_PORTC_BASE,GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7); guan=GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7)&0xf0; jian=GPIOPinRead(GPIO_PORTA_BAS
14、E,GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3)&0x0f; guan=jian|guan; if(guan=0x77) SysCtlDelay(5 * (TheSysClock / 4000); if(guan=0x77) num=11; return num; if(guan=0xb7) SysCtlDelay(5 * (TheSysClock / 4000); if(guan=0xb7) num=7; return num; if(guan=0xd7) SysCtlDelay(5 * (TheSysClock / 4000); if(gu
15、an=0xd7) num=4; return num; if(guan=0xe7) SysCtlDelay(5 * (TheSysClock / 4000); if(guan=0xe7) num=0; return num; GPIOPinTypeOut(GPIO_PORTC_BASE,GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_0| GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3,0X0b); GPIOPinTypeIn(GPIO_PORTC_BASE,GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1