📄 ad0831.c.bak
字号:
#include <REG51.H>
#include <sys.h>
#include <intrins.h>
const unsigned char LedCode[]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0xF7,0xFC,0xB9,0XDE,0xF9,0xF1};
const unsigned char Sel[]={0x80,0x81,0x82,0x83};
sbit CS = P3^4;
sbit CK = P3^5;
sbit Do = P3^6;
bit read_flag;
uchar data1;
void delay()
{
uchar i = 0;
uchar j = 0;
// for (j=0;j<255;j++)
{
for (i=0; i<250; i++)
;
}
}
uchar getdata()
{
uchar i,databuf=0;
CS=1;
CS=0;
CK=0;
delay();
CK=1;
delay();
for(i=0;i<8;i++)
{
CK=0;
delay();
CK=1;
delay();
databuf=databuf<<1;
databuf=(databuf|((uchar)(Do)));
}
return(databuf);
}
void ISRSER() interrupt 4 using 3
{
uchar a;
if (RI)
{
RI=0;
a=SBUF;
if (a==0xac)
read_flag=1;
}
}
void sendchar (uchar c)
{
SBUF=c;
while(TI==0);
TI=0;
}
void main()
{
delay();
SCON|=0x50; /* mode 1: 8-bit UART, enable receiver */
TMOD|=0x20; /* timer 1 mode 2: 8-Bit reload */
PCON|=0x80; // baud x2
TH1=0xf4; //串口初始化 0xfd=19200,0xfa=9600,0xf4=4800,0xe8=2400,0xd0=1200
TR1=1;
EA=1;
ES=1; // Turn on Series Interrupte;
while(1)
{
if (read_flag)
{
sendchar (getdata());
read_flag=0;
P0=0xFF;
P2=Sel[3];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -