电脑发送一个字符;
返回一个字符串
两个按键对应不同字符串发送
#include<reg51.h>
#include<math.h>
#define u8 unsigned char
sbit k3=P3^2;
sbit k4=P3^3;
int x=2;
u8 shumaguang[19]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay(int n)
{
while(n--);
}
void begin(void) //初始函数
{
TMOD=0X20;
TH1=0XF3;
TL1=0XF3;
TR1=1;
PCON=0X80;
SCON=0X50;
ES=1;
IT1=1;
EX1=1;
IT0=1;
EX0=1;
EA=1;
}
void sendbyte(u8 ch) //发送单个字符
{
SBUF=ch;
while(!TI);
TI=0;
}
void sendstring(u8 *str)//发送字符串
{
while(*str)
{
sendbyte(*str++);
}
}
void sendstring2(u8 *str)//发送字符串 2
{
while(*str)
{
sendbyte(*str++);
}
}
void sendstring3(u8 *str)//发送字符串 3
{
while(*str)
{
sendbyte(*str++);
}
}
void sendstring4(u8 *str)//发送字符串 4
{
while(*str)
{
sendbyte(*str++);
}
}
void main(void) //主函数
{
begin();
P2=0x00;
P3=0xff;
delay(1000000);
sendstring4("welcome to west world!!!!!________________________________________\n");
while(1) ;
// sendstring4("welcome to west world!!!!!\n");;
}
void rtinter(void) interrupt 4 //接受中断
{
u8 receivedate;
receivedate=SBUF;
RI=0;
x=receivedate-'0';
P0=shumaguang[x];
sendstring("i have got it!!!buttom k3\n");
}
void outinter(void) interrupt 2 //外部中断0
{
delay(100);
if(k4==0)
{sendstring2("i have a bottom\n");
}
}
void outinter2(void) interrupt 0 //外部中断1
{
delay(100);
if(k3==0)
sendstring3("you send me a digit:\r");
sendbyte(x+'0');
}
|