|
50黑币
stc12c5a想要在串口1接收到的内容后加回车换行符号后由串口2发送出去却实现不了,有大佬能帮忙看看修改一下吗?初始学徒比较菜
- #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;
- }
- }
复制代码
|
|