|
電腦發(fā)送一個(gè)字符;
返回一個(gè)字符串
兩個(gè)按鍵對(duì)應(yīng)不同字符串發(fā)送
#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) //初始函數(shù)
{
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) //發(fā)送單個(gè)字符
{
SBUF=ch;
while(!TI);
TI=0;
}
void sendstring(u8 *str)//發(fā)送字符串
{
while(*str)
{
sendbyte(*str++);
}
}
void sendstring2(u8 *str)//發(fā)送字符串 2
{
while(*str)
{
sendbyte(*str++);
}
}
void sendstring3(u8 *str)//發(fā)送字符串 3
{
while(*str)
{
sendbyte(*str++);
}
}
void sendstring4(u8 *str)//發(fā)送字符串 4
{
while(*str)
{
sendbyte(*str++);
}
}
void main(void) //主函數(shù)
{
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');
}
|
|