- #include <intrins.h>
- #include "MC96F6432.h"
- #define uint unsigned int
- #define uchar unsigned char
- sbit TXD = P1^6;
- sbit RXD = P0^5;
- uchar temp2=0;
- void Uartinit()
- {
- /*IO口设置*/
- P3FSR = 0x00; //Port3 端口功能设置为I/O口
- P3 = 0x00;
- P3IO = 0xC0; //P37、P36设置成输出状态
- P3PU = 0x00;
- P0FSRH= 0x00;
- P0FSRL= 0x00;
- P0 = 0x00;
- P0IO = 0x00;
- P1FSRH = 0x00;
- P1 = 0x00;
- P1IO = 0x40;
- P5FSR = 0x10;
- P5IO = 0x1D;
- P5PU = 0xE0;
- OSCCR = 0x08; //系统时钟设置为1MHZ
- SCCR = 0x00;
- /*定时器设置*/
- T0CR = 0x80; //开启定时器
- T0DR = 208;
- // IE = 0x80; //开启总中断
- // IE2 = 0x02; //开启定时器0中断
- }
- void wait(void)
- {
- while(!((EIFLAG1&0x40)==0x40));
- EIFLAG1 = 0x00;
- T0DR = 208;
- }
- uchar RByte()
- {
- uchar temp=0;
- uchar i;
- wait();
- for(i=0;i<8;i++)
- {
- temp>>=1;
- if(RXD)
- {
- temp|=0x80;
- }
- wait();
- }
- return temp;
- }
- void WByte(uchar temp1)
- {
- uchar j;
- TXD =0; //送起始位
- wait();
- for(j=0;j<8;j++)
- {
- TXD = (bit)(temp1&0x01);
- wait();
- temp1>>=1;
- }
- TXD =(bit)1;
- wait();
- }
- void main()
- {
- UartInit();
- while(1)
- {
- WByte(0x55);
- }
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
系统时钟配置1MHZ,定时器定时208
现在可以了,波特率没设置好
一周热门 更多>