📄 stc_pic_protocol.c
字号:
/**************************** Inintial MCU ******************************/
#include <16F877A.h>
#device ADC = 10
#fuses HS
#fuses NOWDT
#fuses NOLVP
#fuses NOPROTECT
#fuses NOBROWNOUT
#include <stdio.h>
#include "Parameter_defines.h"
#include "RL_Module.c"
#include "Uart_Module.c"
#include "Output_Module.c"
#include "Input_Module.c"
#include "ADC_Module.c"
#include "ADC_10_Bit_Module.c"
#include "Interrupt_Module.c"
#include "Control_Module.c"
/************************************************************************/
/***************************** Initial Port *****************************/
void port_init( void )
{
SetInput_RB = CONFIG_INPUT ;
SetOutput_RD = CONFIG_OUTPUT;
set_tris_a( 0x0F ); // Set pin A4 = output [PWR]
output_low( PWR_PIN ); // Turn off [PWR]
output_high( SS_PIN ); // Set Chip select pin High [SS]
set_tris_c( 0xFF );
output_high( SRT_PIN ); // Set port C2 = input [SRT/STOP]
set_tris_e( 0x07 ); // Set Address analog control
output_e( 0x00 );
if( SetInput_RB )
{
set_tris_b( 0xFF );
}
if( SetOutput_RD )
{
set_tris_d( 0x00 );
output_d( 0x00 );
}
MemPort = 0x00;
PinData = 0x00;
}
/************************************************************************/
/********************************* Main *********************************/
void main ( )
{
/***** Initial Port And Module *****/
Index = 0; //------------------ Step 1.1
IPConfig = IP_CONFIG; //------------------ Step 1.2
SysFlag = FALSE; //------------------ Step 1.3
RxFlag = FALSE; //------------------ Step 1.4
InpFlag = FALSE; //------------------ Step 1.5
IntFlag = FALSE; //------------------ Step 1.6
IntCnt = 0; //------------------ Step 1.7
port_init( ); //------------------ Step 2
//delay_ms( 250 );
clear_relay_all( ); //------------------ Step 3
setup_adc_ports( AN0_AN1_AN2_AN3_AN4 );
setup_adc( ADC_CLOCK_INTERNAL );
enable_interrupts( GLOBAL );
enable_interrupts( int_rda );
enable_interrupts( int_timer0 );
ext_int_edge( H_TO_L );
enable_interrupts( int_ext );
setup_timer_0( RTCC_INTERNAL|RTCC_DIV_64 );
set_timer0( 0 );
while( TRUE )
{
if( (RxFlag == TRUE) && (SysFlag == TRUE) )
{
RxFlag = FALSE;
if( crc_decode( ) ) module_control( );
}
if( input( SRT_PIN ) == 0 )
{
RxFlag = FALSE;
SysFlag = ~( SysFlag );
if( SysFlag == TRUE )
{
output_high( PWR_PIN );
delay_ms( 500 );
}
else if( SysFlag == FALSE )
{
clear_port_all( );
clear_relay_all( );
output_low( PWR_PIN );
delay_ms( 500 );
Index = 0;
RxFlag = FALSE;
}
}
if( (InpFlag == TRUE) && (SysFlag == TRUE) )
{
DatBuff[0] = input_b( );
if( DatBuff[0] != 0xFF )
{
DatBuff[0] = button_key( DatBuff[0] );
uart_transmit( INPUT_MODULE, 0xBB, PKG_TX );
InpFlag = FALSE;
delay_ms( 500 );
}
}
}
}
/***********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -