发表于:2009/5/5 9:00:33
#0楼
单片机晶振为22.1184,输出为P0-P2,也可以自己设定输出。
[IMG]http://blog.gkong.com/download.aspx/20095585310232.jpg?file=uploadfile3/20095585310232.jpg[IMG]
/*****单片机源程序*******************************************/
#include <reg51.h>
unsigned char buffer[5] ; //定义接收缓冲区
unsigned char point; //定义接收数据个数指示变量
sbit Y0=P0^0;
sbit Y1=P0^1;
sbit Y2=P0^2;
sbit Y3=P0^3;
sbit Y4=P0^4;
sbit Y5=P0^5;
sbit Y6=P0^6;
sbit Y7=P0^7;
sbit Y10=P2^7;
sbit Y11=P2^6;
sbit Y12=P2^5;
sbit Y13=P2^4;
sbit Y14=P2^3;
sbit Y15=P2^2;
sbit Y16=P2^1;
sbit Y17=P2^0;
void UART_init()
{
SCON =0x58;
TMOD =0x21;
TH1=0XFA;//
TL1=TH1;
TR1 =1;
ET1 =0;
ES=1;
PS=1;
EA =1;
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
com_interrupt(void) interrupt 4 using 3
{
unsigned char RECEIVR_buffer;
if(RI)
{
RI=0;
RECEIVR_buffer=SBUF;
if(point==0)
{
if(RECEIVR_buffer==''''''''''''''''S''''''''''''''''){buffer[point]=RECEIVR_buffer;point++; }
else point=0;
}
else if(point>0)buffer[point++]=RECEIVR_buffer;
else point=0;
}
if(TI) TI=0;
}
void main(void)
{
UART_init();
while(1)
{
if(point==2)
{
if(buffer[1]==''''''''''''''''1'''''''''''''''')
{
Y0=~Y0;
if(Y0==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''2'''''''''''''''')
{
Y1=~Y1;
if(Y1==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''3'''''''''''''''')
{
Y2=~Y2;
if(Y2==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''4'''''''''''''''')
{
Y3=~Y3;
if(Y3==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''5'''''''''''''''')
{
Y4=~Y4;
if(Y4==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''6'''''''''''''''')
{
Y5=~Y5;
if(Y5==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''7'''''''''''''''')
{
Y6=~Y6;
if(Y6==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''8'''''''''''''''')
{
Y7=~Y7;
if(Y7==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''9'''''''''''''''')
{
Y10=~Y10;
if(Y10==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''A'''''''''''''''')
{
Y11=~Y11;
if(Y11==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''B'''''''''''''''')
{
Y12=~Y12;
if(Y12==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''C'''''''''''''''')
{
Y13=~Y13;
if(Y13==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''D'''''''''''''''')
{
Y14=~Y14;
if(Y14==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''E'''''''''''''''')
{
Y15=~Y15;
if(Y15==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''F'''''''''''''''')
{
Y16=~Y16;
if(Y16==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''G'''''''''''''''')
{
Y17=~Y17;
if(Y17==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''0'''''''''''''''')
{
P0=0X00;P2=0X00;
buffer[5]=''''''''''''''''0'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''H'''''''''''''''')
{
P0=0XFF;P2=0XFF;
buffer[5]=''''''''''''''''1'''''''''''''''';
}
point=0;
buffer[0]=0;
buffer[1]=0;
SBUF=buffer[5];
}
}
}
/*****单片机程序结束*******************************************/
http://blog.gkong.com/download.aspx/20095585252749.rar?file=uploadfile3/20095585252749.rar
[IMG]http://blog.gkong.com/download.aspx/20095585310232.jpg?file=uploadfile3/20095585310232.jpg[IMG]
/*****单片机源程序*******************************************/
#include <reg51.h>
unsigned char buffer[5] ; //定义接收缓冲区
unsigned char point; //定义接收数据个数指示变量
sbit Y0=P0^0;
sbit Y1=P0^1;
sbit Y2=P0^2;
sbit Y3=P0^3;
sbit Y4=P0^4;
sbit Y5=P0^5;
sbit Y6=P0^6;
sbit Y7=P0^7;
sbit Y10=P2^7;
sbit Y11=P2^6;
sbit Y12=P2^5;
sbit Y13=P2^4;
sbit Y14=P2^3;
sbit Y15=P2^2;
sbit Y16=P2^1;
sbit Y17=P2^0;
void UART_init()
{
SCON =0x58;
TMOD =0x21;
TH1=0XFA;//
TL1=TH1;
TR1 =1;
ET1 =0;
ES=1;
PS=1;
EA =1;
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
com_interrupt(void) interrupt 4 using 3
{
unsigned char RECEIVR_buffer;
if(RI)
{
RI=0;
RECEIVR_buffer=SBUF;
if(point==0)
{
if(RECEIVR_buffer==''''''''''''''''S''''''''''''''''){buffer[point]=RECEIVR_buffer;point++; }
else point=0;
}
else if(point>0)buffer[point++]=RECEIVR_buffer;
else point=0;
}
if(TI) TI=0;
}
void main(void)
{
UART_init();
while(1)
{
if(point==2)
{
if(buffer[1]==''''''''''''''''1'''''''''''''''')
{
Y0=~Y0;
if(Y0==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''2'''''''''''''''')
{
Y1=~Y1;
if(Y1==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''3'''''''''''''''')
{
Y2=~Y2;
if(Y2==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''4'''''''''''''''')
{
Y3=~Y3;
if(Y3==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''5'''''''''''''''')
{
Y4=~Y4;
if(Y4==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''6'''''''''''''''')
{
Y5=~Y5;
if(Y5==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''7'''''''''''''''')
{
Y6=~Y6;
if(Y6==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''8'''''''''''''''')
{
Y7=~Y7;
if(Y7==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''9'''''''''''''''')
{
Y10=~Y10;
if(Y10==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''A'''''''''''''''')
{
Y11=~Y11;
if(Y11==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''B'''''''''''''''')
{
Y12=~Y12;
if(Y12==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''C'''''''''''''''')
{
Y13=~Y13;
if(Y13==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''D'''''''''''''''')
{
Y14=~Y14;
if(Y14==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''E'''''''''''''''')
{
Y15=~Y15;
if(Y15==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''F'''''''''''''''')
{
Y16=~Y16;
if(Y16==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''G'''''''''''''''')
{
Y17=~Y17;
if(Y17==1)buffer[5]=''''''''''''''''0'''''''''''''''';
else buffer[5]=''''''''''''''''1'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''0'''''''''''''''')
{
P0=0X00;P2=0X00;
buffer[5]=''''''''''''''''0'''''''''''''''';
}
else if(buffer[1]==''''''''''''''''H'''''''''''''''')
{
P0=0XFF;P2=0XFF;
buffer[5]=''''''''''''''''1'''''''''''''''';
}
point=0;
buffer[0]=0;
buffer[1]=0;
SBUF=buffer[5];
}
}
}
/*****单片机程序结束*******************************************/
http://blog.gkong.com/download.aspx/20095585252749.rar?file=uploadfile3/20095585252749.rar
[此贴子已经被作者于2009-5-5 9:13:51编辑过]
单片机、ARM产品开发设计;
小设备、夹具、治具控制器设计开发;数码管、点阵LED电子看板开发;
小设备、夹具、治具控制器设计开发;数码管、点阵LED电子看板开发;