下面是從機的程序,因為想先搞個簡單的所以我從機1和從機2只是前面的宏定義的序號不同可以讓主機來區分從機。程序都是一樣的。求幫忙
/*************** writer:shopping.w ******************/
#include <reg51.h>
#define uchar unsigned char
#define zj1 1
sbit P3_7=P3^7;
uchar code table[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void display(uchar ch){
if((ch>=48)&& (ch<=57))P2=table[ch-48];
else if ( ( ch>=65)&&(ch<=70)) P2=table[ch-55] ;
}
void main()
{
SCON = 0xf0; //串行方式3多機通訊,允許接受,中斷標志清零
TMOD = 0x20; //T1方式2
TH1 = 0xfd;
TL1 = 0xfd;
TR1=1;
EA= 1;
ES = 1;
while(1);
}
void receive (void) interrupt 4
{
RI=0;
if(RB8==1){
if(SBUF==zj1){ //如果選擇了次從機引腳就翻轉
SM2=0;
P3_7=!P3_7; }
return;
}
display(SBUF); //將主機穿過來的型號通過查表來輸出
SM2=1;
} |