📄 新建 文本文档.txt
字号:
//********************************************************************************
//project:
//name :
//date :
//********************************头文件******************************************
#include<avr/eeprom.h>
#include<avr/pgmspace.h>
#include<avr/interrupt.h>
#include <util/twi.h>
#include"LCD/2402.h"
#include"KEY/KEY.h"
#include"DELAY/DELAY.h"
#include"TWI/TWI.h"
#include"IR/IR.h"
//********************************************************************************
uchar digital[10]="0123456789";
uchar votable[6]={0,1,2,3,4,5}; //0-VOICE/1-BASS/2-TREBLE/3-INPUT/4-DB/5-LOUD
const prog_uchar trbtable[15]={0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x7f,0x7e,0x7d,0x7c,0x7b,0x7a,0x79,0x78};//trbe and treble change date
const prog_uchar bastable[15]={0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x6f,0x6e,0x6d,0x6c,0x6b,0x6a,0x69,0x68};//bass and treble change date
uchar file_return; //菜单返回标志,当5秒无按键按下返回主界面
uchar timecount; //中断计数,当5秒无按键按下返回主界面
uchar ke,model=1,dbloud, mute,lond;
void system_int(void);
SIG_OVERFLOW0(void);
//-------------------------------------main------------------------------------------------------------
//函数名:main
//返回值:无
//-----------------------------------------------------------------------------------------------------
int main()
{
system_int();
while(1)
{
//----------------------VOICE---------------------------
if((ke==10||irnum==10)&&model==1)
{
votable[0]--;if(votable[0]>200)votable[0]=0;
LCD_write_char(18,0,votable[0]/10+48);
LCD_write_char(18,0,votable[0]/10+48);
LCD_write_char(19,0,votable[0]%10+48);
while( !write_nbyte1(0x88,63-votable[0]));
irnum=0;ke=0;
}
if((ke==9||irnum==9)&&model==1)
{
votable[0]++;if(votable[0]>63)votable[0]=63;
LCD_write_char(18,0,votable[0]/10+48);
LCD_write_char(19,0,votable[0]%10+48);
while( !write_nbyte1(0x88,63-votable[0]));
irnum=0;ke=0;
}
//----------------------------BASS------------------------
if((ke==10||irnum==10)&&model==2)
{
votable[1]--;if(votable[1]>200)votable[1]=0;
LCD_write_char(18,0,votable[1]/10+48);
LCD_write_char(19,0,votable[1]%10+48);
while( !write_nbyte1(0x88,pgm_read_byte(&bastable[votable[1]])));
irnum=0;ke=0;
}
if((ke==9||irnum==9)&&model==2)
{
votable[1]++;if(votable[1]>14)votable[1]=14;
LCD_write_char(18,0,votable[1]/10+48);
LCD_write_char(19,0,votable[1]%10+48);
while( !write_nbyte1(0x88,pgm_read_byte(&bastable[votable[1]])));
irnum=0;ke=0;
}
//-------------------------TREB----------------------------
if((ke==10||irnum==10)&&model==3)
{
votable[2]--;if(votable[2]>200)votable[2]=0;
LCD_write_char(18,0,votable[2]/10+48);
LCD_write_char(19,0,votable[2]%10+48);
while( !write_nbyte1(0x88,pgm_read_byte(&trbtable[votable[2]])));
irnum=0;ke=0;
}
if((ke==9||irnum==9)&&model==3)
{
votable[2]++;if(votable[2]>14)votable[2]=14;
LCD_write_char(18,0,votable[2]/10+48);
LCD_write_char(19,0,votable[2]%10+48);
while( !write_nbyte1(0x88,pgm_read_byte(&trbtable[votable[2]])));
irnum=0;ke=0;
}
//------------------------INPUT--------------------------
if((ke==10||irnum==10)&&model==4)
{
votable[3]--;if(votable[3]>200)votable[3]=0;
LCD_write_char(18,0,votable[3]/10+48);
LCD_write_char(19,0,votable[3]%10+48);
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号
irnum=0;ke=0;
}
if((ke==9||irnum==9)&&model==4)
{
votable[3]++;if(votable[3]>3)votable[3]=3;
LCD_write_char(18,0,votable[3]/10+48);
LCD_write_char(19,0,votable[3]%10+48);
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号
irnum=0;ke=0;
}
//----------------------D B------------------------------
if((ke==10||irnum==10)&&model==5)
{
votable[4]--;if(votable[4]>200)votable[4]=0;
LCD_write_char(18,0,votable[4]/10+48);
LCD_write_char(19,0,votable[4]%10+48);
dbloud=(3-votable[4])*8+votable[5];
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号(loud)
irnum=0;ke=0;
}
if((ke==9||irnum==9)&&model==5)
{
votable[4]++;if(votable[4]>3)votable[4]=3;
LCD_write_char(18,0,votable[4]/10+48);
LCD_write_char(19,0,votable[4]%10+48);
dbloud=(3-votable[4])*8+votable[5];
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号(loud)
irnum=0;ke=0;
}
//----------------------LOUD------------------------------
if((ke==8||irnum==8))
{ //LOUD
if(lond)
{
votable[5]=0;
dbloud=(3-votable[4])*8+votable[5];
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号(loud)
LCD_write_string(0,1,"LOUD");
lond=0;
irnum=0;irnum=0;ke=0;
}
if((lond==0)&&(ke==8||irnum==8))
{
votable[5]=4;
dbloud=(3-votable[4])*8+votable[5];
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号(loud)
LCD_write_string(0,1," ");
lond=1;
}
irnum=0;irnum=0;ke=0;
}
//----------------------MUTE------------------------------
if(ke==7||irnum==7)
{
//静音
if(mute)
{
while( !write_nbyte1(0x88,223));//
while( !write_nbyte1(0x88,255));//
LCD_write_string(21,1,"MUTE");
mute=0;
irnum=0;irnum=0;ke=0;
}
if(mute==0&&(ke==7||irnum==7))
{
while( !write_nbyte1(0x88,192));//向声音处理器发送信号(左右平衡)
while( !write_nbyte1(0x88,224));//向声音处理器发送信号(左右平衡)
LCD_write_string(21,1," ");
mute=1;
}
irnum=0;irnum=0;ke=0;
}
//----------------------MODEL-----------------------------
if(ke==11||file_return==0||irnum==11)
{
if(file_return==0)
{
//TIMSK&=0xfe; //关定时中断按键到时
model=1;file_return=1;
eeprom_write_byte (0x01,votable[0]);
eeprom_write_byte (0x02,votable[1]);
eeprom_write_byte (0x03,votable[2]);
eeprom_write_byte (0x04,votable[3]);
eeprom_write_byte (0x05,votable[4]);
eeprom_write_byte (0x06,votable[5]);
}
if(ke==11)model++;
if(model>5)model=1;
if(model==1)
{
LCD_write_char(18,0,votable[0]/10+48);
LCD_write_char(19,0,votable[0]%10+48);
LCD_write_string(0,0,"VOIC ------------ ");
}
if(model==2)
{
LCD_write_char(18,0,votable[1]/10+48);
LCD_write_char(19,0,votable[1]%10+48);
LCD_write_string(0,0,"BASS ------------ ");
}
if(model==3)
{
LCD_write_char(18,0,votable[2]/10+48);
LCD_write_char(19,0,votable[2]%10+48);
LCD_write_string(0,0,"TREB ------------ ");
}
if(model==4)
{
LCD_write_char(18,0,votable[3]/10+48);
LCD_write_char(19,0,votable[3]%10+48);
LCD_write_string(0,0,"INPU ------------ ");
}
if(model==5)
{
LCD_write_char(18,0,votable[4]/10+48);
LCD_write_char(19,0,votable[4]%10+48);
LCD_write_string(0,0,"D B ------------ ");
}
irnum=0;ke=0;
}
ke=key();
if(dobit==0){timecount=0;/*TIMSK|=0X01*/;}//开定时中断按键计时
}
}
//----------------------------system int-------------------------------------------------------------
//函数名:system_int
//返回值:无
//---------------------------------------------------------------------------------------------------
void system_int(void)
{
LCD_init(); //初始化LCD1602
TIMSK|=0X01;
// GICR|=0X40;
//MCUCR|=0X02;
TCCR0|=0X05;//1024分频 CPU=1M
TCNT0 =61; //time=1024*(256-158)=100ms
DDRC|=0x00;
PORTC=0x0f;
PORTD&=~(1<<PD2);
file_return=1;
timecount=0;
//while(key()!=9);
LCD_write_string(6,0,"H");
delay10ms(50);
LCD_write_string(8,0,"E");
delay10ms(50);
LCD_write_string(10,0,"L");
delay10ms(50);
LCD_write_string(12,0,"L");
delay10ms(50);
LCD_write_string(14,0,"O");
delay10ms(200);
write_command(0x01); //清屏--对应清屏指令
delay10ms(2); //delay
votable[0]=eeprom_read_byte (0x01);
votable[1]=eeprom_read_byte (0x02);
votable[2]=eeprom_read_byte (0x03);
votable[3]=eeprom_read_byte (0x04);
votable[4]=eeprom_read_byte (0x05);
votable[5]=eeprom_read_byte (0x06);
LCD_write_string(0,0,"VOIC ------------ ");
if(votable[5]==04)LCD_write_string(0,1,"LOUD");
LCD_write_char(18,0,votable[0]/10+48);
LCD_write_char(19,0,votable[0]%10+48);
while( !write_nbyte1(0x88,63-votable[0]));
dbloud=(3-votable[4])*8+votable[5];
while( !write_nbyte1(0x88,votable[3]+dbloud+64));//向声音处理器发送信号(loud)
while( !write_nbyte1(0x88,pgm_read_byte(&bastable[votable[1]])));
while( !write_nbyte1(0x88,pgm_read_byte(&trbtable[votable[2]])));
while( !write_nbyte1(0x88,224));
while( !write_nbyte1(0x88,192));
sei();
}
//----------------------------timer0 interrupt--------------------------------------------------------
//函数名:
//返回值:
//----------------------------------------------------------------------------------------------------
SIG_OVERFLOW0(void)
{
timecount++;
if(timecount==25){timecount=0;file_return=0;}
TCNT0 =61;
}
/*------------------------外部中断0程序-------------------------*/
/*------------------主要用于处理红外遥控键值--------------------*/
SIG_INTERRUPT0(void)
{
uchar i; uchar k=0; //红外解码判断标志位,为0则为有效信号,为1则为无效
GICR&=0Xbf; //检测到有效信号关中断,防止干扰
ir_in;
ir_on; LCD_write_string(0,0,"VOIC ------------ ");
for(i=0;i<4;i++)
{
delay10us(100);
if(ir_1 ){k=1;} //刚开始为9ms的引导码.
}
if(k==0)
{
//检测到有效信号关中断,防止干扰
IR_decode(); //如果接收到的是有效信号,则调用解码程序
delay10us(240);
delay10us(240);
delay10us(240);
if(date[2]==~date[3])
{
ir_n=date[2];
if(ir_n==0x1b){irnum=6;date[2]=0;}
if(ir_n==0x11){irnum=7;date[2]=0;}
if(ir_n==0x15){irnum=8;date[2]=0;}
if(ir_n==0x17){irnum=9;date[2]=0;}
if(ir_n==0x1E){irnum=12;date[2]=0;}
if(ir_n==0x5B){irnum=13;date[2]=0;}
if(ir_n==0x56){irnum=17;date[2]=0;}
akey=0;
}
else irnum=0;
}
GICR|=0X40; //开外部中断,允许新的遥控按键
}
//-----------------------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -