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

📄 main.c

📁 用凌阳单片机(sunplus)实现的红外接收装置
💻 C
字号:

#include "global.h"

static volatile unsigned int *P_Watchdog_Clear = (unsigned int*)(0x7012);

volatile int digit[4];
volatile int custom_temper = 30;
volatile int current_temper = 0;
volatile int red_int_cnt;
volatile int target_impulse = 0;

/* conmunicate bettwen red_int_callback and main*/
volatile int caculation_ok = 0;
volatile int frame_receive_ok = 0;
volatile int control_impulse_to_send = 0;
volatile int impulse_reveived = 0;
volatile int alarm_enable = 0;;
volatile int synch_lost = 0;
volatile int temper_lost = 0;
/* communicate with delay */
volatile int time_up;

static int impulse_to_send_base = 0;
static int impulse_reveived_table[5];
void main() 
{
	int i;

	for(i=0; i<5; i++) {
		impulse_reveived_table[i] = 0;
	}
	check_and_update_digit();
	update_taget_impulse();
	
	driver_initial();

	red_int_cnt = 0;
	
	asm("int	irq");   // open interrupt;

	while (1) {
		int tmp;
		
		*P_Watchdog_Clear = 0x0001; //  feed watch dog
		
		if (frame_receive_ok == 0) {
			continue;
		}
		frame_receive_ok = 0;

		for(i=0; i<4; i++) {
			impulse_reveived_table[i+1] = impulse_reveived_table[i];
		}
		impulse_reveived_table[0] = impulse_reveived;
		tmp = 0;
		for(i=0; i<5; i++) {
			tmp += impulse_reveived_table[i];
		}
		current_temper = (int)(98.0-((double)tmp) / (1.85*5.0));
		if (current_temper < 0) current_temper = 0;
		if (((custom_temper -current_temper) > 10) || ((custom_temper -current_temper) < -10)) {
			temper_lost = 1;
		} else {
			temper_lost = 0;
		}

		if (impulse_reveived <= target_impulse) {
			int dif = target_impulse - impulse_reveived;
			if (dif >= 3) {
				impulse_to_send_base -= 10;
			} else if (dif > 0) {
				impulse_to_send_base--;
			}
			if (impulse_to_send_base < 0) 
				impulse_to_send_base = 0;
			control_impulse_to_send = impulse_to_send_base;
		} else {
			impulse_to_send_base++;
			if (impulse_to_send_base >27) 
				impulse_to_send_base = 27;
			control_impulse_to_send = impulse_to_send_base;
		}

		check_and_update_digit();
		
		caculation_ok = 1;
	}
	
}











⌨️ 快捷键说明

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