仿真原理图如下
avr单片机源码:
#include #include #define uchar unsigned char #define uint unsigned int #define LED1_ON() PORTA=0xFE #define LED2_ON() PORTA=0xF7 #define LED3_ON() PORTA=0xBF #define LED4_ON() PORTA=0x7F uchar key_0=16; uint Fr[]= {0,262*8,294*8,330*8,349*8,392*8,440*8, 494*8,523*8,587*8,659*8,698*8,784*8,880*8,988*8 ,1046*8}; uchar SEG_CODE[]= { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E }; uint Tone_Delay_Table[] = { 64021,64103,64260,64400,64524,64580,64684,64777, 64820,64898,64968,65030,65058,65110,65157,65178}; uchar spe1_Tone[] = { 3,5,5,3,2,1,2,3,5,3, 2,3,5,5,3,2,1,2,3,2,1,1,0xFF }; uchar spe1_Time[] = { 2,1,1,2,1,1,1,2,1,1,1,2,1,1,2,1,1,1,2,1,1,1,0xFF }; uchar spe2_Tone[] = { 1,3,3,3,3,5,4,2,5,3,7,6,5,5,7,4,4,3,6,7,2,1,0xFF }; uchar spe2_Time[] = { 2,1,1,2,1,1,1,2,1,1,3,2,1,1,2,4,1,1,2,1,1,1,0xFF }; uchar spe3_Tone[] = { 0,1,2,3,4,5,5,6,7,8,9,10,11,12,13,14,15, 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0xFF}; uchar spe3_Time[] = { 1,1,1,1,1,1,1,1,1,1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1,1,1,1,1,1,1,1,1,0xFF}; uchar spe4_Tone[] = { 1,2,3,1,1,2,3,1,3,4,5,3,4,5,5,6,5,4,3,1,5,6, 5,4,3,1,1,5,1,1,5,1,0xFF }; uchar spe4_Time[] = { 2,1,1,1,2,1,1,1,2,1,1,2,1,1,3,0.5,0.25,0.5,0.25,1,1, 0.5,0.25,0.5,1,1,1,1,3,1,1,3,0xFF }; uchar *spe_Tone_Ptr[]={ spe1_Tone,spe2_Tone,spe3_Tone,spe4_Tone}, *spe_Time_Ptr[]= {spe1_Time,spe2_Time,spe3_Time,spe4_Time}; uint Tone_Idx = 0; uint i = 0,j=1,spe_Idx = 0; uint FALSE = 0, TRUE = 1, Pause = 1; void delay_1ms(void) { uint i; for(i=1;i<(uint)(153*143-2);i++) ; } void delay(unsigned int n) { unsigned int i; for(i=0;i delay_1ms(); } uchar KeyMatrix_Down() { DDRB=0XF0; PORTB=0X0F; delay(1); return PINB!=0x0f? 1:0; } void Keys_Scan() { switch(PINB) { case 0B00001110: key_0=0; break; case 0B00001101: key_0=1; break; case 0B00001011: key_0=2; break; case 0B00000111: key_0=3; break; default:key_0=0xFF; } DDRB=0x0F; PORTB=0xF0; delay(1); switch(PINB) { case 0B11100000: key_0+=0; break; case 0B11010000: key_0+=4; break; case 0B10110000: key_0+=8; break; case 0B01110000: key_0+=12; break; default: key_0= 0xFF; } } int main() { DDRB=0xFF; PORTB=0xFF; DDRA=0xFF; PORTA=0xFF; DDRC=0xFF; PORTC=0xBF; DDRD|=BIT(PD7); PORTD&=~BIT(PD7); DDRD=~(BIT(PD2)|BIT(PD3)); PORTD=BIT(PD2)|BIT(PD3); MCUCR=0x82; GICR=BIT(INT0)|BIT(INT1); TCCR1A=0x00; TCCR1B=0x09; SREG=0x80; while(1) { if(KeyMatrix_Down()==0) { if(Pause) { continue; } TCCR1B=0x01; Tone_Idx=spe_Tone_Ptr[spe_Idx][i]; if(Tone_Idx==0xFF) { delay(200); i=0; continue; } TIMSK=BIT(TOIE1); delay(spe_Time_Ptr[spe_Idx][Tone_Idx]*200/26); TIMSK=0x00; i++; } else
上一篇:avr单片机带小数点数码管的程式
下一篇:ATmage128内部EEPROE的应用程序
推荐阅读最新更新时间:2024-11-17 17:02
设计资源 培训 开发板 精华推荐
- LTC3446,一个 IC 从一个锂离子电池产生三个低于 2V 的电源轨
- ESP8266-01s 继电器(LTV-817S-B)
- LT3091EFE GND 引脚参考 SHDN 信号的典型应用
- 使用 Richtek Technology Corporation 的 RT9184A 的参考设计
- 多功能mini电脑(SD、wifi、OLED)
- 便携式酒精检测仪
- SY89831U,用于 GB 以太网交换机时钟缓冲器的评估板
- #第七届立创电赛#USB功率+姿态显示工具
- LDK130PU18R 1.8V、300 mA 低静态电流极低噪声 LDO 的典型应用可调版本电路
- 基于HNC-25LA的电流采样模块