图上红色是keil 仿真输出,蓝色是是实际输出,keil仿真是我想要的,但输出是错的不知道为什
单片机源程序
- #include<STC8.h>
- #define T_SYN_H 1 //发送状态1 发送同步码高电平,存储同步码高电平脉宽
- #define T_SYN_L 2 //发送状态3 发送同步码低电平,
- #define T_DATA_H 3 //发送状态3 发送数据码高电平,
- #define T_DATA_L 4 //接收状态4 发送数据码低电平,
- sbit RF_T =P3^4; //发射端口
- struct RF_Code
- {
- unsigned int y;
- unsigned char x2;
- };
- struct RF_Code RF_Send_Code={42405,2};
- unsigned char Send_Times=0;
- bit RF_T0_Send(struct RF_Code *SendCode)
- {
- static unsigned char RF_T_Step;
- static unsigned char i; //i发送编码的字节数,j发送取位辅助变量,每次发射完成重新清零
- static unsigned char j;
- //static bit abit; static bit bbit;
- //Lcd_Show_Str(50,28,Num2Str(RF_T_Step,2,0),WHITE,BLUE,1); //测试 f(i==1)
- switch (RF_T_Step)
- {
- case T_SYN_H:
- //RF_R_STOP;
- P34=1; //同步码高电平
- TL0 = 0x66; //8F FE 0.2ms@22.1184
- TH0 = 0xFC; //66 FC 0.5ms
- RF_T_Step=T_SYN_L;
- i=0;
- j=0x80;
- break;
- case T_SYN_L:
- P34=0; //同步码低电平
- TL0 = 0x66; //5C D3 6.2ms@22.1184
- TH0 = 0x90; //66 90 15.5ms
- RF_T_Step=T_DATA_H;
- //RF_T_Step=T_SYN_H ;
- break;
- case T_DATA_H:
- P34=1; //数据码高电平
- //abit=(((unsigned char *)SendCode)[i]) & j ;
- if( (((unsigned char *)SendCode)[i]) & j )
- {
- TL0 = 0x33; //AE FB 600us@22.1184
- TH0 = 0xF5; //33 F5 1500us
- }
- else
- {
- TL0 = 0x66; //8F FE 200us@22.1184
- TH0 = 0xFC; //66 FC 500US
- }
- RF_T_Step=T_DATA_L;
- //lcdShowChar(50,28,'3',WHITE,BLUE,1);
- break;
- case T_DATA_L:
- P34=0; //数据码低电平
- //bbit=(((unsigned char *)SendCode)[i]) & j ;
- if( (((unsigned char *)SendCode)[i]) & j ) //(((unsigned char *)SendCode)[i-1]) & j
- {
- TL0 = 0x66; //8F FE 200us@22.1184
- TH0 = 0xFC; //66 FC 500US
- }
- else
- {
- TL0 = 0x33; //AE FB 600ms@22.1184
- TH0 = 0xF5; //33 F5 1500us
- }
- j >>=1;
- if(!j)
- {i++;
- j=0x80;
- }
- RF_T_Step = T_DATA_H;
- break;
- default:
- RF_T_Step = T_SYN_H;
- WDT_CONTR |=0x10; //喂狗
- break;
- }
- if(i==sizeof(*SendCode))
- { RF_T_Step = T_SYN_H; return 1; } // RF_T_Step = T_DATA_H;
- else { return 0;} //测试 f(i==1)
- }
- void Timer0Init(void) //10毫秒@22.1184MHz
- {
- //IPH |=0x08; IP |=0x00; //提到3级
- AUXR &= 0x7F; //定时器时钟12T模式(cpu12分频)
- TMOD &= 0xF0; //设置定时器模式 T0GATE=0,T0_C/T=0,T0M1=0,T0M0=0;16位自动重装模式
- TL0 = 0x00; //设置定时初值
- TH0 = 0x00; //设置定时初值
- TF0 = 0; //清除TF0标志
- // TR0 = 1; //定时器0开始计时
- }
- void main()
- {
- unsigned long *ll ;
- ll=(unsigned long*)&RF_Send_Code;
- Timer0Init();
- ET0=1;//使能定时器0中断
- EA=1;
- P3M1 &=0XEF; P3M0 |=0X10; //推挽输出
- P34=0;
- //TL0=0XF0; TH0=0XFF; TR0=1;
- while(1)
- {
- if(!Send_Times) {Send_Times=15;TL0=0XF0; TH0=0XFF; TR0=1; }
- }
- }
- void Timer0_Isr() interrupt 1 //10毫秒@22.1184MHz
- {
- TF0 = 0; //清除TF0标志
- //lcdShowCC(140,5,"信",RED,GBLUE,1);//信号符号,不是‘信’ 字 测试
- if(Send_Times)
- {
- if(RF_T0_Send(&RF_Send_Code)) Send_Times--;
- //Lcd_Show_Str(50,28,Num2Str(Send_Times,2,0),WHITE,BLUE,1); //测试
- }
- else
- {
- RF_T=0;
- TR0=0; //发送完毕,停止Timer0
- //lcdShowCC(140,5,"信",BLACK,GBLUE,1);//信号符号,不是‘信’ 字 测试
- }
- }
复制代码
|