- #include <REG52.H>
- #define fck 11059200
- //串口初始化代碼*/
- // 9600 = 1/32*(fck/12/(256-TH1))
- void usart_init(int bound)
- {
- /*T1定時(shí)模式方式2,與中斷引腳無關(guān)*/
- TMOD &=~(0xf<<4);
- TMOD |= (0x2<<4);
- TH1=(256-(fck/32/12/bound));
- TL1=(256-(fck/32/12/bound)); //根據(jù)波特率公式算出預(yù)裝載值
-
- SCON = 0x50;//方式一,使能吸收,失能校驗(yàn),清標(biāo)志位//0101 0000
- PCON &=~(1<<7); //不加倍 0111 1111
- TR1=1; //開定時(shí)器1
- }
- void usart_send(char dat)
- {
-
- SBUF=dat;//發(fā)送新數(shù)據(jù)
- while(TI==0);//等待發(fā)送完成
- TI=0;
- }
- char usart_receive(void)
- {
- char dat;
- while(RI==0);
- dat=SBUF;
- RI=0;
- usart_send(dat);
- return dat;
- }
- int main()
- {
- char a;
- usart_init(9600); //串口初始化
- while(1)
- {
- int strcmp (const char *str1, const char *str2);
- (str1"開燈",str2"關(guān)燈");
- if(a == '1')
- {
- P2 = 0x00;
- }
- else if(a == '0')
- {
- P2 = 0xff;
- }
-
- //usart_receive();
- //usart_send('a');
- }
-
- }
復(fù)制代碼
為什么實(shí)現(xiàn)不了
|