#include<pic.h>
__CONFIG(XT&WDTDIS);
#define sdin RA3 //数据
#define clk RA5 //时钟
#define V1_8CS RE0 //V1-V8片选
#define L1CS RE1 //led1片选
#define L2CS RE2 //led2片选
#define L3CS RC0 //led3片选
#define L4CS RD0 //led4片选
#define cs RC4
#define dout RC7
#define sck RC5
#define din RC6
#define uchar unsigned char
#define uint unsigned int
#define nop() asm("NOP")
uchar a1=1,a2,a3,a4;
const uchar table[10]={0x88,0xdb,0x2a,0x0b,0x59,0x0d,0x0c,0xcb,0x08,0x09};
void send(uchar dat);
void delay(uchar x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void write_164(unsigned char dt)
{
unsigned char i;
for(i=0;i<8;i++)
{
clk=0;
if(dt&0x80)
sdin=1;
else
sdin=0;
clk=1;
dt=dt<<1;
}
}
void init(void)
{
TRISA=0;
TRISB=0;
TRISD=0;
TRISE=0;
TRISC0=0;
TRISC4=0;
TRISC5=0;
TRISC6=0;
TRISC7=1;
ADCON1=0x06;
PORTE=0x07;
cs=0;
}
void write_enable()
{
cs=1;
nop();
send(0x09);
send(0x80);
nop();
}
void write(uchar add,uchar dat)
{
cs=1;
nop();
write_enable();
nop();
nop();
/* sck=0;
din=1; //起始位1100
sck=1;
nop();
sck=0;
din=0; //
sck=1;
nop();
sck=0;
din=1; //
sck=1;
nop();
sck=0;
//din=0; //A8位0
sck=1;
nop();
sck=0;*/
send(0x0a);
send(add);
send(dat);
// cs=0;nop();
}
void send(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
sck=0;nop();
if(dat&0x80)
din=1;
else
din=0;
nop();
sck=1; nop();
dat=dat<<1;
}
sck=0;
nop();
}
uchar read(uchar add)
{
uchar i,out_data;
// TRISC6=0;
cs=1;
nop();
/* sck=0;
din=1; //起始位1100
sck=1;
nop();
sck=0;
din=1; //
sck=1;
nop();
sck=0;
din=0; //
sck=1;
nop();
sck=0;
//din=0; //A8
sck=1;
nop();
sck=0;*/
write_enable();
send(0x0c);
send(add);
sck=1;nop();
TRISC7=1;
for(i=0;i<8;i++)
{
out_data=out_data<<1;
sck=1;
nop();
sck=0;
nop();
out_data=out_data|dout;
}
cs=0;nop();
return out_data;
}
void main()
{
uchar i;
init();
for(i=4;i>0;i--)
{
nop();
nop();
write(i,i);
}
a1=read(4);
nop();
a2=read(3);
nop();
a3=read(2);
nop();
a4=read(1);
nop();
while(1)
{
write_164(table[a1]);
RE1=0;
delay(10);
RE1=1;
write_164(table[a2]);
RE2=0;
delay(10);
RE2=1;
write_164(table[a3]);
RC0=0;
delay(10);
RC0=1;
write_164(table[a4]);
RD0=0;
delay(10);
RD0=1;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
用的什么信号PIC单片机?
16位以上的有库函数直接调用,写那么多程序干嘛?
一周热门 更多>