proteus 仿真51单片机串口通讯,适合proteus+51初学者,也适合工程设计中调试串口通讯用
- #include <reg8253.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar table[14]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,
- 0x20,0x63,0x07,0x23}; //阴极7SEG
- uchar send=0x00;
- void rs232Ini(void)
- {
- TMOD=0x20;
- TH1=0xfd; //9600
- TL1=0xfd;
- PCON=0x00;
- SCON=0x50;//方式1
- EA=1;
- ES=1;
- TR1=1;
- }
- void ex_int(void)
- {
- EA=1;
- IE0=0;
- EX0=1;
- }
- void delay(unsigned char n)
- {
- uchar i,j,k;
- for(i=0;i<=n;i++)
- {
- for(j=0;j<100;j++)
- for(k=0;k<=250;k++);
- }
- }
- void main(void)
- {
- delay(1);
- rs232Ini();
- ex_int();
- P3_3=0;//led
- while(1)
- {
- }
- }
- void ex_button() interrupt 0 using 2
- {// send=5;
- SBUF=send;
- while(!TI);
- TI=0;
- P1_0=!P1_0;
- send++;
- IE0=0;
- if(send>10) send=0;
- delay(1);
- P3_7=!P3_7;//Led
- }
- void serial_Read(void) interrupt 4 using 3
- {
- uint iBuf;
- uchar cBuf;
- if(RI==1)
- {
- P2=1;
- iBuf=SBUF;
- cBuf=iBuf;
- P0=table[cBuf];
- RI=0;
- }
- }
复制代码