|
晶振11.0592M,波特率9600,用了虛擬終端,打算加上 虛擬串口,嘿嘿
51hei截圖_20210717233407.png (77.38 KB, 下載次數(shù): 70)
下載附件
2021-7-17 23:30 上傳
51hei.png (25.81 KB, 下載次數(shù): 53)
下載附件
2021-7-18 15:43 上傳
單片機(jī)源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- ///共陽(yáng)數(shù)碼管 0-9 P 滅
- uchar code smdm[]=
- {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0xFF}; //
- #define sm_dm P0
- sbit Led=P3^7;
- sbit Key_set=P3^2;
- uchar code hello_world[]="Hello World ";
- uchar Dat_rxd;
- uchar work_mode=0;
- /******************************************************************/
- void DelayUs(unsigned char us)//delay us
- {
- unsigned char uscnt;
- uscnt=us>>1; /*12MHz頻率*/
- while(--uscnt);
- }
- /******************************************************************/
- /* 毫秒函數(shù)聲明 */
- /******************************************************************/
- void DelayMs(unsigned int ms)
- {
- while(--ms)
- {
- DelayUs(250);
- DelayUs(250);
- DelayUs(250);
- DelayUs(250);
- }
- }
- //******************串口初始化函數(shù)****************************//
- void Com0_Init(void)
- {
- EA=1; //開(kāi)總中斷
- ES=1; //允許串口中斷
- TMOD=0x20; //定時(shí)器T1,在方式3中斷產(chǎn)生波特率
- SCON=0x50;
- TH1=0xfd; //波特率設(shè)置為9600(晶振12M)
- TL1=0xfd;
- TR1=1; //開(kāi)定時(shí)器T1運(yùn)行控制位
- }
- ///////////////////////
- void Com0(void) interrupt 4 using 1
- {
- if(RI)
- {
- Led=~Led;
- Dat_rxd=SBUF; //串口接收
- Dat_rxd=Dat_rxd-0x30;
- sm_dm=smdm[Dat_rxd];
- RI=0;
- }
- }
- void send_string(uchar *p)
- {
- while(*p!= '\0')
- {
- SBUF=*p;
- p++;
- while(TI==0);
- TI=0;
- }
- }
- //////////////////////
- void main(void)
- {
- ////////////
- Com0_Init();
- while(1)
- {
- if(~Key_set)
- {
- DelayMs(3);
- if(~Key_set)
- {
- work_mode=1;
- while(~Key_set);
- }
- }
- switch(work_mode)
- {
- case 0: break;
- case 1: Led=~Led;
- send_string(hello_world);
- work_mode=0;
- break;
- }
- }
- }
復(fù)制代碼
仿真代碼51hei附件下載:
仿真代碼.7z
(308.84 KB, 下載次數(shù): 131)
2021-7-18 15:42 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|