//Charging pile, perform charging operation after the page reaches the specified page (this time you reach the specified page by touching) //1. The picture with the picture number 0 is displayed when the power is turned on, and the picture with the number 1 is entered after 2s. 2. When the number is 2 by touch, turn on the charging relay for charging operation //Get the PIC_ID of the current display page (address 0x03), send the get current page, page turning command, and receive the return value of the current page #include #include unsigned char data_start,data_ok,RX5A,RXA5,RXLEN,RXCMD,RXADDR,RXDLEN,TXTIME,PAGE_TIME,page_flag=1; unsigned char RX_BUF[2]; unsigned char TX_BUF[13]={0x5A,0xA5,0x03,0x81,0x03,0x02, //Read control register PIC_ID (address 0x03) instruction (0x81) 0x5A,0xA5,0x04,0x80,0x03,0x00,0x01}; //Write control register 0x03 PIC_ID (address 0x03), occupying two bytes of instruction (0x80) unsigned char TX_CNT,RX_CNT;//The pointer position of the transceiver buffer sbit RTR1=P1^0;//Charge and power off relay void main(void) { int temp_s; //Power-on initialization PCON=PCON|0x80;//Configure the serial port baud rate clock to 22.1184bps, and the baud rate to 115200 SCON=0x50;//Receive mode 1, allow serial port reception TMOD=0x21;//Timer 1 mode 2, Timer 0 mode 1 TH1=255; TL1=255; TR1=1; TH0=0xB8;//10ms timer interrupt, calculation: (2^16-0xB800)*12*1/(22.1184*10^6)=0.01 TL0=0x00; TR0=1; TXTIME=200;//Jump from page 0 to page 1 2s after booting data_start=0; data_ok=0; RTR1=1;//Turn on the refrigeration relay ES=1; ET0=1; EA=1; while(1) { if(data_ok==0xff) { data_ok=0; temp_s=RX_BUF[0]*256+RX_BUF[1]; if(temp_s==0x0002)//When the second page is touched, the charging operation is performed RTR1=1; else RTR1=0; } } } void Time0_interrupt(void) interrupt 2 { TF0 = 0; TH0 = 0xB8; TL0 = 0x00; TXTIME--; if(TXTIME == 0) { TXTIME = 20;//200ms Send once TX_CNT = 0; TI = 0; SBUF = TX_BUF[0];//TI = 1; } } void Uart_interrupt(void) interrupt 4 { unsigned char temp; if(RI) { RI=0; temp = SBUF; if(data_start==0) { RX5A=RXA5; RXA5=RXLEN; RXLEN=RXCMD; RXCMD=RXADDR; RXADDR=RXDLEN; RXDLEN=temp; //Check the sync frame data if((RX5A==0x5A)&&(RXA5==0xA5)&&(RXLEN==0x05)&&(RXCMD==0x81) &&(RXADDR=0x03)&&(RXDLEN=0x02)) { data_start=0xff; RX_CNT=0; } }else { RX_BUF[RX_CNT]=temp; RX_CNT++; if(RX_CNT==2) { data_start=0; data_ok=0xff; } } } if(TI) { TI=0; TX_CNT++; if(page_flag == 1)//Page turning is performed only once after startup { if(TX_CNT<13) {SBUF=TX_BUF[TX_CNT];}//TI = 1; else page_flag = 0; }else { if(TX_CNT<6) {SBUF=TX_BUF[TX_CNT];}//TI = 1 } } }
|