我想实现按键传送,可是出现了问题
发送
#include<reg52.h>
char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
sbit q=P3^6;
int num=0;
scon=0x50;
int ge;
void delay(){
int i,j=0;
for(i=500;i<0;i--)
for(;j<100;j++);
}
main(){
while(1){
if(q==0)
delay();
if(q==0)
{
num++;
if(num>9)num=0;
SBUF=num;
while(ti==0);
TI=0;
while(RI==0);
RI=0;
if(SBUF==num){
ge=num%10;
P1=tab[ge];
delay();
}
while(q==0);
}
}
}
接收
#include<reg52.h>
char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int num=0;
scon=0x50;
char receive;
int ge;
void delay(){
int i,j=0;
for(i=500;i<0;i--)
for(;j<100;j++);
}
main(){
while(1){
while(RI==0){
RI=0;
receive=SBUF;
SBUF=receive;
while(TI==0);
TI=0;
P1=tab[receive%10];
}
delay();
}
}
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
EA = 1; //interrupt enable
//**************************************
Usart1Mode(0x01); //8bits variable baud rate
Usart1MulComDisable(); //multip machine communitate disable
Usart1ReceiveEnable();
UsartBaudRateDouble(0); //without double baud rate
Usart1BaudTimer(1);//selsct baud rate timer2
Usart1BaudRateFreDivDis();
Usart1Pin(0x01);//P3.6/RxD_2, P3.7/TxD_2
GPIOInit(GPIO_P3, GPIO_PIN7, PP_OUT); //push_pull out
Usart1IntEnable();//Usart1 interrupt enable
Usart1BaudRate(9600);//configure Usart1 baud rate 9600
PS = 1;
Usart1ResetTi();//set TI to 0
Usart1ResetRi();//set TI to 0
TIMER_T2Start();//Timer2 start
一周热门 更多>