📄 door.c
字号:
//包含所需头文件
#include <avr/io.h>
#include <avr/interrupt.h>
#include "led.h"
#include "global.h"
#include "ir.h"
#include "sw.h"
#include "delay.h"
#include "uart0.h"
#include "uart1.h"
#include "action.h"
#include "timer0.h"
#include "uart2.h"
#include "relay.h"
/**********************************************************************
* Function Name port_init
* Function Desc 初始化端口
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/12 周斌 做成
**********************************************************************/
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
/**********************************************************************
* Function Name init_devices
* Function Desc 初始化设备
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/12 周斌 做成
**********************************************************************/
void init_devices(void)
{
cli(); //禁止所有中断
MCUCR = 0x00;
//MCUCSR = 0x80;//禁止JTAG
//GICR = 0x00;
port_init();
led_init();
ir_init();
sw_init();
uart0_init(BAUD_38400);
uart1_init(BAUD_38400);
uart2_init();
timer0_init(TIMER0_1MS);
sei();//开全局中断
}
/**********************************************************************
* Function Name task_action
* Function Desc 判断人出入、并将ir状态显示到led3 - led6
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/12 周斌 做成
**********************************************************************/
void task_action(void)
{
volatile UCHAR ir;
volatile UCHAR temp; //临时变量;
//
if(timer0_task_action_stat==TIMER0_TASK_ACTION_READY) //如果任务准备好
{
ir = ir_stat();
//传感器取反
ir = ~ir;
ir = ir & 0x0F;
action_judge(ir);
//
temp = ir&0x01;
if (temp)
{
LED3ON();
//uart0_put_string("IR1-1 , ");
}
else
{
LED3OFF();
//uart0_put_string("IR1-0 , ");
}
//
temp = ir&0x02;
if (temp)
{
LED4ON();
//uart0_put_string("IR2-1 , ");
}
else
{
LED4OFF();
//uart0_put_string("IR2-0 , ");
}
//
temp = ir&0x04;
if (temp)
{
LED5ON();
//uart0_put_string("IR3-1 , ");
}
else
{
LED5OFF();
//uart0_put_string("IR3-0 , ");
}
//
temp = ir&0x08;
if (temp)
{
LED6ON();
//uart0_put_string("IR4-1\r\n");
}
else
{
LED6OFF();
//uart0_put_string("IR4-0\r\n");
}
timer0_task_action_stat = TIMER0_TASK_ACTION_FINISH;
}
}
/**********************************************************************
* Function Name task_led1
* Function Desc led1显示系统状态,正常:闪烁,错误:常明、常灭
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/12 周斌 做成
**********************************************************************/
void task_led1(void)
{
if(timer0_task_led1_stat == TIMER0_TASK_LED1_READY)
{
if(error_code == ERROR_NOMAL)
{
LED1NEG();
}
else
{
LED1ON();
}
timer0_task_led1_stat = TIMER0_TASK_LED1_FINISH;
}
}
/**********************************************************************
* Function Name task_uart0_test
* Function Desc 串口0测试程序,把收到的字符发送
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/12 周斌 做成
**********************************************************************/
void task_uart0_test(void)
{
char data;
char* p_data;
p_data=&data;
//
if(uart0_get_byte(p_data) == SUCESS)
{
uart0_put_byte(*p_data);
}
}
/**********************************************************************
* Function Name task_uart0
* Function Desc 串口0响应程序,根据响应的命令进行响应
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/13 周斌 做成
**********************************************************************/
void task_uart0(void)
{
}
/**********************************************************************
* Function Name task_uart2
* Function Desc 串口0响应程序,根据响应的命令进行响应
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/13 周斌 做成
**********************************************************************/
void task_uart2(void)
{
}
/**********************************************************************
* Function Name task_uart2_process
* Function Desc 串口2,收发任务
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/13 周斌 做成
**********************************************************************/
void task_uart2_process(void)
{
uart2_put_byte_process();
NOP();
uart2_rx_process();
NOP();
}
/**********************************************************************
* Function Name task_uart2_test
* Function Desc 串口2,测试任务
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/13 周斌 做成
**********************************************************************/
void task_uart2_test(void)
{
UCHAR get_data[1];
//
if(uart2_get_byte(get_data))
{
uart2_put_byte(get_data[0]);
}
}
/**********************************************************************
* Function Name main
* Function Desc 系统主函数
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/12 周斌 做成
**********************************************************************/
int main(void)
{
//SYSTEM BOOT START
delay_ms(10);
init_devices();
delay_ms(10);
//RESET ERROR CODE
error_code = ERROR_NOMAL; //错误代码,正常
//BOOT INFO TO UARTS
uart0_put_string("UART0 : SYSTEM BOOT SUCESS\r\n");
uart1_put_string("UART1 : SYSTEM BOOT SUCESS\r\n");
uart2_put_string("UART2 : SYSTEM BOOT SUCESS\r\n");
//SYSTEM BOOT END
NOP();
//SYSTEM REAL TIME TASK
while(1)
{
task_action(); //出入动作判断
task_uart0(); //串口0任务,IF1响应
task_uart2(); //串口2任务,IF2响应
task_led1(); //led1,系统状态显示任务
//
task_uart2_process(); //串口2收发任务
task_uart2_test(); //串口2测试任务,回传字符
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -