本帖最后由 xuxiangming2013 于 2013-10-16 14:33 编辑
下面是我写的程序,按照时序写的,可信号无法采集,求高手指教!!
#include<pic.h>
#include<stdio.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
#define data RA0
#define clk RA1
#define sl RA2
#define nop() asm("nop")
//__CONFIG(0X0052);
//void init_time0();
void gathernum();//采集
void display(uchar m,uchar n,uchar j);//显示
const uchar table[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x09};
uchar dat;
uchar bit1,bit2,bit3;
void delay(uint x)//延时1ms
{
uint a,b;
for(a=x;a>0;a--)
for(b=400;b>0;b--);
}
void delaynop()
{
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
nop();
}
void main()
{
TRISA=0x01;
TRISB=0;
TRISC=0;
while(1)
{
gathernum();
}
}
void gathernum()
{
uint i;
sl=0;
delaynop();
sl=1;
// clk=0;
for(i=0;i<8;i++)
{
dat=dat<<1;
clk=0;
nop();
nop();
dat|=data;
clk=1;
nop();
nop();
}
bit1=dat/100;
bit2=dat%100/10;
bit3=dat+1;
display(bit1,bit2,bit3);
}
void display(uchar m,uchar n,uchar j)
{
PORTB=table[m];
RC0=0;
delay(2);
RC0=1;
PORTB=table[n];
RC1=0;
delay(2);
RC1=1;
PORTB=table[j];
RC2=0;
delay(2);
RC2=1;
} |