📄 yk_469_tx.c
字号:
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
unsigned char I2C2_Data;
unsigned char I2C2_readdata(bit flag_nack)
{
unsigned char i,x1;
x1 = 0;
for(i = 0; i<8; i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL2 = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
x1 <<= 1;
if(SDA2 != 0)
{
x1 |= 1;
}
SCL2 = 0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
SDA2 = flag_nack;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL2 = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL2 = 0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
return(x1);
}
void write_data_para(unsigned char add1,unsigned char add2,unsigned char buff_data_para)
{
I2C2_init();
I2C2_start();
I2C2_senddata(0xa0);
I2C2_senddata(add1);
I2C2_senddata(add2);
I2C2_senddata(buff_data_para);
I2C2_stop();/**/
/*P1 = 0x01;
while(1);*/
}
void delay(unsigned long v)
{
while (v!=0)v--;
}
void cmx469_senddata()
{
TX_EN = 0;
while( flag_cmx469_send_finished == 0)
{
WDKEY = 0x22;
WDRST = 0x1e;
}
flag_cmx469_send_finished = 0;
cmx469_TX_buff[send_byte - 2] = 0;
cmx469_TX_buff[send_byte - 1] = 0;
}
xdata unsigned char uart0_TX_buff[160];
void uart0_senddata(unsigned char end_type)
{
unsigned char i=0, x1,x2,x3;
i=0;
do
{
TI=0; /*TI = 0;*/
x2=uart0_TX_buff[i];
SBUF = x2;
do
{
x1 = TI;
} while (x1 == 0) ;
i++;
switch (end_type)
{
case 0:
x3 = 0xa;
break;
case 1:
x3 = 26; /* Ctrl_Z */
break;
default:
x3 = 0xd;
break;
}
} while (x2 != x3) ;
}
/* ===================================== 结束 : 子程序 ===================================== */
unsigned char Ctrl_Step = 0;
/* ===================================== 开始 : 中断程序 ===================================== */
void int0() interrupt 0 using 1
{
unsigned char x1,i;
if(flag_receive_begin == 0)
{
x1 = 0x80 ;
if(receive_bit < 8)
{
if(RX_D == 1)
cmx469_receive_data_buff += (x1 >> receive_bit);
else
cmx469_receive_data_buff = cmx469_receive_data_buff;
}
receive_bit++;
if(receive_bit == 8)
{
if(cmx469_receive_data_buff == 0x2b)
{
cmx469_RX_data_buff[0] = cmx469_receive_data_buff;
cmx469_receive_data_buff = 0;
flag_receive_begin = 1;
receive_bit = 0;
receive_byte_index = 1;
}
else
{
cmx469_receive_data_buff = (cmx469_receive_data_buff << 1);
receive_bit = 7;
}
}
}
else
{
x1 = 0x80 ;
if(receive_bit < 8)
{
if(RX_D == 1)
cmx469_receive_data_buff += (x1 >> receive_bit);
else
cmx469_receive_data_buff = cmx469_receive_data_buff;
}
receive_bit++;
if(receive_bit == 8)
{
cmx469_RX_data_buff[receive_byte_index] = cmx469_receive_data_buff;
if((cmx469_RX_data_buff[receive_byte_index-1] == 0x1d) && (cmx469_RX_data_buff[receive_byte_index] == 0x1a))
{
flag_cmx469_receive_finished = 1;
flag_receive_begin = 0;
for(i = 0;i<=receive_byte_index;i++)
cmx469_RX_data[i] = cmx469_RX_data_buff[i];
}
cmx469_receive_data_buff = 0;
receive_bit = 0;
receive_byte_index++;
}
}
}
unsigned char Timer10ms,BaseTimer=0,Para_Timer_h=40,Para_Timer_l=255;
unsigned char Time_Count=0,receive_time_count = 0;
void timer0(void) interrupt 1 using 1
{
TR0 = 0;
TH0 = Mode1_T0_h; /* 22.1184MHz 定时20ms */
TL0 = Mode1_T0_l;
if(Para_Timer_l == 0)
{
if(Para_Timer_h == 0)
{
Para_Timer_l = 255;
Para_Timer_h = 20;
flag_read_para = 1;
}
else
{
Para_Timer_l = 255;
Para_Timer_h -= 1;
receive_time_count++;
}
}
else
{
Para_Timer_l -= 1;
}
// if (flag_RXCMD == 1)
// {
// }
// else
// {
if(Ctrl_Step == 0)
{
BaseTimer = 0;
}
else
{
if(Ctrl_Step == 1)
{
if(Timer10ms != 0)
{
Timer10ms--;
}
else
{
Timer10ms = 2;
BaseTimer += 1;
}
}
else
{
if(Ctrl_Step == 3)
{
if(Timer10ms != 0)
{
Timer10ms--;
}
else
{
Timer10ms = 2;
BaseTimer += 1;
}
}
}
}
// }
//PTT = !PTT;
TR0 = 1;
}
void int1() interrupt 2 using 2
{
unsigned char x1,x2 ;
if(send_byte_index < send_byte)
{
x1 = cmx469_TX_buff[send_byte_index] ;
x2 = ( (x1 << send_bit) & 0x80 );
if(send_bit < 8)
{
if(x2 == 0x80 ) TX_D = 1;
else TX_D = 0;
}
send_bit++;
if(send_bit == 8)
{
send_bit = 0;
send_byte_index++;
}
}
else
{
TX_EN = 1;
send_byte_index = 0;
flag_cmx469_send_finished = 1;
} /* */
}
void int_timer1() interrupt 3 using 2
{
TR1 = 0;
TF0 = 0;
TH1 = Mode1_T1_h; /* 22.1184MHz 定时20ms */
TL1 = Mode1_T1_l;
timer1_count++;
if(timer1_count > delay_time1)
{
flag_timer1_time_out= 1;
timer1_count = 0;
}
else TR1 = 1;
}
unsigned char uart0_RX_index = 0,channel_num,delay_time,CS_IN,uart0_buff_length,flag_uart0_RX_ready;
xdata unsigned char uart0_RX_data[320],uart0_RX_data_buff[320];
bit receive_all =0,new_data =0,receive_flag = 0;
void int_Uart0() interrupt 4 using 2
{
unsigned char i;
if ( RI != 0 )
{
RI = 0;
if(SBUF == '$')
{
uart0_RX_index = 0;
// flag_uart0_RX_ready = 0;
}
if(uart0_RX_index < uart0_buff_length)
{
uart0_RX_data_buff[uart0_RX_index] = SBUF;
uart0_RX_index++;
if(uart0_RX_data_buff[uart0_RX_index-1] == 0xa)
{
for(i=0; i<uart0_RX_index; i++) uart0_RX_data[i]=uart0_RX_data_buff[i];
//CS_IN = 1;
//if(CS_IN == 1)
flag_uart0_RX_ready = 1;
}
}
else
{
uart0_RX_data[uart0_buff_length-1] = SBUF;
}
}
}
void int_timer2() interrupt 5 using 2
{
}
void int_USB() interrupt 6 using 2
{
}
void i2c_isr (void) interrupt 8 using 2
{
}
void uPSD_uart1_isr (void) interrupt 9 using 2
{
}
/* ===================================== 结束 : 中断程序 ===================================== */
unsigned char Timer_H=0,Timer_L=0,Timer_Lp;
#define WIRE_TIME1 16
#define WIRE_TIME2 3
#define WIRE_TIME3 0
#define NOWIRE_TIME1 11
#define NOWIRE_TIME2 24
#define NOWIRE_TIME3 25
unsigned char code bit_base[8] = {1,2,4,8,0x10,0x20,0x40,0x80};
main()
{
unsigned char x0,x1,x2,i,j,k,k1,m,m1,checksum1,checksum2,checksum3,receive_buff;
bit flag_check;
bit flag_new=0;
TMOD = 0x11;
WDKEY = 0x22;
P1SFS = 0x00;
P3SFS = 0x00;
P4SFS = 0x00;
PCON = 0x0c;
T2CON = 0x30;
T2MOD = 0x00;
SCON = 0x50;
RCAP2H = 0xFF;
RCAP2L = 0x70;
TH2 = 0xFF; // 22.1184M晶体,波特率=4800
TL2 = 0x70;
TR2 = 1;
EX0 = 1;
EX1 = 1;
IT0 = 1;
IT1 = 1;
ET0 = 1;
ET1 = 1;
ES = 1;
EA = 1;
site_h = 0;
site_l = 0;
while(1)
{
WDKEY = 0x22;
WDRST = 0x1e;
switch(Ctrl_step_469)
{
case 0:
cmx469_TX_buff[0] = 0x55;
cmx469_TX_buff[1] = 0x2b;
for(i = 2;i<3;i++)
cmx469_TX_buff[i] = 0x55;
cmx469_TX_buff[i] = 0x1d;
cmx469_TX_buff[i+1] = 0x1a;
send_byte = i+2 ;
cmx469_senddata();
P4_2 = !P4_2;
timer1_count = 0;
delay_time1 = 5;
TH1 = Mode1_T1_h; /* 22.1184MHz 定时20ms */
TL1 = Mode1_T1_l;
TR1 = 1; /* */
Ctrl_step_469 = 1;
break;
case 1:
if(flag_timer1_time_out == 1)
{
flag_timer1_time_out = 0;
Ctrl_step_469 = 0;
}
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -