⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 power.c

📁 这个源码是在电源上电过程中的处理程序
💻 C
字号:
//--------------------------------------------//
#include 	<avr/pgmspace.h>
#include	<avr/eeprom.h>
#include	<util/delay.h>

#include	"power.h"
#include	"main.h"
#include 	"ir.h"
#include	"osc32.h"
#include	"sys_timer.h"
#include	"m61540.h"
#include	"i2c.h"
#include	"uart.h"
#include	"ipod.h"
#include	"si4700.h"
#include	"hd7279.h"
#include	"process.h"
#include	"util.h"

//--------------------------------------------//
//void working(void);
void standby(void);

//--------------------------------------------//
void power_process(void)
{
	if(on_off==0) 	working();
	else standby();
}

//----------------Working---------------------//
//开机(working) si4700启动 & 恢复I2C功能
//增加快速logo显示!!!!!!!!!!!!!!!!!!!!!!!
void working(void)
{
//默认显示项目...................................
	function=0;
	mute=0;			//冗余

//delay50ms上电稳定
	_delay_ms(100);

//设备启动.......................................
	if(input==IPODIN)	ipod_weak();

//初始化61540....................................
	uchar	vol_bak=vol;
	vol= 0;
	m61540_mw();
	vol= vol_bak;

//快速显示,延时100ms............................
	hd7279_redraw();
	
//power_state...................................
	on_off=1;

//amp启动.......................................
	portSTBY	&= ~(1<<bitSTBY);		//clr

//淡入 ???? vol==0 ????
	fade_in();
}


//-----------------STANDBY--------------------//
//关机(standby)
void standby(void)
{
//关机默认显示项目..............................
	function=0;

//淡出...........................................
	if(mute== 0)	fade_out();
	else			mute= 0;
//power_state....................................
	on_off=0;							//clr

//standby amp....................................
	portSTBY	|= (1<<bitSTBY);		//set

//led关显示......................................
	hd7279_send_byte(HD7279_RST);

//关ipod.&.关机显示..............................
	ipod_sleep();

//save to eeprom.................................
	eeprom_busy_wait();
	eeprom_write_byte(&e2vol,vol);
	eeprom_busy_wait();
	eeprom_write_byte(&e2treble,treble);
	eeprom_busy_wait();
	eeprom_write_byte(&e2bass,bass);
	eeprom_busy_wait();
	eeprom_write_byte(&e2input,input);
	eeprom_busy_wait();
	eeprom_write_byte(&e2channel,channel);
	eeprom_busy_wait();
	eeprom_write_byte(&e2frequency,frequency);
	eeprom_busy_wait();
	eeprom_write_byte(&e2seekState,seekState);

	eeprom_busy_wait();
	eeprom_write_byte(&e2fm1ch,fm1ch);
	eeprom_busy_wait();
	eeprom_write_byte(&e2fm2ch,fm2ch);
	eeprom_busy_wait();
	eeprom_write_byte(&e2fm3ch,fm3ch);
}

//--------------------------------------------//
void power_up(void)
{
//置关机
	on_off=00;	
	mute=0;
	function=0;
//PIN_PC6(RESET)抗干扰 OUTPUT=HIGH
	DDRC	|= (1<<PC6);
	PORTC	|= (1<<PC6);
//stby_pin & psw_pin & power init
	ddrSTBY 	|= (1<<bitSTBY);		//output
	portSTBY	|= (1<<bitSTBY);		//set 1
//si4700
	si4700_ini();		//置低scl,sda & include osc32.ini
//m61540 i/o ini
	m61540_ini();
//i2c_ini
	i2c_ini();
//hd7279 pin ini
	hd7279_ini();		//含hd7279_rst
//UART_INI
	uart_ini();
//system_timer=20ms
	sys_timer_ini();
//IR开机初始化
	ir_receive_ini();

//load from eeprom
//e2prom排错
	eeprom_busy_wait();
	vol= 		checkrange(24, 32, 40, eeprom_read_byte(&e2vol));
	eeprom_busy_wait();
	treble=		checkrange(0, 7, 14,eeprom_read_byte(&e2treble));
	eeprom_busy_wait();
	bass=		checkrange(0, 7, 14, eeprom_read_byte(&e2bass));
	eeprom_busy_wait();
	input=		checkrange(0, 0, 2, eeprom_read_byte(&e2input));
	eeprom_busy_wait();
	channel=	checkrange(0, 0, 17, eeprom_read_byte(&e2channel));
	eeprom_busy_wait();
	seekState=	checkrange(0, 0, 1, eeprom_read_byte(&e2seekState));
	eeprom_busy_wait();
	fm1ch=		checkrange(0, 0, 5, eeprom_read_byte(&e2fm1ch));
	eeprom_busy_wait();
	fm2ch=		checkrange(0, 0, 5, eeprom_read_byte(&e2fm2ch));
	eeprom_busy_wait();
	fm3ch=		checkrange(0, 0, 5, eeprom_read_byte(&e2fm3ch));
//	eeprom_busy_wait();
//	country=	checkrange(0, 2, 3, eeprom_read_byte(&e2country));
	eeprom_busy_wait();
	if(seekState== 0)	frequency= checkrange(0, 0, 205, eeprom_read_byte(&e2memory[channel]));
	else				frequency= checkrange(0, 0, 205, eeprom_read_byte(&e2frequency));

//开机延时
	_delay_ms(100);
//si4700_启动(开启osc32,i2c)
	si4700_start();		//for volona 因i2c不能停故上电就启动si4700

hd7279_print_hex(7, 0x11, 0);	//ASCII_NEG
	si4700_tune();
hd7279_print_hex(6, 0x11, 0);	//ASCII_NEG
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -