- #include <REG52.H>
- #define fck 11059200
- //串口初始化代码*/
- // 9600 = 1/32*(fck/12/(256-TH1))
- void usart_init(int bound)
- {
- /*T1定时模式方式2,与中断引脚无关*/
- TMOD &=~(0xf<<4);
- TMOD |= (0x2<<4);
- TH1=(256-(fck/32/12/bound));
- TL1=(256-(fck/32/12/bound)); //根据波特率公式算出预装载值
-
- SCON = 0x50;//方式一,使能吸收,失能校验,清标志位//0101 0000
- PCON &=~(1<<7); //不加倍 0111 1111
- TR1=1; //开定时器1
- }
- void usart_send(char dat)
- {
-
- SBUF=dat;//发送新数据
- while(TI==0);//等待发送完成
- 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"关灯");
- if(a == '1')
- {
- P2 = 0x00;
- }
- else if(a == '0')
- {
- P2 = 0xff;
- }
-
- //usart_receive();
- //usart_send('a');
- }
-
- }
复制代码
为什么实现不了
|