|
請(qǐng)問各位大神我該如何修改?
單片機(jī)源程序如下:
- #include "reg52.h"
- #include "intrins.h "
- typedef unsigned char u8;
- typedef unsigned int u16;
- sbit SRCLK=P3^6; //串行輸入時(shí)鐘
- sbit RCLK=P3^5; // 存儲(chǔ)寄存器時(shí)鐘
- sbit SER=P3^6; // 控制串行數(shù)據(jù)輸入
- u8 smgduan[]={0x00,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //選擇哪一位smg亮
- code smgwei[]={0x80,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- void UsartInit()
- {
- TMOD=0x20;//0010 0000 T1選擇工作方式2(八位自動(dòng)重裝定時(shí)/計(jì)數(shù)器)
- TH1=0xF3; //計(jì)算TH1 TL1的波特率;打開常用輔助開發(fā)軟件的51波特率初值計(jì)算 選擇方式12 12Mhz 波特率4800 SMOD選擇1(令其加倍) 得到F3H
- TL1=0xF3;//跟TH1一樣 因?yàn)槭前宋坏闹匮b載
- PCON=0x80;//1000 0000 //smod=1時(shí)波特率調(diào)高一倍
- TR1=1;
- SCON=0x50; //0101 0000 SCON采用方式1; SM2(多機(jī)控制位)不使用,令其為0
- ES=1;
- EA=1;
- }
- void main()
- {
- UsartInit();//調(diào)用此函數(shù) 才能令其初始化
- while(1);
- }
- void delay(unsigned int i)
- {
- while(i--);
- }
- void Usart() interrupt 4//編中斷函數(shù)
- {
- unsigned int receiveData;
- unsigned int j;
- receiveData=SBUF;
- RI=0;//串行接收停止位的中間時(shí),由內(nèi)部硬件使RI置1,向CPU發(fā)出中斷申請(qǐng)。因此需要軟件清0來取消中斷申請(qǐng)等待下一次的接收
- SBUF=receiveData;
- while(!TI); //判斷TI是否發(fā)送完成 假設(shè)發(fā)送完成后TI由硬件置1 則!TI則變?yōu)? 就會(huì)跳出while循環(huán) ;假設(shè)還在發(fā)送中,則為0,!TI就是1,就不會(huì)跳出循環(huán)
- TI=0;//串行接收停止位的中間時(shí),由內(nèi)部硬件使TI置1,向CPU發(fā)出中斷申請(qǐng)。因此需要軟件清0來取消中斷申請(qǐng)等待下一次的發(fā)送
- SBUF=P0;
- P0=smgwei[j];
- delay(100);
- P0=0x00; //消影
- }
復(fù)制代碼
|
|