📄 350_int.c
字号:
//-----------------------------------------------------------------------------
// 包含文件
//-----------------------------------------------------------------------------
//
#include "C8051F350.H"
#include "C8051F350_command.h"
#include <intrins.h>
//-----------------------------------------------------------------------------
// 外部全局变量声明区
//-----------------------------------------------------------------------------
//
extern unsigned char GCV_uart_send_status; //UART发送控制状态
extern unsigned char GCV_received_command_buf; //UART接收命令缓冲
extern unsigned char GCV_adc0_conver_channel_num; //ADC0转换通道号码
extern unsigned char GCV_conver_result_h; //ADC0转换结果高位
extern unsigned char GCV_conver_result_l; //ADC0转换结果低位
//-----------------------------------------------------------------------------
// 中断服务程序区
//-----------------------------------------------------------------------------
//准备好所有中断,以便在中断向量区生成RETI,有助抗干扰
//
//-----------------------------------------------------------------------------
// 外部0中断函数
//-----------------------------------------------------------------------------
//
void Int0_ISR(void) interrupt 0
{
_nop_();
_nop_();
_nop_();
}
//-----------------------------------------------------------------------------
// Timer0中断
//-----------------------------------------------------------------------------
//
void Timer0_ISR(void) interrupt 1
{
_nop_();
_nop_();
_nop_();
}
//-----------------------------------------------------------------------------
// 外部1中断函数
//-----------------------------------------------------------------------------
//
void Int1_ISR(void) interrupt 2
{
_nop_();
_nop_();
_nop_();
}
//-----------------------------------------------------------------------------
// Timer1中断
//-----------------------------------------------------------------------------
//
void Timer1_ISR(void) interrupt 3
{
_nop_();
_nop_();
_nop_();
}
//-----------------------------------------------------------------------------
// UART0中断
//-----------------------------------------------------------------------------
//
void UART0_ISR(void) interrupt 4
{
unsigned char TCV_sbuf0_mirror_image;
//发送采样数据
if(TI0)
{
TI0 = 0;
//检查还剩多少位数据未被发送出去
if( GCV_uart_send_status == 5 )
{
//发送数据起始标志1
SBUF0 = 0xda;
GCV_uart_send_status--;
}
//检查还剩多少位数据未被发送出去
else if( GCV_uart_send_status == 4 )
{
//发送数据起始标志2
SBUF0 = 0xad;
GCV_uart_send_status--;
}
//检查还剩多少位数据未被发送出去
else if( GCV_uart_send_status == 3 )
{
//发送数据通道号码
SBUF0 = GCV_adc0_conver_channel_num;
//随后改变通道的号码
GCV_adc0_conver_channel_num += 0x11;
if( GCV_adc0_conver_channel_num == 0x55 )
{
GCV_adc0_conver_channel_num = 0x11;
}
GCV_uart_send_status--;
}
//检查还剩多少位数据未被发送出去
else if( GCV_uart_send_status == 2 )
{
//发送转换结果高位
SBUF0 = GCV_conver_result_h;
GCV_uart_send_status--;
}
//检查还剩多少位数据未被发送出去
else if( GCV_uart_send_status == 1 )
{
//发送转换结果低位
SBUF0 = GCV_conver_result_l;
GCV_uart_send_status = 0;
}
else
{
//其他无效中断则初始化发送状态
GCV_uart_send_status = 5;
}
}
//接收上级命令
if(RI0)
{
RI0 =0;
TCV_sbuf0_mirror_image = SBUF0;
//首先满足关键字A5
if ( TCV_sbuf0_mirror_image == 0xa5 )
{
GCV_received_command_buf = 0xa5;
}
//然后满足关键字F1
else if ( ( TCV_sbuf0_mirror_image == 0xf1 ) & ( GCV_received_command_buf == 0xa5 ) )
{
GCV_received_command_buf = 0xf1;
}
//最后将命令放入命令缓冲
else if ( GCV_received_command_buf == 0xf1 )
{
GCV_received_command_buf = TCV_sbuf0_mirror_image;
}
//其他无效状态则初始化接收状态
else
{
GCV_received_command_buf = 0xff;
}
}
}
//-----------------------------------------------------------------------------
// ADC0中断
//-----------------------------------------------------------------------------
//
void ADC0_ISR(void) interrupt 10
{
//软件清除ADC0中断
AD0INT = 0;
//ADC0进入空闲状态,等待设置转换参数
COM_ADC0_idle;
//保存转换结果高8位
GCV_conver_result_h = ADC0H;
//保存转换结果低8位
GCV_conver_result_l = ADC0M;
//判断下次应该采样哪个通道
if( GCV_adc0_conver_channel_num == 0x11 )
{
/*
float TFV_temp_calculate_vlu;
unsigned int TIV_temp_result;*/
//上次采样为1通道,则此次采样2通道
COM_ADC0_channels_2;
/*
//计算温度显示值(差分计算)
TFV_temp_calculate_vlu = GCV_conver_result_h * 256 + GCV_conver_result_l;
TFV_temp_calculate_vlu *= 2490;
TFV_temp_calculate_vlu /= (65536 * 32);
TFV_temp_calculate_vlu -= 54.3;
TFV_temp_calculate_vlu /= 0.205;
TFV_temp_calculate_vlu *= 335.54;
TIV_temp_result = (unsigned int)TFV_temp_calculate_vlu;
GCV_conver_result_l = (unsigned char)TIV_temp_result;
GCV_conver_result_h = (unsigned char)(TIV_temp_result>>8); */
}
else if ( GCV_adc0_conver_channel_num == 0x22 )
{
//上次采样为2通道,则此次采样3通道
COM_ADC0_channels_3;
}
else if ( GCV_adc0_conver_channel_num == 0x33 )
{
//上次采样为3通道,则此次采样4通道
COM_ADC0_channels_4;
}
else if ( GCV_adc0_conver_channel_num == 0x44 )
{
//上次采样为4通道,则此次采样1通道
COM_ADC0_channels_1;
//COM_ADC0_channels_temp;
}
//启动下次单次转换
COM_ADC0_single_conver;
//进入信息发送状态
TI0 = 1;
//看门狗计数复位
PCA0CPH2 = 0x00;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -