|
50黑幣
stc12c5a想要在串口1接收到的內(nèi)容后加回車換行符號(hào)后由串口2發(fā)送出去卻實(shí)現(xiàn)不了,有大佬能幫忙看看修改一下嗎?初始學(xué)徒比較菜
- #include<stc12c5a.h>
- #define S2RI 0x01
- #define S2TI 0x02
- sbit RW=P1^7;
- unsigned char *a,*b;
- unsigned char flag1,flag2;
- void InitUART(void)
- {
- TMOD = 0x20;
- SCON = 0x50;
- TH1 = 0xFA;
- TL1 = TH1;
- TR1 = 1;
- EA =1;
- ES =1;
- S2CON = 0x50;
- BRT = 0xFA;
- AUXR = 0x10;
- IE2 =0x01;
- }
- void UART_1SendOneByte(unsigned char c)
- {
- SBUF = c;
- while(!TI);
- TI = 0;
- }
- void UART_2SendOneByte(unsigned char c)
- {
- RW=1;
- S2BUF=c;
- while(!(S2CON&S2TI));
- S2CON&=~S2TI;
- RW=0;
- }
- void uart1SendStr(unsigned char *s)
- {
- while(*s!='\0')
- {
- UART_1SendOneByte(*s);
- s++;
- }
- }
- void uart2SendStr(unsigned char *s)
- {
- while(*s!='\0')
- {
- UART_2SendOneByte(*s);
- s++;
- }
- }
- void delay(unsigned int z)
- {
- unsigned int x,y;
- for(x=z;x>0;x--)
- for(y=600;y>0;y--);
- }
- void main(void)
- {
- InitUART();
- delay(50);
- while(1)
- {
-
- if(flag1==1)
- {
- flag1=0;
- uart2SendStr(a);
-
- }
- if(flag2==1)
- {
- flag2=0;
- uart1SendStr(b);
- }
- }
- }
- void UART_1Interrupt(void) interrupt 4
- {
- if(RI==1)
- {
- RI=0;
- *a=SBUF;
- a+='\r';
- a+='\n';
-
- }
- }
- void UART_2Interrupt(void) interrupt 8
- {
- if(S2CON&S2RI)
- {
- S2CON&=~S2RI;
- *b=S2BUF;
- }
- }
復(fù)制代碼
|
-
-
04.zip
2021-1-11 09:58 上傳
點(diǎn)擊文件名下載附件
695 Bytes, 下載次數(shù): 3
|