PIC and 485 communication source program

SMD LED
>

PIC and 485 communication source program

#include"HardwareProfile.h"


//Configurebits
__CONFIG(HS&WDTDIS&PWRTDIS&BORDIS&LVPDIS);
voidBoard_Init(void);
#ifdefined(PIC_USE_HC595)
bitb_Reflash;
#endif
#ifdefined(PIC_USE_KB)
#defineFree1
#definePress0
bitb_KeyActive;
bitb_KeyPress;
bitb_KeyState;
BYTEu_KeyValue;
BYTEu_SCANACC;
BYTEi_KeyValueBuffer[2];
#endif

BYTEu_10ms_Acc=0;
BYTEu_50ms_Acc=0;
BYTEu_100ms_Acc=0;
BYTEu_200ms_Acc=0;
WORDi_500ms_Acc=0;
WORDi_1s_Acc=0;
BYTEu_frame=0;
WORDi_ADC;

voidinterruptISR(void)
{
If(T0IF)
{
T0IF=0;
TMR0 = 0x0a; / / timing 1ms
u_10ms_Acc++;
u_50ms_Acc++;
u_100ms_Acc++;
u_200ms_Acc++;
i_500ms_Acc++;
i_1s_Acc++;
#ifdefined(PIC_USE_HC595)
b_Reflash=1;
#endif
If(u_10ms_Acc>=10)
{
u_10ms_Acc=0;
//Add your own tasks below, execute every 10ms
}
If(u_50ms_Acc>=50)
{
u_50ms_Acc=0;
//Add your own tasks below, execute every 50ms
#ifdefined(PIC_USE_KB)
ADIF=0;
ADGO=1;
#endif
}
If(u_100ms_Acc>=100)
{
u_100ms_Acc=0;
//Add your own tasks below, execute once every 100ms
}
If(u_200ms_Acc>=200)
{
u_200ms_Acc=0;
//Add your own tasks below, execute every 200ms
}
If(i_500ms_Acc>=500)
{
i_500ms_Acc=0;
//Add your own tasks below, execute once every 500ms
}
}
If(ADIF)
{
ADIF=0;
#ifdefined(PIC_USE_KB)
If(ADRESH!=0)
{
b_KeyPress=1;//The button is pressed
i_ADC=ADRESH;
i_ADC=i_ADC<<8;
i_ADC=i_ADC|ADRESL;
i_ADC=i_ADC&0xfff8l;
i_ADC=i_ADC>>2;
}
Else
{
b_KeyState=Free;//No button is pressed
b_KeyPress=0;
LED_IO=0x00;
}
#endif
If(TXIF&&TXEN)
{
TXIF=0;
}
}
}

Voidmain()
{
Board_Init();
While(1)
{

#ifdefined(PIC_USE_HC595)
If(b_Reflash)
{
LED_Reflash();
b_Reflash=0;
}
#endif


If(BUTTON1_IO==0)
{
DisplayNumber_Process(8888);
}
If(BUTTON2_IO==0)
{
DisplayNumber_Process(0);
}


#ifdefined(PIC_USE_RS485)
If(RCIF)
{
LED0_IO=LED0_IO^1;
DisplayNumber_Process(RS485_RW());
}
#endif

}
}

//////////////////////////////////////////////////////////// ///////////////
//FunctionvoidBoard_Init(void)
//Input:
//NULL
//Output:
//NULL
//Overview: Initialize each device on the board according to the actual application.
//
voidBoard_Init(void)
{
BUTTON1_TRIS=1;
BUTTON2_TRIS=1;
LED_TRIS=0;
LED_IO=0x01;
TMR0_Init();
#ifdefined(PIC_USE_HC595)
HC595_Init();
#endif

#ifdefined(PIC_USE_LCD12864)
LCD_Init();
#endif

#ifdefined(PIC_USE_ISD1700)
ISD1700_Init();
#endif

#ifdefined(PIC_USE_KB)
KeyBoard_Init();
#endif

#ifdefined(PIC_USE_RS485)
RS485_Init();
#endif
}

#include
#include "HardwareProfile.h"
#if defined(PIC_USE_RS485)


Void RS485_Init(void)
{
RS485_DIR_IO = Receive;
RS485_DIR_TRIS = 0;
RS485_RX_TRIS = 1;
RS485_TX_TRIS = 0;
/*SPBRG = DIVIDER;
RCSTA = (NINE_BITS|0x90);
TXSTA = (SPEED|NINE_BITS|0x20);*/
//SPBRG=25; //baud rate is 9600 Baud Rate = Fosc/(16*(SPBRG+1))
SPBRG=64;
BRGH=1; //High speed baud rate enable bit
TXEN=1; //Send permission
CREN=1; //Continuous reception of the selection bit
SPEN=1; // serial port enable bit
TXIE=0;
RCIE=0; //Receive interrupt enable
TXIF=0;
RCIF=0;
PEIE=1;
GIE=1;
}

Void RS485_Putch(BYTE byte)
{

/* output one byte */
While(!TXIF)/* set when register is empty */
Continue;
RS485_DIR_IO = Send;
TXREG = byte;
While(!TRMT)/* set when register is empty */
;
RS485_DIR_IO = Receive;
}

BYTE RS485_Getch(void)
{
/* retrieve one byte */
While(!RCIF)/* set when register is not empty */
Continue;
RCIF = 0;
Return RCREG;
}

BYTE RS485_RW(void)
{
BYTE temp;
RS485_Putch(temp = RS485_Getch());
Return temp;
}

#endif

Welding Wire

With zinc as the base,the product is added 2 to 15% aluminium,with welding flux content of 10 to 20%

Wildely used in copper-aluminium,copper bus-aluminium foil,Aluminium-aluminium and aluminium alloy welding.



Welding Wire,Flux-Cored Copper Aluminum Welding Wire,Mig Welding Wire,Aluminium Welding Wires

Shaoxing Tianlong Tin Materials Co.,Ltd. , https://www.tianlongspray.com

Posted on